diff --git a/last_stats.php b/last_stats.php index 26f3666..02583ac 100644 --- a/last_stats.php +++ b/last_stats.php @@ -6,6 +6,7 @@ error_reporting(E_ALL); + @@ -14,42 +15,67 @@ error_reporting(E_ALL); + - + -
-
-

Player Stats past 14 days

- +
+

Player Stats past 14 days

+ "; - echo " - Playername - Deaths - Kills - Human Kills - Matches - K/D (Human) - K/D (All) - "; - - foreach ($players_matches as $player_data) { - if (!isset($player_data['playername']) || is_null($player_data['playername'])) { - continue; // Skip this iteration and move to the next + foreach ($players_matches as $key => $player_datas) { + if ($key == 'updated') { + continue; } - $player_name = $player_data['playername']; - $deaths = number_format($player_data['deaths'], 2, ',', ''); - $kills = number_format($player_data['kills'], 2, ',', ''); - $humankills = number_format($player_data['humankills'], 2, ',', ''); - $matches = $player_data['matches']; - $KD_H = ($player_data['KD_H'] == "Infinity") ? "∞" : number_format($player_data['KD_H'], 2, ',', ''); - $KD_ALL = ($player_data['KD_ALL'] == "Infinity") ? "∞" : number_format($player_data['KD_ALL'], 2, ',', ''); - + echo "
"; + echo "Stats for $key"; + echo ""; echo " + + + + + + + + "; + foreach ($player_datas as $player_data) { + if (!isset($player_data['playername']) || is_null($player_data['playername'])) { + continue; // Skip this iteration and move to the next + } + + $player_name = $player_data['playername']; + $deaths = number_format($player_data['deaths'], 2, ',', ''); + $kills = number_format($player_data['kills'], 2, ',', ''); + $humankills = number_format($player_data['humankills'], 2, ',', ''); + $matches = $player_data['matches']; + $KD_H = + !isset($player_data['KD_H']) || $player_data['KD_H'] === null + ? "null" + : ($player_data['KD_H'] == "Infinity" + ? "∞" + : (is_numeric($player_data['KD_H']) + ? number_format((float) $player_data['KD_H'], 2, ',', '') + : "0")); // or any other default string for non-numerical values + + + $KD_ALL = + !isset($player_data['KD_ALL']) || $player_data['KD_ALL'] === null + ? "null" + : ($player_data['KD_ALL'] == "Infinity" + ? "∞" + : (is_numeric($player_data['KD_ALL']) + ? number_format((float) $player_data['KD_ALL'], 2, ',', '') + : "0")); // or any other default string for non-numerical values + + + + echo " @@ -58,23 +84,28 @@ error_reporting(E_ALL); "; + } + + echo "
PlayernameDeathsKillsHuman KillsMatchesK/D (Human)K/D (All)
$player_name $deaths $kills$KD_H $KD_ALL
"; } - echo ""; - echo "Last update: "; - foreach ($players_matches as $player_data) { - if (isset($player_data['updated'])) { - echo $player_data['updated']; - break; // Once found, exit the loop + + foreach ($players_matches as $key => $update) { + if ($key == 'updated'){ + echo "Last update: $update "; + } } - - ?> -
-
- + + + ?> + + + + - + + \ No newline at end of file diff --git a/update/matchparser.ps1 b/update/matchparser.ps1 index 608d635..ca12aff 100644 --- a/update/matchparser.ps1 +++ b/update/matchparser.ps1 @@ -5,11 +5,13 @@ if ($PSScriptRoot.length -eq 0) { else { $scriptroot = $PSScriptRoot } - +$matches = 5 function get-killstats { param ( $player_name, - $telemetry + $telemetry, + $matchType, + $gameMode ) $attacks = @() foreach ($action in $telemetry) { @@ -25,17 +27,24 @@ function get-killstats { humankills = ($kills | where-object { $_.victim.accountId -notlike 'ai.*' }).count kills = $kills.count deaths = ($attacks | where-object { $_.victim.name -eq $player_name }).count + gameMode = $gameMode + matchType = $matchType } } $all_player_matches = get-content "$scriptroot/../data/player_matches.json" | convertfrom-json -Depth 100 $killstats = @() +$i = 0 + foreach ($player in $all_player_matches) { $player_name = $player.playername - - foreach ($match in $player.player_matches) { - + $i++ + $j = 0 + write-output "$($all_player_matches.count) / $i" + foreach ($match in $player.player_matches | select-object -First $matches) { + $j++ + write-output "$($player.player_matches.count)/ $j" $telemetryfile = "$scriptroot/../data/telemetry_cache/$($match.telemetry_url.split("/")[-1])" @@ -51,20 +60,20 @@ foreach ($player in $all_player_matches) { } 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' }) -gameMode $match.gameMode -matchType $match.matchType } } -$playerstats = @() +$playerstats_all = @() foreach ($player in $all_player_matches.playername) { $deaths = (($killstats | where-object { $_.playername -eq $player }).deaths | Measure-Object -sum).sum $kills = (($killstats | where-object { $_.playername -eq $player }).kills | Measure-Object -sum).sum $humankills = (($killstats | where-object { $_.playername -eq $player }).humankills | Measure-Object -sum).sum - $playerstats += [PSCustomObject]@{ + $playerstats_all += [PSCustomObject]@{ playername = $player deaths = $deaths kills = $kills @@ -74,6 +83,63 @@ foreach ($player in $all_player_matches.playername) { KD_ALL = $kills / $deaths } } +##IBR + +$playerstats_event_ibr = @() +foreach ($player in $all_player_matches.playername) { + + $deaths = (($killstats | where-object { $_.playername -eq $player -and $_.gameMode -eq 'ibr' -and $_.matchType -eq 'event' }).deaths | Measure-Object -sum).sum + $kills = (($killstats | where-object { $_.playername -eq $player -and $_.gameMode -eq 'ibr' -and $_.matchType -eq 'event' }).kills | Measure-Object -sum).sum + $humankills = (($killstats | where-object { $_.playername -eq $player -and $_.gameMode -eq 'ibr' -and $_.matchType -eq 'event' }).humankills | Measure-Object -sum).sum + + $playerstats_event_ibr += [PSCustomObject]@{ + playername = $player + deaths = $deaths + kills = $kills + humankills = $humankills + matches = ((($all_player_matches | where-object { $_.playername -eq $player }).player_matches | Where-Object { $_.matchType -eq 'event' -and $_.gameMode -eq 'ibr' }).count) + KD_H = $humankills / $deaths + KD_ALL = $kills / $deaths + } +} + +##airoyale +$playerstats_airoyale = @() +foreach ($player in $all_player_matches.playername) { + + $deaths = (($killstats | where-object { $_.playername -eq $player -and $_.matchType -eq 'airoyale' }).deaths | Measure-Object -sum).sum + $kills = (($killstats | where-object { $_.playername -eq $player -and $_.matchType -eq 'airoyale' }).kills | Measure-Object -sum).sum + $humankills = (($killstats | where-object { $_.playername -eq $player -and $_.matchType -eq 'airoyale' }).humankills | Measure-Object -sum).sum + + $playerstats_airoyale += [PSCustomObject]@{ + playername = $player + deaths = $deaths + kills = $kills + humankills = $humankills + matches = ((($all_player_matches | where-object { $_.playername -eq $player }).player_matches | Where-Object { $_.matchType -eq 'airoyale' }).count) + KD_H = $humankills / $deaths + KD_ALL = $kills / $deaths + } +} + +$playerstats_official = @() +foreach ($player in $all_player_matches.playername) { + + $deaths = (($killstats | where-object { $_.playername -eq $player -and $_.matchType -eq 'official' }).deaths | Measure-Object -sum).sum + $kills = (($killstats | where-object { $_.playername -eq $player -and $_.matchType -eq 'official' }).kills | Measure-Object -sum).sum + $humankills = (($killstats | where-object { $_.playername -eq $player -and $_.matchType -eq 'official' }).humankills | Measure-Object -sum).sum + + $playerstats_official += [PSCustomObject]@{ + playername = $player + deaths = $deaths + kills = $kills + humankills = $humankills + matches = ((($all_player_matches | where-object { $_.playername -eq $player }).player_matches | Where-Object { $_.matchType -eq 'official' }).count) + KD_H = $humankills / $deaths + KD_ALL = $kills / $deaths + } +} + $currentDateTime = Get-Date @@ -84,10 +150,14 @@ $currentTimezone = (Get-TimeZone).Id $formattedString = "$currentDateTime - Time Zone: $currentTimezone" # Output the formatted string -$playerstats += [PSCustomObject]@{ - updated = $formattedString -} +$playerstats = [PSCustomObject]@{ + all = $playerstats_all + Intense = $playerstats_event_ibr + Casual = $playerstats_airoyale + official = $playerstats_official + updated = $formattedString +} write-output "Writing file" ($playerstats | convertto-json) | out-file "$scriptroot/../data/player_last_stats.json"