This commit is contained in:
Lanta 2023-11-08 20:01:42 +01:00
parent ed96c74a04
commit f374e81b3e

View file

@ -13,8 +13,8 @@ $dataPoints = array(
?> ?>
<?php <?php
$dataPoints = array(); $dataPointsPerPlayer = [];
$directory = './data/killstats'; $directory = 'data/killstats';
// Check if the directory exists // Check if the directory exists
if (!is_dir($directory)) { if (!is_dir($directory)) {
@ -33,12 +33,19 @@ if ($handle = opendir($directory)) {
// Decode JSON data to PHP array // Decode JSON data to PHP array
$jsonArray = json_decode($content, true); $jsonArray = json_decode($content, true);
// Extract playername
$playername = $jsonArray['stats']['playername'];
// Process the date // Process the date
$date = new DateTime($jsonArray['created']); $date = new DateTime($jsonArray['created']);
$label = $date->format('m-d'); // Month-Day format $label = $date->format('m-d'); // Month-Day format
// Add to dataPoints // Initialize player array if not existing
$dataPoints[] = array( if (!isset($dataPointsPerPlayer[$playername])) {
$dataPointsPerPlayer[$playername] = [];
}
// Add to dataPoints for this player
$dataPointsPerPlayer[$playername][] = array(
"y" => $jsonArray['winplace'], "y" => $jsonArray['winplace'],
"label" => $label "label" => $label
); );
@ -47,11 +54,19 @@ if ($handle = opendir($directory)) {
closedir($handle); closedir($handle);
} }
// Output the array // Now, $dataPointsPerPlayer is an array that contains an array of data points for each player
print_r($dataPoints); // You can access the data for a specific player like this:
// $playerData = $dataPointsPerPlayer['Lanta01'];
// Output the array for debugging purposes
echo '<pre>';
print_r($dataPointsPerPlayer);
echo '</pre>';
?> ?>
<!DOCTYPE HTML> <!DOCTYPE HTML>
<html> <html>
<head> <head>