Compare commits

...

2 Commits

  1. 30
      public/elotracker/Tracker.php
  2. 6
      public/elotracker/update.php

@ -208,10 +208,20 @@ class Account {
$currentElo->rank = $fetchedElo->rank; $currentElo->rank = $fetchedElo->rank;
$currentElo->points = $fetchedElo->leaguePoints; $currentElo->points = $fetchedElo->leaguePoints;
$date = (new DateTime("now"))->format("Y-m-d H:i:s"); $latestMatchTimestamp = $this->getLatestMatchTimestamp();
$eloEntries[$date] = $currentElo;
$conn = new MySQLConnection(); $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(" $sqlAccountId = $conn->query("
SELECT id SELECT id
@ -224,7 +234,7 @@ class Account {
(accountId, date, tier, `rank`, points) (accountId, date, tier, `rank`, points)
VALUES (?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?)
")->execute([ ")->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` = ? WHERE `puuid` = ?
")->execute([$this->gameName, $this->tagLine, $this->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 { class Elo {

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

Loading…
Cancel
Save