public/Get-FootballFixtureHTFTProbability.ps1

function Get-FootballFixtureHTFTProbability {
    <#
        .EXAMPLE
            Get-FootballFixtureHTFTProbability -Competition jpn-jleague -Date 2025-03-15 -Path C:\sportsmonk
     
    #>

    [CmdletBinding()]
    param(

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$Competition,

        [Parameter(Mandatory=$false)]
        [ValidateNotNullOrEmpty()]
        [string]$Date,

        [Parameter(Mandatory=$false)]
        [ValidateNotNullOrEmpty()]
        [string]$Path

    )
    process {

        $ErrorActionPreference = 'Stop'

        try {

            $ResultsPath = "$Path\sportsmonk-results"
            $PredictionPath = "$Path\sportsmonk-predictions"
            $MarketTypeFilePath = "$PredictionPath\$Competition\$Date\$Competition-232-$Date.csv"
            $ResultsFilePath = "$ResultsPath\$Competition\$Date\$Competition-$Date.csv"
            $PredictionReviewPath = "$Path\fixture-artifact\prediction-preview\$Competition\$Date"

            $MarketTypeData = Import-Csv -Path $MarketTypeFilePath
            $FixtureResults = Import-Csv -Path $ResultsFilePath

            foreach ($FixtureResult in $FixtureResults) {

                $FixtureFilePath = Get-ChildItem -Path $PredictionReviewPath -Recurse -File `
                    | Where-Object {$_.FullName -like "*$($FixtureResult.fixture_id)*" -and $_.FullName -like '*htft-top-percentage.csv'}

                Write-CustomWarningMessage -ParentPath $Path -FilePath $($FixtureFilePath.FullName)
                $FixtureData = Import-Csv -Path $($FixtureFilePath.FullName) | Where-Object {$_.FixtureId -eq $($FixtureResult.fixture_id)}
                $FixtureDataToUse = $FixtureData | Select-Object -First 1

                if ($($FixtureDataToUse.HTHomeScore) -gt $($FixtureDataToUse.HTAwayScore)) {

                    if ($($FixtureDataToUse.SHHomeScore) -gt $($FixtureDataToUse.SHAwayScore)) {

                        $Outcome = 'home_home'

                    } # if

                    if ($($FixtureDataToUse.SHHomeScore) -lt $($FixtureDataToUse.SHAwayScore)) {

                        $Outcome = 'home_away'

                    } # if

                    if ($($FixtureDataToUse.SHHomeScore) -eq $($FixtureDataToUse.SHAwayScore)) {

                        $Outcome = 'home_draw'

                    } # if

                } # if

                if ($($FixtureDataToUse.HTAwayScore) -gt $($FixtureDataToUse.HTHomeScore)) {

                    if ($($FixtureDataToUse.SHHomeScore) -gt $($FixtureDataToUse.SHAwayScore)) {

                        $Outcome = 'away_away'

                    } # if

                    if ($($FixtureDataToUse.SHAwayScore) -lt $($FixtureDataToUse.SHHomeScore) ) {

                        $Outcome = 'away_home'

                    } # if

                    if ($($FixtureDataToUse.SHAwayScore) -eq $($FixtureDataToUse.SHHomeScore)) {

                        $Outcome = 'away_draw'

                    } # if

                } # if

                if ($($FixtureDataToUse.HTAwayScore) -eq $($FixtureDataToUse.HTHomeScore)) {

                    if ($($FixtureDataToUse.SHHomeScore) -gt $($FixtureDataToUse.SHAwayScore)) {

                        $Outcome = 'draw_home'

                    } # if

                    if ($($FixtureDataToUse.SHAwayScore) -gt $($FixtureDataToUse.SHHomeScore) ) {

                        $Outcome = 'draw_away'

                    } # if

                    if ($($FixtureDataToUse.SHAwayScore) -eq $($FixtureDataToUse.SHHomeScore)) {

                        $Outcome = 'draw_draw'

                    } # if

                } # if

                $FixtureMarketTypeData = $MarketTypeData | Where-Object {$_.FixtureId -eq $($FixtureResult.fixture_id)}
                $FixtureMarketTypeData.PSObject.Properties | ForEach-Object -Process {

                    if ($($_.Name) -eq $Outcome) {

                        $PSObject = [PSCustomObject]@{
                            FixtureId = $($FixtureResult.fixture_id)
                            FixtureName = $($FixtureResult.FixtureName)
                            HTHomeScore = $($FixtureDataToUse.HTHomeScore)
                            HTAwayScore = $($FixtureDataToUse.HTAwayScore)
                            HTResult    = $($FixtureDataToUse.HTResult)
                            FTHomeScore = $($FixtureDataToUse.SHHomeScore)
                            FTAwayScore = $($FixtureDataToUse.SHAwayScore)
                            FTResult    = $($FixtureDataToUse.FTResult)
                            Outcome = $($_.Name)
                            Percentage = $($_.Value)
                        }

                        $PSObject

                    } # if

                } # foreach-object
    
            } # foreach

        }
        catch {

            "$($MyInvocation.MyCommand.Name): $_.Exception.Message"

        } # process

    } # process

} # function