public/Get-CorrectScoreProbability.ps1

function Get-CorrectScoreProbability {

    [CmdletBinding()]
    param(

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

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

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

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$TeamName

    )
    process {

        $ErrorActionPreference = 'Stop'

        # .\sportsmonk\sportsmonk-predictions\sco-premier\2025-01-25\sco-premier-240-2025-01-25.csv
        $FileToUse = "$Path\$Competition\$Date\$Competition-240-$Date.csv"
        $FileExists = Test-Path -Path $FileToUse

        if ($FileExists) {

            $Objects = Import-Csv -Path $FileToUse
            $Objects | ForEach-Object {

                $FixtureName = $_.FixtureName
                $FixtureId = $_.FixtureId

                $_.PsObject.Properties | ForEach-Object {

                    if ($($_.Name -like '*-*')) {

                        $PercentageValue = $_.Value -replace "[^0-9.]", ""  # Remove any non-numeric characters e.g. "50.5%" → "50.5"
                        $Percentage = if ($PercentageValue -match "^\d+(\.\d+)?$") { [double]$PercentageValue } else { 0.00 }
                        $Score = $($_.Name)
                        $Split = $Score.Split('-')
                        [int]$HomeScore = $Split[0]
                        [int]$AwayScore = $Split[1]

                        If ($HomeScore -gt $AwayScore) {

                            $OutCome = 'HomeWin'

                        } # if

                        If ($HomeScore -lt $AwayScore ) {

                            $OutCome = 'AwayWin'
                            
                        } # if

                        If ($HomeScore -eq $AwayScore ) {

                            $OutCome = 'Draw'
                            
                        } # if

                        $CSObject = [PSCustomObject]@{
                            FixtureId = $FixtureId
                            FixtureName = $FixtureName
                            TypeId = 240
                            Score = $($_.Name)
                            OutCome = $OutCome
                            Percentage = $Percentage
                        }

                        $CSObject | Where-Object {$_.FixtureName -like "*$TeamName*"}

                    } # if

                } # foreach-object

            } # foreach-object

        }
        else {

            Write-Warning "File Not Exists: $FileToUse."
    
        } # if

    } # process

} # function