Merge pull request #47 from OpzekerIT/dev

IBR CASUAL OFFICIAL SEPERATED
This commit is contained in:
Lanta 2023-09-29 14:39:58 +02:00 committed by GitHub
commit 9187d1fc4c
2 changed files with 151 additions and 50 deletions

View file

@ -6,6 +6,7 @@ error_reporting(E_ALL);
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
@ -14,42 +15,67 @@ error_reporting(E_ALL);
<link rel="stylesheet" href="./includes/styles.css"> <link rel="stylesheet" href="./includes/styles.css">
<script src="./lib/sorttable.js"></script> <script src="./lib/sorttable.js"></script>
</head> </head>
<body> <body>
<?php include './includes/navigation.php'; ?> <?php include './includes/navigation.php'; ?>
<main> <main>
<section> <section>
<h2>Player Stats past 14 days</h2> <h2>Player Stats past 14 days</h2>
<?php <?php
include './config/config.php'; include './config/config.php';
$players_matches = json_decode(file_get_contents('./data/player_last_stats.json'), true); $players_matches = json_decode(file_get_contents('./data/player_last_stats.json'), true);
echo "<table border='1' class='sortable'>"; foreach ($players_matches as $key => $player_datas) {
echo "<tr> if ($key == 'updated') {
<th>Playername</th> continue;
<th>Deaths</th>
<th>Kills</th>
<th>Human Kills</th>
<th>Matches</th>
<th>K/D (Human)</th>
<th>K/D (All)</th>
</tr>";
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
} }
$player_name = $player_data['playername']; echo "<br>";
$deaths = number_format($player_data['deaths'], 2, ',', ''); echo "Stats for $key";
$kills = number_format($player_data['kills'], 2, ',', ''); echo "<table border='1' class='sortable'>";
$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 "<tr> echo "<tr>
<th>Playername</th>
<th>Deaths</th>
<th>Kills</th>
<th>Human Kills</th>
<th>Matches</th>
<th>K/D (Human)</th>
<th>K/D (All)</th>
</tr>";
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 "<tr>
<td>$player_name</td> <td>$player_name</td>
<td>$deaths</td> <td>$deaths</td>
<td>$kills</td> <td>$kills</td>
@ -58,23 +84,28 @@ error_reporting(E_ALL);
<td>$KD_H</td> <td>$KD_H</td>
<td>$KD_ALL</td> <td>$KD_ALL</td>
</tr>"; </tr>";
}
echo "</table>";
} }
echo "</table>";
echo "Last update: "; foreach ($players_matches as $key => $update) {
foreach ($players_matches as $player_data) { if ($key == 'updated'){
if (isset($player_data['updated'])) { echo "Last update: $update ";
echo $player_data['updated'];
break; // Once found, exit the loop
} }
} }
?>
</section>
</main>
<?php include './includes/footer.php'; ?>
?>
</section>
</main>
<?php include './includes/footer.php'; ?>
</body> </body>
</html> </html>

View file

@ -5,11 +5,13 @@ if ($PSScriptRoot.length -eq 0) {
else { else {
$scriptroot = $PSScriptRoot $scriptroot = $PSScriptRoot
} }
$matches = 5
function get-killstats { function get-killstats {
param ( param (
$player_name, $player_name,
$telemetry $telemetry,
$matchType,
$gameMode
) )
$attacks = @() $attacks = @()
foreach ($action in $telemetry) { foreach ($action in $telemetry) {
@ -25,17 +27,24 @@ function get-killstats {
humankills = ($kills | where-object { $_.victim.accountId -notlike 'ai.*' }).count humankills = ($kills | where-object { $_.victim.accountId -notlike 'ai.*' }).count
kills = $kills.count kills = $kills.count
deaths = ($attacks | where-object { $_.victim.name -eq $player_name }).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 $all_player_matches = get-content "$scriptroot/../data/player_matches.json" | convertfrom-json -Depth 100
$killstats = @() $killstats = @()
$i = 0
foreach ($player in $all_player_matches) { foreach ($player in $all_player_matches) {
$player_name = $player.playername $player_name = $player.playername
$i++
foreach ($match in $player.player_matches) { $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])" $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)" 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) { foreach ($player in $all_player_matches.playername) {
$deaths = (($killstats | where-object { $_.playername -eq $player }).deaths | Measure-Object -sum).sum $deaths = (($killstats | where-object { $_.playername -eq $player }).deaths | Measure-Object -sum).sum
$kills = (($killstats | where-object { $_.playername -eq $player }).kills | 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 $humankills = (($killstats | where-object { $_.playername -eq $player }).humankills | Measure-Object -sum).sum
$playerstats += [PSCustomObject]@{ $playerstats_all += [PSCustomObject]@{
playername = $player playername = $player
deaths = $deaths deaths = $deaths
kills = $kills kills = $kills
@ -74,6 +83,63 @@ foreach ($player in $all_player_matches.playername) {
KD_ALL = $kills / $deaths 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 $currentDateTime = Get-Date
@ -84,10 +150,14 @@ $currentTimezone = (Get-TimeZone).Id
$formattedString = "$currentDateTime - Time Zone: $currentTimezone" $formattedString = "$currentDateTime - Time Zone: $currentTimezone"
# Output the formatted string # 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" 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"