change
This commit is contained in:
parent
060459c1a7
commit
45a74ed969
1 changed files with 61 additions and 5 deletions
|
|
@ -8,6 +8,26 @@ if ($PSScriptRoot.length -eq 0) {
|
|||
else {
|
||||
$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 {
|
||||
param (
|
||||
$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
|
||||
$killstats = @()
|
||||
$i = 0
|
||||
|
||||
foreach ($player in $all_player_matches) {
|
||||
if($player.psobject.properties.name -eq 'new_win_matches'){
|
||||
foreach ($player in ($all_player_matches)) {
|
||||
if ($player.psobject.properties.name -eq 'new_win_matches') {
|
||||
continue
|
||||
}
|
||||
$player_name = $player.playername
|
||||
|
|
@ -79,6 +113,8 @@ foreach ($player in $all_player_matches.playername) {
|
|||
$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_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)
|
||||
|
||||
|
||||
|
||||
|
|
@ -90,11 +126,14 @@ foreach ($player in $all_player_matches.playername) {
|
|||
matches = ($all_player_matches | where-object { $_.playername -eq $player }).player_matches.count
|
||||
KD_H = $humankills / $deaths
|
||||
KD_ALL = $kills / $deaths
|
||||
winratio = ($player_wins / $player_matches) * 100
|
||||
winratio = $winratio
|
||||
wins = $player_wins
|
||||
change = get-change -winratio_old $winratio_old -winratio $winratio
|
||||
|
||||
}
|
||||
}
|
||||
$playerstats_all = $playerstats_all | Sort-Object winratio -Descending
|
||||
|
||||
##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
|
||||
$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
|
||||
$winratio = ($player_wins / $player_matches) * 100
|
||||
$winratio_old = (($oldstats.all | Where-Object { $_.playername -eq $player }).winratio)
|
||||
|
||||
$playerstats_event_ibr += [PSCustomObject]@{
|
||||
playername = $player
|
||||
|
|
@ -116,8 +157,10 @@ foreach ($player in $all_player_matches.playername) {
|
|||
KD_ALL = $kills / $deaths
|
||||
winratio = ($player_wins / $player_matches) * 100
|
||||
wins = $player_wins
|
||||
change = get-change -winratio_old $winratio_old -winratio $winratio
|
||||
}
|
||||
}
|
||||
$playerstats_event_ibr = $playerstats_event_ibr | Sort-Object winratio -Descending
|
||||
|
||||
##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
|
||||
$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
|
||||
$winratio = ($player_wins / $player_matches) * 100
|
||||
$winratio_old = (($oldstats.all | Where-Object { $_.playername -eq $player }).winratio)
|
||||
|
||||
$playerstats_airoyale += [PSCustomObject]@{
|
||||
playername = $player
|
||||
|
|
@ -139,8 +184,10 @@ foreach ($player in $all_player_matches.playername) {
|
|||
KD_ALL = $kills / $deaths
|
||||
winratio = ($player_wins / $player_matches) * 100
|
||||
wins = $player_wins
|
||||
change = get-change -winratio_old $winratio_old -winratio $winratio
|
||||
}
|
||||
}
|
||||
$playerstats_airoyale = $playerstats_airoyale | Sort-Object winratio -Descending
|
||||
|
||||
$playerstats_official = @()
|
||||
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
|
||||
$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
|
||||
$winratio = ($player_wins / $player_matches) * 100
|
||||
$winratio_old = (($oldstats.all | Where-Object { $_.playername -eq $player }).winratio)
|
||||
|
||||
$playerstats_official += [PSCustomObject]@{
|
||||
playername = $player
|
||||
|
|
@ -161,9 +210,10 @@ foreach ($player in $all_player_matches.playername) {
|
|||
KD_ALL = $kills / $deaths
|
||||
winratio = ($player_wins / $player_matches) * 100
|
||||
wins = $player_wins
|
||||
change = get-change -winratio_old $winratio_old -winratio $winratio
|
||||
}
|
||||
}
|
||||
|
||||
$playerstats_official = $playerstats_official | Sort-Object winratio -Descending
|
||||
|
||||
$currentDateTime = Get-Date
|
||||
|
||||
|
|
@ -185,6 +235,12 @@ $playerstats = [PSCustomObject]@{
|
|||
|
||||
write-output "Writing file"
|
||||
($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"
|
||||
|
||||
$files_keep = (($all_player_matches).player_matches.telemetry_url | Select-Object -Unique) | ForEach-Object { $_.split("/")[-1] }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue