Merge remote-tracking branch 'origin/main'

main
Simon Lang 3 months ago
commit 829e882270
  1. 30
      public/elotracker/Tracker.php
  2. 6
      public/elotracker/update.php
  3. 3
      structure.sql

@ -208,10 +208,20 @@ class Account {
$currentElo->rank = $fetchedElo->rank;
$currentElo->points = $fetchedElo->leaguePoints;
$date = (new DateTime("now"))->format("Y-m-d H:i:s");
$eloEntries[$date] = $currentElo;
$latestMatchTimestamp = $this->getLatestMatchTimestamp();
$conn = new MySQLConnection();
$isMatchUnknown = $conn->query("
SELECT COUNT(date) = 0 AS match_unknown
FROM updates
WHERE date > FROM_UNIXTIME($latestMatchTimestamp) AND status = 'COMPLETE';
")->fetch_assoc()["match_unknown"];
$date = new DateTime();
if ($isMatchUnknown)
$date->setTimestamp($latestMatchTimestamp);
$eloEntries[$date->getTimestamp()] = $currentElo;
$sqlAccountId = $conn->query("
SELECT id
@ -224,7 +234,7 @@ class Account {
(accountId, date, tier, `rank`, points)
VALUES (?, ?, ?, ?, ?)
")->execute([
$sqlAccountId, $date, $currentElo->tier, $currentElo->rank, $currentElo->points
$sqlAccountId, $date->format("Y-m-d H:i:s"), $currentElo->tier, $currentElo->rank, $currentElo->points
]);
}
}
@ -245,6 +255,20 @@ class Account {
WHERE `puuid` = ?
")->execute([$this->gameName, $this->tagLine, $this->puuid]);
}
private function getLatestMatchTimestamp(): int {
$matchIdsRequest = new RiotRequest("lol/match/v5/matches/by-puuid/$this->puuid/ids");
$matchIdsRequest->useRouting();
$matchIdsRequest->setQueries([
"count" => 1,
"queue" => 420 // 5x5 solo queue
]);
$latestMatchId = $matchIdsRequest->run()[0];
$latestMatchRequest = new RiotRequest("lol/match/v5/matches/$latestMatchId");
$latestMatchRequest->useRouting();
return intval($latestMatchRequest->run()->info->gameEndTimestamp / 1000);
}
}
class Elo {

@ -50,4 +50,10 @@ $tracker->update(function($value){
sendEvent('progress', $value);
});
$conn->query("
UPDATE updates
SET status = 'COMPLETE'
WHERE status = 'RUNNING'
");
sendEvent("done", "");

@ -3,7 +3,7 @@
-- https://www.phpmyadmin.net/
--
-- Host: localhost
-- Generation Time: Jun 15, 2024 at 11:21 PM
-- Generation Time: Jun 25, 2024 at 01:07 AM
-- Server version: 8.0.37-0ubuntu0.22.04.3
-- PHP Version: 8.1.29
@ -63,6 +63,7 @@ CREATE TABLE IF NOT EXISTS `elo_entries` (
CREATE TABLE IF NOT EXISTS `updates` (
`id` int NOT NULL AUTO_INCREMENT,
`date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`status` enum('RUNNING','COMPLETE') CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT 'RUNNING',
PRIMARY KEY (`id`),
KEY `date` (`date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

Loading…
Cancel
Save