public/Assert-FootballFixtureMarketTypeProbability.ps1

function Assert-FootballFixtureMarketTypeProbability {

    [CmdletBinding()]
    param(

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [Object]$FixtureMarketType

    )
    process{

        $ErrorActionPreference = 'Stop'

        try {

            foreach ($MartketType in $FixtureMarketType) {

                if  ($($MartketType.TypeId) -like '16*') {

                    Assert-FootballFixtureCornerMarketTypeProbability -FixtureMarketType $MartketType

                } # if

                if  ($($MartketType.TypeId) -like '32*' -or $($MartketType.TypeId) -like '33*') {

                    Assert-FootballFixtureGoalMarketTypeProbability -FixtureMarketType $MartketType

                } # if
   
                # $PercentageColumns =@("Yes","No")
                $BTTS = $MartketType | Where-Object {$_.TypeId -eq 231}

                if ($($BTTS.Count) -ge 1)  {

                    $BTTSObject = $BTTS.PSObject.Copy()
                    $Correct = 'false'

                    if ($($BTTS.label) -eq 'Yes') {
                    
                        if ($($BTTS.SHHomeScore) -ge 1 -and $($BTTS.SHAwayScore) -ge 1) {

                            $Correct = 'true'

                        }

                    } # if

                    if ($($BTTS.label) -eq 'No'){

                        if ($($BTTS.SHHomeScore) -lt 1 -or $($BTTS.SHAwayScore) -lt 1) {

                            $Correct = 'true'

                        } # if

                    } # if

                    $BTTSObject | Add-Member -MemberType NoteProperty -Name Correct -Value $Correct
                    $BTTSObject

                } # if

                # $PercentageColumns =@("home_home","home_away","home_draw","away_home","away_away","away_draw","draw_draw","draw_home","draw_away")
                $HalfTimeFullTime = $MartketType | Where-Object {$_.TypeId -eq 232}

                if ($($HalfTimeFullTime.Count) -ge 1) {

                    $HalfTimeFullTimeObject = $HalfTimeFullTime.PSObject.Copy()

                    # "home_home","home_away","home_draw

                    if ($($HalfTimeFullTime.label) -eq 'home_home') {

                        $Correct = 'false'

                        if ($($HalfTimeFullTime.HTHomeScore) -gt $($HalfTimeFullTime.HTAwayScore) -and $($HalfTimeFullTime.SHHomeScore) -gt $($HalfTimeFullTime.SHAwayScore)) {

                            $Correct = 'true'

                        }

                    } # if

                    if ($($HalfTimeFullTime.label) -eq 'home_away') {

                        $Correct = 'false'

                        if ($($HalfTimeFullTime.HTHomeScore) -gt $($HalfTimeFullTime.HTAwayScore) -and $($HalfTimeFullTime.SHHomeScore) -lt $($HalfTimeFullTime.SHAwayScore)) {

                            $Correct = 'true'

                        }

                    } # if

                    if ($($HalfTimeFullTime.label) -eq 'home_draw') {

                        $Correct = 'false'

                        if ($($HalfTimeFullTime.HTHomeScore) -gt $($HalfTimeFullTime.HTAwayScore) -and $($HalfTimeFullTime.SHHomeScore) -eq $($HalfTimeFullTime.SHAwayScore)) {

                            $Correct = 'true'
                            
                        }
           
                    } # if

                    # "away_home","away_away","away_draw"
                    if ($($HalfTimeFullTime.label) -eq 'away_home') {

                        $Correct = 'false'

                        if ($($HalfTimeFullTime.HTHomeScore) -lt $($HalfTimeFullTime.HTAwayScore) -and $($HalfTimeFullTime.SHHomeScore) -gt $($HalfTimeFullTime.SHAwayScore)) {

                            $Correct = 'true'

                        }

                    } # if

                    if ($($HalfTimeFullTime.label) -eq 'away_away') {

                        $Correct = 'false'

                        if ($($HalfTimeFullTime.HTHomeScore) -lt $($HalfTimeFullTime.HTAwayScore) -and $($HalfTimeFullTime.SHHomeScore) -lt $($HalfTimeFullTime.SHAwayScore)) {

                            $Correct = 'true'

                        }

                    } # if

                    if ($($HalfTimeFullTime.label) -eq 'away_draw') {

                        $Correct = 'false'

                        if ($($HalfTimeFullTime.HTHomeScore) -lt $($HalfTimeFullTime.HTAwayScore) -and $($HalfTimeFullTime.SHHomeScore) -eq $($HalfTimeFullTime.SHAwayScore)) {

                            $Correct = 'true'
                            
                        }

                    } # if

                    # "draw_draw","draw_home","draw_away"

                    if ($($HalfTimeFullTime.label) -eq 'draw_draw') {

                        $Correct = 'false'

                        if ($($HalfTimeFullTime.HTHomeScore) -eq $($HalfTimeFullTime.HTAwayScore) -and $($HalfTimeFullTime.SHHomeScore) -eq $($HalfTimeFullTime.SHAwayScore)) {
                            
                            $Correct = 'true'
                            
                        }

                    } # if

                    if ($($HalfTimeFullTime.label) -eq 'draw_home') {

                        $Correct = 'false'

                        if ($($HalfTimeFullTime.HTHomeScore) -eq $($HalfTimeFullTime.HTAwayScore) -and $($HalfTimeFullTime.SHHomeScore) -gt $($HalfTimeFullTime.SHAwayScore)) {

                            $Correct = 'true'
                            
                        }
                
                    } # if

                    if ($($HalfTimeFullTime.label) -eq 'draw_away') {

                        $Correct = 'false'

                        if ($($HalfTimeFullTime.HTHomeScore) -eq $($HalfTimeFullTime.HTAwayScore) -and $($HalfTimeFullTime.SHHomeScore) -lt $($HalfTimeFullTime.SHAwayScore)) {

                            $Correct = 'true'
                            
                        }
                   
                    } # if

                    $HalfTimeFullTimeObject | Add-Member -MemberType NoteProperty -Name Correct -Value $Correct
                    $HalfTimeFullTimeObject

                } # if

                # $PercentageColumns =@("Home","Away","Draw")
                $FirstHalfWinner = $MartketType | Where-Object {$_.TypeId -eq 233}

                if ($($FirstHalfWinner.Count) -ge 1) {

                    $FirstHalfWinnerObject = $FirstHalfWinner.PSObject.Copy()
                    $Correct = 'false'

                    if ($($FirstHalfWinner.label) -eq 'Home' -and $($FirstHalfWinner.HTHomeScore) -gt $($FirstHalfWinner.HTAwayScore)) {

                        $Correct = 'true'

                    } # if

                    if ($($FirstHalfWinner.label) -eq 'Away' -and $($FirstHalfWinner.HTAwayScore) -gt $($FirstHalfWinner.HTHomeScore)) {

                        $Correct = 'true'

                    } # if

                    if ($($FirstHalfWinner.label) -eq 'Draw' -and $($FirstHalfWinner.HTAwayScore) -eq $($FirstHalfWinner.HTHomeScore)) {

                        $Correct = 'true'

                    } # if

                    $FirstHalfWinnerObject | Add-Member -MemberType NoteProperty -Name Correct -Value $Correct
                    $FirstHalfWinnerObject

                } # if

                # $PercentageColumns =@("Yes","No")
                $OU15 = $MartketType | Where-Object {$_.TypeId -eq 234}

                if ($($OU15.Count) -ge 1) {

                    $OU15Object = $OU15.PSObject.Copy()
                    $Correct = 'false'
        
                    if ($($OU15.label) -eq 'Yes' -and $($OU15.SHHomeScore) + $($OU15.SHAwayScore) -gt 1.5) {

                        $Correct = 'true'

                    } # if

                    if ($($OU15.label) -eq 'No' -and $($OU15.SHHomeScore) + $($OU15.SHAwayScore) -lt 1.5) {

                        $Correct = 'true'

                    } # if

                    $OU15Object | Add-Member -MemberType NoteProperty -Name Correct -Value $Correct
                    $OU15Object

                } # if

                # $PercentageColumns =@("Yes","No")
                $OU25 = $MartketType | Where-Object {$_.TypeId -eq 235}

                if ($($OU25.Count) -ge 1) {
                    
                    $OU25Object = $OU25.PSObject.Copy()
                    $Correct = 'false'
            
                    if ($($OU25.label) -eq 'Yes' -and $($OU25.SHHomeScore) + $($OU25.SHAwayScore) -gt 2.5) {

                        $Correct = 'true'

                    } # if

                    if ($($OU25.label) -eq 'No' -and $($OU25.SHHomeScore) + $($OU25.SHAwayScore) -lt 2.5) {

                        $Correct = 'true'

                    } # if

                    $OU25Object | Add-Member -MemberType NoteProperty -Name Correct -Value $Correct
                    $OU25Object

                } # if

                # $PercentageColumns =@("Yes","No")
                $OU35 = $MartketType | Where-Object {$_.TypeId -eq 236}

                if ($($OU35.Count) -ge 1) {

                    $OU35Object = $OU35.PSObject.Copy()
                    $Correct = 'false'
            
                    if ($($OU35.label) -eq 'Yes' -and $($OU35.SHHomeScore) + $($OU35.SHAwayScore) -gt 3.5) {

                        $Correct = 'true'

                    } # if

                    if ($($OU35.label) -eq 'No' -and $($OU35.SHHomeScore) + $($OU35.SHAwayScore) -lt 3.5) {

                        $Correct = 'true'

                    } # if

                    $OU35Object | Add-Member -MemberType NoteProperty -Name Correct -Value $Correct
                    $OU35Object

                } # if

                # $PercentageColumns =@("Home","Away","Draw")
                $TimeToScoreFirst = $MartketType | Where-Object {$_.TypeId -eq 238}

                if ($($TimeToScoreFirst.Count) -ge 1) {

                    $TimeToScoreFirstObject = $TimeToScoreFirst.PSObject.Copy()
                    $FirstGoal = Get-FootballFixtureEvent -Header $Header -Token $Token -FixtureId $($TimeToScoreFirst.FixtureId) `
                        | Where-Object {$_.sort_order -eq 1 -and ($_.type_id -eq 14 -or $_.type_id -eq 16)}
                    
                    $Teams = $($TimeToScoreFirst.FixtureName).Split(' vs ')
                    $HomeTeam = $Teams[0]
                    $AwayTeam = $Teams[1]
                    $Correct = 'false'

                    if ($($TimeToScoreFirst.label) -eq 'Home' -and $($FirstGoal.participant_name) -eq $HomeTeam) {

                        $Correct = 'true'

                    } # if

                    if ($($TimeToScoreFirst.label) -eq 'Away' -and $($FirstGoal.participant_name) -eq $AwayTeam) {

                        $Correct = 'true'

                    } # if

                    if ($($TimeToScoreFirst.label) -eq 'Draw' -and $($FirstGoal.Count) -eq 0) {

                        $Correct = 'true'

                    } # if

                    $TimeToScoreFirstObject | Add-Member -MemberType NoteProperty -Name Correct -Value $Correct
                    $TimeToScoreFirstObject

                } # if

                # $PercentageColumns =@("Home","Away","Draw")
                $FullTimeResult = $MartketType | Where-Object {$_.TypeId -eq 237}

                if ($($FullTimeResult.Count) -ge 1) {

                    $FullTimeResultObject = $FullTimeResult.PSObject.Copy()
                    $Correct = 'false'

                    if ($($FullTimeResult.label) -eq 'Home' -and $($FullTimeResult.SHAwayScore) -lt $($FullTimeResult.SHHomeScore)) {

                        $Correct = 'true'

                    } # if

                    if ($($FullTimeResult.label) -eq 'Away' -and $($FullTimeResult.SHAwayScore) -gt $($FullTimeResult.SHHomeScore)) {

                        $Correct = 'true'

                    } # if

                    if ($($FullTimeResult.label) -eq 'Draw' -and $($FullTimeResult.SHAwayScore) -eq $($FullTimeResult.SHHomeScore)) {

                        $Correct = 'true'
    
                    } # if

                    $FullTimeResultObject | Add-Member -MemberType NoteProperty -Name Correct -Value $Correct
                    $FullTimeResultObject

                } # if

                # $PercentageColumns =@("DrawHome","DrawAway","HomeAway")
                $DoubleChance = $MartketType | Where-Object {$_.TypeId -eq 239}

                if ($($DoubleChance.Count) -ge 1) {

                    $DoubleChanceObject = $DoubleChance.PSObject.Copy()
                    $Correct = 'false'

                    if ($($DoubleChance.label) -eq 'DrawHome' -and $($DoubleChance.SHHomeScore) -ge $($DoubleChance.SHAwayScore)) {

                        $Correct = 'true'
                    
                    } # if


                    if ($($DoubleChance.label) -eq 'DrawAway' -and $($DoubleChance.SHAwayScore) -ge $($DoubleChance.SHHomeScore)) {

                        $Correct = 'true'

                    } # if

                    if ($($DoubleChance.label) -eq 'HomeAway' -and $($DoubleChance.SHHomeScore) -gt $($DoubleChance.SHAwayScore)) {

                            $Correct = 'true'

                    } # if

                    if ($($DoubleChance.label) -eq 'HomeAway' -and $($DoubleChance.SHAwayScore) -gt $($DoubleChance.SHHomeScore)) {

                        $Correct = 'true'

                    } # if

                    $DoubleChanceObject | Add-Member -MemberType NoteProperty -Name Correct -Value $Correct
                    $DoubleChanceObject

                } # if dobulechance

            } # foreach

        }
        catch {

            $_.Exception.Message

        } # try catch

    } # process

} # function