From 095562419e5f1068535ba41fd4cdf427f4c38488 Mon Sep 17 00:00:00 2001 From: Sheikah45 Date: Thu, 2 Sep 2021 08:51:02 -0400 Subject: [PATCH] Use gamePlayerStats.scoreTime to determine date of leaderBoardRatingJournal --- public/js/app/leaderboards.js | 21 ++++++++++++++++----- scripts/extractor.js | 2 +- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/public/js/app/leaderboards.js b/public/js/app/leaderboards.js index bf59a2b8..39004fb9 100755 --- a/public/js/app/leaderboards.js +++ b/public/js/app/leaderboards.js @@ -148,12 +148,23 @@ $(document).on('click', '.player', (function () { let pastYear = moment().subtract(1, 'years').format("YYYY-MM-DDTHH:mm:ss") + "Z"; $.ajax({ - url: apiURL + '/data/leaderboardRatingJournal?filter=gamePlayerStats.player.id==' + id + ';leaderboard.technicalName==' + ratingType + ';updateTime=ge=' + pastYear + ';deviationAfter=isnull=false&fields[leaderboardRatingJournal]=meanAfter,deviationAfter,updateTime', + url: apiURL + '/data/leaderboardRatingJournal?filter=gamePlayerStats.player.id==' + id + ';leaderboard.technicalName==' + ratingType + ';gamePlayerStats.scoreTime=ge=' + pastYear + ';deviationAfter=isnull=false&fields[leaderboardRatingJournal]=meanAfter,deviationAfter,gamePlayerStats&fields[gamePlayerStats]=scoreTime&include=gamePlayerStats', success: function (result) { - $.each(result.data, function (key, stats) { - var date = moment(stats.attributes.updateTime).format('MMM D, YYYY'); - var mean = stats.attributes.meanAfter; - var deviation = stats.attributes.deviationAfter; + + let gamePlayerStats = {}; + + $.each(result.included, function (key, object) { + if (object.type === "gamePlayerStats") { + gamePlayerStats[object.id] = object; + } + }); + + $.each(result.data, function (key, journal) { + var statsId = journal.relationships.gamePlayerStats.data.id; + var scoreTime = gamePlayerStats[statsId].attributes.scoreTime; + var date = moment(scoreTime).format('MMM D, YYYY'); + var mean = journal.attributes.meanAfter; + var deviation = journal.attributes.deviationAfter; labels.push(date); dataset.push(Math.round(mean - 3 * deviation)); }); diff --git a/scripts/extractor.js b/scripts/extractor.js index a0ca85d7..9f8e7553 100644 --- a/scripts/extractor.js +++ b/scripts/extractor.js @@ -49,7 +49,7 @@ module.exports.run = function run() { request(process.env.API_URL + "/data/leaderboardRating?include=player&sort=-rating&filter=leaderboard.id==1;updateTime=ge=" + pastMonth.format("YYYY-MM-DDTHH:mm:ss") + "Z", function (error, response, body) { if (error || response.statusCode > 210) { - console.log(moment().format("DD-MM-YYYY - HH:mm:ss") + " - There was an issue while fetching leaderboards 1v1:"); + console.log(moment().format("DD-MM-YYYY - HH:mm:ss") + " - There was an issue while fetching leaderboards global:"); console.error(error); if (response) console.trace(response.statusCode); return;