From e295141eb14619c8e0a1f5d5f52823c938e574f1 Mon Sep 17 00:00:00 2001 From: Valentin Kaelin Date: Sat, 21 Dec 2019 17:56:31 +0100 Subject: [PATCH] feat: add all champions stats --- client/src/components/SVGContainer.vue | 4 +- client/src/components/SearchForm.vue | 10 +- .../Summoner/Champions/ChampionsTable.vue | 271 ++++++++++++++++++ client/src/main.js | 6 +- client/src/store/modules/summoner.js | 16 ++ client/src/views/SummonerChampions.vue | 35 ++- .../Controllers/Http/SummonerController.js | 4 +- server/app/Repositories/MatchRepository.js | 11 +- 8 files changed, 337 insertions(+), 20 deletions(-) create mode 100644 client/src/components/Summoner/Champions/ChampionsTable.vue diff --git a/client/src/components/SVGContainer.vue b/client/src/components/SVGContainer.vue index cc2ac75..25ce9fe 100644 --- a/client/src/components/SVGContainer.vue +++ b/client/src/components/SVGContainer.vue @@ -1,10 +1,12 @@ + + + + diff --git a/client/src/main.js b/client/src/main.js index 6b04997..98b8fe9 100644 --- a/client/src/main.js +++ b/client/src/main.js @@ -20,7 +20,7 @@ Vue.filter('kilo', (value) => { Vue.filter('secToTime', (sec) => { const min = Math.floor(sec / 60) - const newSec = sec - min * 60 + const newSec = Math.floor(sec - min * 60) return min + 'm' + (newSec < 10 ? '0' + newSec : newSec) + 's' }) @@ -28,8 +28,8 @@ Vue.filter('percent', (value) => { return `${+value.toFixed(1)}%` }) -Vue.filter('round', (value) => { - return parseFloat(value.toFixed(2)) +Vue.filter('round', (value, decimals = 2) => { + return parseFloat(value.toFixed(decimals)) }) new Vue({ diff --git a/client/src/store/modules/summoner.js b/client/src/store/modules/summoner.js index 7a80d4a..cde0e99 100644 --- a/client/src/store/modules/summoner.js +++ b/client/src/store/modules/summoner.js @@ -6,6 +6,7 @@ export const namespaced = true export const state = { infos: { account: {}, + champions: [], matchIndex: 0, matchList: [], matches: [], @@ -14,11 +15,16 @@ export const state = { stats: {}, playing: false }, + championsLoaded: false, matchesLoading: false, status: '', } export const mutations = { + CHAMPIONS_FOUND(state, { champions }) { + state.infos.champions = champions + state.championsLoaded = true + }, MATCHES_LOADING(state) { state.matchesLoading = true }, @@ -30,6 +36,8 @@ export const mutations = { state.infos.matchIndex += newMatches.length state.infos.stats = stats + + state.championsLoaded = false }, SUMMONER_REQUEST(state) { state.status = 'loading' @@ -43,6 +51,7 @@ export const mutations = { state.infos.playing = infos.playing state.infos.stats = infos.stats state.status = 'found' + state.championsLoaded = false }, SUMMONER_NOT_FOUND(state) { state.status = 'error' @@ -50,6 +59,13 @@ export const mutations = { } export const actions = { + async championStats({ commit }) { + const resp = await axios(({ url: 'champions', data: { puuid: state.infos.account.puuid }, method: 'POST' })).catch(() => { }) + console.log('CHAMPIONS STATS') + console.log(resp.data) + + commit('CHAMPIONS_FOUND', { champions: resp.data }) + }, async moreMatches({ commit }) { commit('MATCHES_LOADING') diff --git a/client/src/views/SummonerChampions.vue b/client/src/views/SummonerChampions.vue index c3b3184..2ceccd3 100644 --- a/client/src/views/SummonerChampions.vue +++ b/client/src/views/SummonerChampions.vue @@ -1,7 +1,40 @@ + + diff --git a/server/app/Controllers/Http/SummonerController.js b/server/app/Controllers/Http/SummonerController.js index 337270f..d32a5a4 100644 --- a/server/app/Controllers/Http/SummonerController.js +++ b/server/app/Controllers/Http/SummonerController.js @@ -75,9 +75,9 @@ class SummonerController { async champions({ request, response }) { const puuid = request.input('puuid') - console.log('champions request', puuid) + console.time('championsRequest') const championStats = await StatsService.getChampionStats(puuid) - + console.timeEnd('championsRequest') return response.json(championStats) } } diff --git a/server/app/Repositories/MatchRepository.js b/server/app/Repositories/MatchRepository.js index 8068ece..fb6945d 100644 --- a/server/app/Repositories/MatchRepository.js +++ b/server/app/Repositories/MatchRepository.js @@ -85,15 +85,16 @@ class MatchRepository { championCompleteStats(puuid) { const groupParams = { time: { $sum: "$time" }, + gameLength: { $avg: "$time" }, + date: { $last: "$date" }, champion: { $first: "$champion" }, kills: { $sum: "$stats.kills" }, deaths: { $sum: "$stats.deaths" }, assists: { $sum: "$stats.assists" }, - minions: { $sum: "$stats.minions" }, - vision: { $sum: "$stats.vision" }, - gold: { $sum: "$stats.gold" }, - dmgChamp: { $sum: "$stats.dmgChamp" }, - dmgTaken: { $sum: "$stats.dmgTaken" }, + minions: { $avg: "$stats.minions" }, + gold: { $avg: "$stats.gold" }, + dmgChamp: { $avg: "$stats.dmgChamp" }, + dmgTaken: { $avg: "$stats.dmgTaken" }, kp: { $avg: "$stats.kp" }, } const finalSteps = [