From dfd0c04fe78fc0b005595789656918d3a3d64d34 Mon Sep 17 00:00:00 2001 From: Valentin Kaelin Date: Sat, 25 Jan 2020 12:33:28 +0100 Subject: [PATCH] fix: kda issue in records tab and add season number to all matches --- server/app/Commands/EditMatch.js | 1 + server/app/Repositories/MatchRepository.js | 5 ++--- server/app/Transformers/MatchTransformer.js | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/server/app/Commands/EditMatch.js b/server/app/Commands/EditMatch.js index a37637d..721e682 100644 --- a/server/app/Commands/EditMatch.js +++ b/server/app/Commands/EditMatch.js @@ -56,6 +56,7 @@ class EditMatch extends Command { // All matches from the db const matches = await Match.all() const matchesArray = matches.toJSON() + console.log(`${matchesArray.length} matches to edit.`) // Create jobs const jobs = [] diff --git a/server/app/Repositories/MatchRepository.js b/server/app/Repositories/MatchRepository.js index 50e54e4..5710497 100644 --- a/server/app/Repositories/MatchRepository.js +++ b/server/app/Repositories/MatchRepository.js @@ -142,7 +142,6 @@ class MatchRepository { $match: { summoner_puuid: puuid, result: { $not: { $eq: 'Remake' } }, - 'stats.kda': { $not: { $eq: '∞' } }, gamemode: { $nin: [800, 810, 820, 830, 840, 850] }, } }, @@ -155,7 +154,7 @@ class MatchRepository { maxGold: { $max: '$stats.gold' }, maxTime: { $max: '$time' }, maxMinions: { $max: '$stats.minions' }, - maxKda: { $max: '$stats.kda' }, + maxKda: { $max: '$stats.realKda' }, maxDmgTaken: { $max: '$stats.dmgTaken' }, maxDmgChamp: { $max: '$stats.dmgChamp' }, maxDmgObj: { $max: '$stats.dmgObj' }, @@ -171,7 +170,7 @@ class MatchRepository { 'gold': '$stats.gold', 'time': '$time', 'minions': '$stats.minions', - 'kda': '$stats.kda', + 'kda': '$stats.realKda', 'dmgTaken': '$stats.dmgTaken', 'dmgChamp': '$stats.dmgChamp', 'dmgObj': '$stats.dmgObj', diff --git a/server/app/Transformers/MatchTransformer.js b/server/app/Transformers/MatchTransformer.js index 15a14f9..bded68c 100644 --- a/server/app/Transformers/MatchTransformer.js +++ b/server/app/Transformers/MatchTransformer.js @@ -25,6 +25,12 @@ class MatchTransformer { this.perkstyles = perkstyles.styles this.summonerSpells = summonerSpells this.sortTeamByRole = Helpers.sortTeamByRole + + // League of Legends seasons timestamps + this.seasons = { + 0: 9, + 1578628800000: 10 + } } /** @@ -42,11 +48,19 @@ class MatchTransformer { * Get global data about the match */ getGameInfos(match) { + // Get season number + const arrSeasons = Object.keys(this.seasons) + arrSeasons.push(match.gameCreation) + arrSeasons.sort() + const indexSeason = arrSeasons.indexOf(match.gameCreation) - 1 + const season = this.seasons[arrSeasons[indexSeason]] + return { map: match.mapId, gamemode: match.queueId, date: match.gameCreation, region: match.platformId.toLowerCase(), + season, time: match.gameDuration } } @@ -80,8 +94,10 @@ class MatchTransformer { if (stats.kills + stats.assists !== 0 && stats.deaths === 0) { stats.kda = '∞' + stats.realKda = stats.kills + stats.assists } else { stats.kda = +(stats.deaths === 0 ? 0 : ((stats.kills + stats.assists) / stats.deaths)).toFixed(2) + stats.realKda = stats.kda } // Percent stats / Per minute stats : only for detailed match