public/Get-FootballFixtureOutcome.ps1
function Get-FootballFixtureOutcome { [CmdletBinding()] param( [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$Competition, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$Date, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$Path ) process{ $ErrorActionPreference = 'Stop' try { # Get the results and the outcome $PathToUse = "$Path\sportsmonk-results\$Competition\$Date\$Competition-$Date.csv" $FixtureResultFileExists = Test-Path $PathToUse if ($FixtureResultFileExists) { $FixtureResults = Import-Csv -Path $PathToUse [PSCustomObject]$ResultPSObjects =@() foreach ($FixtureResult in $FixtureResults) { if ($($FixtureResult.MatchResult) -eq "" -or $($FixtureResult.HomeScore) -eq "" -or $($FixtureResult.AwayScore) -eq "") { Write-Warning "Missing data: $PathToUse" continue } # if if ($($FixtureResult.HomeScore) -gt $($FixtureResult.AwayScore)) { $Outcome = 'HomeWin' } #if if ($($FixtureResult.HomeScore) -lt $($FixtureResult.AwayScore)) { $Outcome = 'AwayWin' } # if if ($($FixtureResult.HomeScore) -eq $($FixtureResult.AwayScore)) { $Outcome = 'Draw' } # if $ResultPSObject = [PSCustomObject]@{ FixtureId = $($FixtureResult.Fixture_Id) FixtureName = $($FixtureResult.FixtureName) MatchResult = $($FixtureResult.MatchResult) FullTimeResult = "$($FixtureResult.HomeScore)-$($FixtureResult.AwayScore)" ResultOutcome = $Outcome } $ResultPSObjects += $ResultPSObject } $ResultPSObjects | Sort-Object -Property FixtureId $ResultPSObjects | Export-Csv -Path "$Path\game-predictions-outcomes\$Competition\$Date\$Competition-$Date-match-outcomes.csv" -Force -Verbose } else { Write-Warning "File Not Exists: $PathToUse." } # if } catch { "$($MyInvocation.MyCommand.Name): $_.Exception.Message" } # trycatch } # process } # function |