cacheclean and formatting

This commit is contained in:
Lanta 2023-09-25 15:57:38 +02:00
parent 663d4c6d4a
commit 2b291591fd
5 changed files with 1634 additions and 844 deletions

View file

@ -1,7 +1,8 @@
if($PSScriptRoot.length -eq 0){
if ($PSScriptRoot.length -eq 0) {
$scriptroot = Get-Location
}else{
}
else {
$scriptroot = $PSScriptRoot
}
@ -43,13 +44,14 @@ foreach ($player in $all_player_matches) {
$telemetry_content = (Invoke-WebRequest -Uri $match.telemetry_url).content
$telemetry_content | out-file $telemetryfile
$telemetry = $telemetry_content | ConvertFrom-Json
}else{
}
else {
write-output "Getting from cache $telemetryfile"
$telemetry = get-content $telemetryfile | convertfrom-json
}
write-output "Analyzing for player $player_name telemetry: $($match.telemetry_url)"
$killstats += get-killstats -player_name $player_name -telemetry ($telemetry | where-object {$_._T -eq 'LOGPLAYERKILLV2'})
$killstats += get-killstats -player_name $player_name -telemetry ($telemetry | where-object { $_._T -eq 'LOGPLAYERKILLV2' })
}
}
@ -67,7 +69,7 @@ foreach ($player in $all_player_matches.playername) {
deaths = $deaths
kills = $kills
humankills = $humankills
matches = ($all_player_matches | where-object {$_.playername -eq $player}).player_matches.count
matches = ($all_player_matches | where-object { $_.playername -eq $player }).player_matches.count
KD_H = $humankills / $deaths
KD_ALL = $kills / $deaths
@ -87,10 +89,21 @@ $formattedString = "$currentDateTime - Time Zone: $currentTimezone"
# Output the formatted string
$playerstats += [PSCustomObject]@{
updated = $formattedString
}
}
write-output "Writing file"
($playerstats | convertto-json) | out-file "$scriptroot/../data/player_last_stats.json"
write-output "Cleaning cache"
$files_keep = (($all_player_matches).player_matches.telemetry_url | Select-Object -Unique) | ForEach-Object { $_.split("/")[-1] }
$files_cache = (get-childitem "$scriptroot/../data/telemetry_cache/").name
$difference = (Compare-Object -ReferenceObject $files_keep -DifferenceObject $files_cache | Where-Object { $_.SideIndicator -eq "=>" }).InputObject
foreach ($file in $difference) {
write-output "removing $scriptroot/../data/telemetry_cache/$file"
Remove-Item -Path "$scriptroot/../data/telemetry_cache/$file"
}
write-output "Operation complete"