Merge pull request #60 from OpzekerIT/dev

change
This commit is contained in:
Lanta 2023-10-03 11:27:55 +02:00 committed by GitHub
commit 1c77c838f0

View file

@ -8,6 +8,26 @@ if ($PSScriptRoot.length -eq 0) {
else { else {
$scriptroot = $PSScriptRoot $scriptroot = $PSScriptRoot
} }
function get-change {
param (
$winratio_old,
$winratio
)
if ($winratio_old -eq 0) {
if ($winratio -eq 0) {
$change = 0
} else {
# Decide how you want to handle this scenario
$change = [double]::PositiveInfinity
}
} else {
$change =[math]::Round((($winratio - $winratio_old) / $winratio_old * 100) , 2)
}
return $change
}
function get-killstats { function get-killstats {
param ( param (
$player_name, $player_name,
@ -34,13 +54,27 @@ 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 } catch {
$latestFile = @()
}
# Display the result
if ($latestFile.FullName) {
$oldstats = get-content $latestFile.FullName | ConvertFrom-Json
}
else {
$oldstats = @()
}
$all_player_matches = get-content "$scriptroot/../data/player_matches.json" | convertfrom-json -Depth 100 $all_player_matches = get-content "$scriptroot/../data/player_matches.json" | convertfrom-json -Depth 100
$killstats = @() $killstats = @()
$i = 0 $i = 0
foreach ($player in $all_player_matches) { foreach ($player in ($all_player_matches)) {
if($player.psobject.properties.name -eq 'new_win_matches'){ if ($player.psobject.properties.name -eq 'new_win_matches') {
continue continue
} }
$player_name = $player.playername $player_name = $player.playername
@ -79,8 +113,10 @@ foreach ($player in $all_player_matches.playername) {
$humankills = (($killstats | where-object { $_.playername -eq $player }).humankills | Measure-Object -sum).sum $humankills = (($killstats | where-object { $_.playername -eq $player }).humankills | Measure-Object -sum).sum
$player_matches = ($all_player_matches | where-object { $_.playername -eq $player }).player_matches.count $player_matches = ($all_player_matches | where-object { $_.playername -eq $player }).player_matches.count
$player_wins = ($all_player_matches | where-object { $_.playername -eq $player } | ForEach-Object { $_.player_matches } | where-object { $_.stats.winPlace -eq 1 }).count $player_wins = ($all_player_matches | where-object { $_.playername -eq $player } | ForEach-Object { $_.player_matches } | where-object { $_.stats.winPlace -eq 1 }).count
$winratio = ($player_wins / $player_matches) * 100
$winratio_old = (($oldstats.all | Where-Object { $_.playername -eq $player }).winratio)
$playerstats_all += [PSCustomObject]@{ $playerstats_all += [PSCustomObject]@{
playername = $player playername = $player
@ -90,11 +126,14 @@ foreach ($player in $all_player_matches.playername) {
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_H = $humankills / $deaths
KD_ALL = $kills / $deaths KD_ALL = $kills / $deaths
winratio = ($player_wins / $player_matches) * 100 winratio = $winratio
wins = $player_wins wins = $player_wins
change = get-change -winratio_old $winratio_old -winratio $winratio
} }
} }
$playerstats_all = $playerstats_all | Sort-Object winratio -Descending
##IBR ##IBR
$playerstats_event_ibr = @() $playerstats_event_ibr = @()
@ -105,6 +144,8 @@ foreach ($player in $all_player_matches.playername) {
$humankills = (($killstats | where-object { $_.playername -eq $player -and $_.gameMode -eq 'ibr' -and $_.matchType -eq 'event' }).humankills | Measure-Object -sum).sum $humankills = (($killstats | where-object { $_.playername -eq $player -and $_.gameMode -eq 'ibr' -and $_.matchType -eq 'event' }).humankills | Measure-Object -sum).sum
$player_matches = ((($all_player_matches | where-object { $_.playername -eq $player }).player_matches | Where-Object { $_.matchType -eq 'event' -and $_.gameMode -eq 'ibr' }).count) $player_matches = ((($all_player_matches | where-object { $_.playername -eq $player }).player_matches | Where-Object { $_.matchType -eq 'event' -and $_.gameMode -eq 'ibr' }).count)
$player_wins = ($all_player_matches | where-object { $_.playername -eq $player } | ForEach-Object { $_.player_matches } | where-object { $_.stats.winPlace -eq 1 } | Where-Object { $_.matchType -eq 'event' -and $_.gameMode -eq 'ibr' }).count $player_wins = ($all_player_matches | where-object { $_.playername -eq $player } | ForEach-Object { $_.player_matches } | where-object { $_.stats.winPlace -eq 1 } | Where-Object { $_.matchType -eq 'event' -and $_.gameMode -eq 'ibr' }).count
$winratio = ($player_wins / $player_matches) * 100
$winratio_old = (($oldstats.all | Where-Object { $_.playername -eq $player }).winratio)
$playerstats_event_ibr += [PSCustomObject]@{ $playerstats_event_ibr += [PSCustomObject]@{
playername = $player playername = $player
@ -116,8 +157,10 @@ foreach ($player in $all_player_matches.playername) {
KD_ALL = $kills / $deaths KD_ALL = $kills / $deaths
winratio = ($player_wins / $player_matches) * 100 winratio = ($player_wins / $player_matches) * 100
wins = $player_wins wins = $player_wins
change = get-change -winratio_old $winratio_old -winratio $winratio
} }
} }
$playerstats_event_ibr = $playerstats_event_ibr | Sort-Object winratio -Descending
##airoyale ##airoyale
$playerstats_airoyale = @() $playerstats_airoyale = @()
@ -128,6 +171,8 @@ foreach ($player in $all_player_matches.playername) {
$humankills = (($killstats | where-object { $_.playername -eq $player -and $_.matchType -eq 'airoyale' }).humankills | Measure-Object -sum).sum $humankills = (($killstats | where-object { $_.playername -eq $player -and $_.matchType -eq 'airoyale' }).humankills | Measure-Object -sum).sum
$player_matches = ((($all_player_matches | where-object { $_.playername -eq $player }).player_matches | Where-Object { $_.matchType -eq 'airoyale' }).count) $player_matches = ((($all_player_matches | where-object { $_.playername -eq $player }).player_matches | Where-Object { $_.matchType -eq 'airoyale' }).count)
$player_wins = ($all_player_matches | where-object { $_.playername -eq $player } | ForEach-Object { $_.player_matches } | where-object { $_.stats.winPlace -eq 1 } | Where-Object { $_.matchType -eq 'airoyale' }).count $player_wins = ($all_player_matches | where-object { $_.playername -eq $player } | ForEach-Object { $_.player_matches } | where-object { $_.stats.winPlace -eq 1 } | Where-Object { $_.matchType -eq 'airoyale' }).count
$winratio = ($player_wins / $player_matches) * 100
$winratio_old = (($oldstats.all | Where-Object { $_.playername -eq $player }).winratio)
$playerstats_airoyale += [PSCustomObject]@{ $playerstats_airoyale += [PSCustomObject]@{
playername = $player playername = $player
@ -139,8 +184,10 @@ foreach ($player in $all_player_matches.playername) {
KD_ALL = $kills / $deaths KD_ALL = $kills / $deaths
winratio = ($player_wins / $player_matches) * 100 winratio = ($player_wins / $player_matches) * 100
wins = $player_wins wins = $player_wins
change = get-change -winratio_old $winratio_old -winratio $winratio
} }
} }
$playerstats_airoyale = $playerstats_airoyale | Sort-Object winratio -Descending
$playerstats_official = @() $playerstats_official = @()
foreach ($player in $all_player_matches.playername) { foreach ($player in $all_player_matches.playername) {
@ -150,6 +197,8 @@ foreach ($player in $all_player_matches.playername) {
$humankills = (($killstats | where-object { $_.playername -eq $player -and $_.matchType -eq 'official' }).humankills | Measure-Object -sum).sum $humankills = (($killstats | where-object { $_.playername -eq $player -and $_.matchType -eq 'official' }).humankills | Measure-Object -sum).sum
$player_matches = ((($all_player_matches | where-object { $_.playername -eq $player }).player_matches | Where-Object { $_.matchType -eq 'official' }).count) $player_matches = ((($all_player_matches | where-object { $_.playername -eq $player }).player_matches | Where-Object { $_.matchType -eq 'official' }).count)
$player_wins = ($all_player_matches | where-object { $_.playername -eq $player } | ForEach-Object { $_.player_matches } | where-object { $_.stats.winPlace -eq 1 } | Where-Object { $_.matchType -eq 'official' }).count $player_wins = ($all_player_matches | where-object { $_.playername -eq $player } | ForEach-Object { $_.player_matches } | where-object { $_.stats.winPlace -eq 1 } | Where-Object { $_.matchType -eq 'official' }).count
$winratio = ($player_wins / $player_matches) * 100
$winratio_old = (($oldstats.all | Where-Object { $_.playername -eq $player }).winratio)
$playerstats_official += [PSCustomObject]@{ $playerstats_official += [PSCustomObject]@{
playername = $player playername = $player
@ -161,9 +210,10 @@ foreach ($player in $all_player_matches.playername) {
KD_ALL = $kills / $deaths KD_ALL = $kills / $deaths
winratio = ($player_wins / $player_matches) * 100 winratio = ($player_wins / $player_matches) * 100
wins = $player_wins wins = $player_wins
change = get-change -winratio_old $winratio_old -winratio $winratio
} }
} }
$playerstats_official = $playerstats_official | Sort-Object winratio -Descending
$currentDateTime = Get-Date $currentDateTime = Get-Date
@ -185,6 +235,12 @@ $playerstats = [PSCustomObject]@{
write-output "Writing file" write-output "Writing file"
($playerstats | convertto-json) | out-file "$scriptroot/../data/player_last_stats.json" ($playerstats | convertto-json) | out-file "$scriptroot/../data/player_last_stats.json"
$date = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
$filenameDate = ($date -replace ":", "-")
($playerstats | convertto-json) | out-file "$scriptroot/../data/archive/$($filenameDate)_player_last_stats.json"
write-output "Cleaning cache" write-output "Cleaning cache"
$files_keep = (($all_player_matches).player_matches.telemetry_url | Select-Object -Unique) | ForEach-Object { $_.split("/")[-1] } $files_keep = (($all_player_matches).player_matches.telemetry_url | Select-Object -Unique) | ForEach-Object { $_.split("/")[-1] }