From 9a0d062b4d604b14f56de79c9d06bbab1d99733f Mon Sep 17 00:00:00 2001 From: Benjamin Kraft Date: Sat, 15 Jun 2024 13:54:04 +0200 Subject: [PATCH] tracker->entries now unix timestamp as key --- public/elotracker/Tracker.php | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/public/elotracker/Tracker.php b/public/elotracker/Tracker.php index a20e46d..c54bcf5 100644 --- a/public/elotracker/Tracker.php +++ b/public/elotracker/Tracker.php @@ -16,6 +16,11 @@ class Tracker { */ public array $entries; + /** + * @var Elo[][] + */ + public array $entriesByDateString; + public function __construct() { $this->conn = new MySQLConnection(); $this->readAccounts(); @@ -45,27 +50,30 @@ class Tracker { ORDER BY accounts.puuid, date "); - $result = []; + $this->entries = []; + $this->entriesByDateString = []; while ($row = $sql->fetch_assoc()) { $puuid = $row["puuid"]; - $date = $row["date"]; - if (!isset($result[$puuid])) - $result[$puuid] = []; + if (!isset($this->entries[$puuid])) + $this->entries[$puuid] = []; - if (!$date) - continue; + if (!isset($this->entriesByDateString[$puuid])) + $this->entriesByDateString[$puuid] = []; - $elo = new Elo(); - $elo->tier = $row["tier"]; - $elo->rank = $row["rank"]; - $elo->points = $row["points"]; + if ($dateString = $row["date"]){ + $elo = new Elo(); + $elo->tier = $row["tier"]; + $elo->rank = $row["rank"]; + $elo->points = $row["points"]; - $result[$puuid][$date] = $elo; - } + $datetime = new DateTime($dateString); + $this->entries[$puuid][$datetime->getTimestamp()] = $elo; + $this->entriesByDateString[$puuid][$dateString] = $elo; + } - $this->entries = $result; + } } /**