-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_probability.ps1
85 lines (76 loc) · 3.32 KB
/
get_probability.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
$lineNumber = 22
# Set the directory containing .pcsp files
$pcspDirectory = "./pcsp_files"
# Set the output directory for specific lines
$outputDirectory = "./data_output/generated_probabilities"
if (Test-Path $outputDirectory) {
# do nothing
} else {
Write-Output "Error: Directory $outputDirectory not found, creating directory..."
New-Item -ItemType Directory $outputDirectory
}
$outputFile = "./data_output/out.txt"
$pattern = "\[(-?\d+\.\d+), (-?\d+\.\d+)\]"
$yearRangeArray = @("1516", "1718", "1819", "1920", "2021")
foreach ($item in $yearRangeArray) {
"match_id,match_url,team,low,high" | Out-File -FilePath "$outputDirectory/$item.csv" -Encoding utf8
}
# Loop through .pcsp files in the directory
foreach ($pcspFile in Get-ChildItem -Path $pcspDirectory -Filter *.pcsp) {
# Extract the integer value using regular expression
$strValueMatchId = [regex]::Match($pcspFile.BaseName, '\d+').Value
# Convert the extracted value to integer
$matchIdIntValue = [int]$strValueMatchId
$yearCsvFile = ""
if ($matchIdIntValue -lt 13000) {
$yearCsvFile = "1516.csv"
}
elseif ($matchIdIntValue -lt 15000) {
$yearCsvFile = "1617.csv"
}
elseif ($matchIdIntValue -lt 23000) {
$yearCsvFile = "1718.csv"
}
elseif ($matchIdIntValue -lt 39000) {
$yearCsvFile = "1819.csv"
}
elseif ($matchIdIntValue -lt 47000) {
$yearCsvFile = "1920.csv"
}
elseif ($matchIdIntValue -lt 60000) {
$yearCsvFile = "2021.csv"
}
if ($yearCsvFile -eq "") {
Write-Output "Error: match_id not in range to map to <year_range>.csv"
continue
}
# Extract team -> home or away
$team = ($pcspFile.BaseName -split '_')[-1]
# $resultsCsvFile = Join-Path -Path $outputDirectory -ChildPath "$($pcspFile.BaseName).txt"
$resultsCsvFile = Join-Path -Path $outputDirectory -ChildPath $yearCsvFile
# Run the command and capture the output
.\PAT340\PAT3.Console.exe -pcsp $pcspFile.FullName ".$outputFile"
$errLogFilePath = "./error_log.txt"
if ($LASTEXITCODE -ne 0) {
"PAT Error at -> $strValueMatchId,https://www.premierleague.com/match/$($strValueMatchId),$team" | Out-File -FilePath $errLogFilePath -Encoding utf8
}
# Check if the file exists and read the specific line
if (Test-Path $outputFile) {
$assertionValidLine = Get-Content $outputFile -TotalCount ($lineNumber) | Select-Object -Last 1
Write-Output "Specific Line for $($pcspFile.Name): $assertionValidLine"
if ($assertionValidLine -match $pattern) {
$probabilityRange =
"$strValueMatchId,https://www.premierleague.com/match/$($strValueMatchId),$team,$($Matches[1]),$($Matches[2])"
$probabilityRange | Out-File -Append -FilePath $resultsCsvFile -Encoding utf8
} else {
$probabilityRange =
"$strValueMatchId,https://www.premierleague.com/match/$($strValueMatchId),$team,error,error"
$probabilityRange | Out-File -Append -FilePath $resultsCsvFile -Encoding utf8
}
} else {
Write-Output "Error: File $outputFile not found."
$probabilityRange =
"$strValueMatchId,https://www.premierleague.com/match/$($strValueMatchId),$team,error,error"
$probabilityRange | Out-File -Append -FilePath $resultsCsvFile -Encoding utf8
}
}