From 48a888e4f43a268e070ba0304fc96801aad82c2b Mon Sep 17 00:00:00 2001 From: Lanta Date: Mon, 6 Nov 2023 15:28:51 +0100 Subject: [PATCH 1/3] latest --- update/matchparser.ps1 | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/update/matchparser.ps1 b/update/matchparser.ps1 index 12114e3..f8c83bc 100644 --- a/update/matchparser.ps1 +++ b/update/matchparser.ps1 @@ -48,7 +48,17 @@ function get-killstats { } # Get the latest file in the directory by last modification time try { - $latestFile = Get-ChildItem -Path "$scriptroot/../data/archive/" -File -ErrorAction Stop | Sort-Object LastWriteTime -Descending | Select-Object -First 1 + $filesarray = @() + $files = Get-ChildItem -Path "$scriptroot/../data/archive/" -File -ErrorAction Stop + foreach ($file in $files) { + $dateinfile = $file.Name.split('_')[0] + $format = 'yyyy-MM-ddTHH-mm-ss\Z' + $culture = [Globalization.CultureInfo]::InvariantCulture + $dateTime = [datetime]::ParseExact($dateinfile, $format, $culture) + $filesarray += [PSCustomObject]@{name = $file.Name; date = $dateTime } + + } + $latestFile = ($filesarray | where-object { $_.date -gt (get-date).AddDays(-1) } | Sort-Object date)[-1] Write-Output "Found file $($latestFile.FullName)" } @@ -102,14 +112,15 @@ foreach ($player in $all_player_matches) { $savekillstats = @{ - matchid = $match.id - created = $match.createdAt - stats = $killstat - winplace = (($all_player_matches | where-object { $_.playername -eq $player_name } ).player_matches | where-object {$_.id -eq $match.id}).stats.winplace + matchid = $match.id + created = $match.createdAt + stats = $killstat + winplace = (($all_player_matches | where-object { $_.playername -eq $player_name } ).player_matches | where-object { $_.id -eq $match.id }).stats.winplace } $savekillstats | ConvertTo-Json | out-file "$scriptroot/../data/killstats/$($match.id)_$player_name.json" - } else{ + } + else { Write-Output "$($match.id) already in cache" } } @@ -118,11 +129,12 @@ foreach ($player in $all_player_matches) { $killstats = @() $matchfiles = Get-ChildItem "$scriptroot/../data/killstats/" -File -Filter *.json $last_month = (get-date).AddMonths(-1) -foreach($file in $matchfiles){ +foreach ($file in $matchfiles) { $json = get-content $file | ConvertFrom-Json - if($json.created -gt $last_month){ + if ($json.created -gt $last_month) { $killstats += $json.stats - }else{ + } + else { write-output "Archiveing $($file.name)" Move-Item -Path $file.FullName -Destination "$scriptroot/../data/killstats/archive" -Force } From b448cf0c51ff7a1aed178899d42b20cd1be6b175 Mon Sep 17 00:00:00 2001 From: Lanta Date: Mon, 6 Nov 2023 15:46:41 +0100 Subject: [PATCH 2/3] always compare from yesterday --- update/matchparser.ps1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/update/matchparser.ps1 b/update/matchparser.ps1 index f8c83bc..21dd5d8 100644 --- a/update/matchparser.ps1 +++ b/update/matchparser.ps1 @@ -58,7 +58,9 @@ try { $filesarray += [PSCustomObject]@{name = $file.Name; date = $dateTime } } - $latestFile = ($filesarray | where-object { $_.date -gt (get-date).AddDays(-1) } | Sort-Object date)[-1] + + $latestFile = ($filesarray | where-object { ($_.date -gt (get-date).AddDays(-2)) -and ($_.date -lt (get-date).AddDays(-1))} | Sort-Object date)[-1] + $latestFile = Get-Item -Path "$scriptroot/../data/archive/$($latestFile.name)" Write-Output "Found file $($latestFile.FullName)" } @@ -76,7 +78,7 @@ else { write-output 'setting old stats var empty' $oldstats = @() } - +start-sleep -Seconds 10 $all_player_matches = get-content "$scriptroot/../data/player_matches.json" | convertfrom-json -Depth 100 From 7d589f868ea646a250fdac5dc423451f788a9f7e Mon Sep 17 00:00:00 2001 From: Lanta Date: Mon, 6 Nov 2023 15:49:42 +0100 Subject: [PATCH 3/3] sleep away! --- update/matchparser.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update/matchparser.ps1 b/update/matchparser.ps1 index 21dd5d8..09036e5 100644 --- a/update/matchparser.ps1 +++ b/update/matchparser.ps1 @@ -78,7 +78,7 @@ else { write-output 'setting old stats var empty' $oldstats = @() } -start-sleep -Seconds 10 + $all_player_matches = get-content "$scriptroot/../data/player_matches.json" | convertfrom-json -Depth 100