From 5ab71a0292c5832ffa5e0d0348ea0e24934d9797 Mon Sep 17 00:00:00 2001 From: Valentin Kaelin Date: Sun, 12 Jan 2020 01:31:28 +0100 Subject: [PATCH] feat: add records tab --- .../Summoner/Records/RecordCard.vue | 77 +++++++ client/src/layouts/Default.vue | 5 + client/src/router.js | 6 + client/src/store/modules/summoner.js | 22 +- client/src/views/SummonerRecords.vue | 197 ++++++++++++++++++ .../Controllers/Http/SummonerController.js | 11 + server/app/Repositories/MatchRepository.js | 143 +++++++++---- server/start/routes.js | 1 + 8 files changed, 424 insertions(+), 38 deletions(-) create mode 100644 client/src/components/Summoner/Records/RecordCard.vue create mode 100644 client/src/views/SummonerRecords.vue diff --git a/client/src/components/Summoner/Records/RecordCard.vue b/client/src/components/Summoner/Records/RecordCard.vue new file mode 100644 index 0000000..60bbc2b --- /dev/null +++ b/client/src/components/Summoner/Records/RecordCard.vue @@ -0,0 +1,77 @@ + + + + + diff --git a/client/src/layouts/Default.vue b/client/src/layouts/Default.vue index d2e3827..90e8e9d 100644 --- a/client/src/layouts/Default.vue +++ b/client/src/layouts/Default.vue @@ -73,6 +73,11 @@ class="ml-4 pb-2 border-b-2 border-transparent text-blue-300 cursor-pointer hover:text-blue-100" exact >champions + records diff --git a/client/src/router.js b/client/src/router.js index 67921da..90d422a 100644 --- a/client/src/router.js +++ b/client/src/router.js @@ -5,6 +5,7 @@ import { axios } from './plugins/axios' import Home from '@/views/Home.vue' import Summoner from '@/views/Summoner.vue' import SummonerChampions from '@/views/SummonerChampions.vue' +import SummonerRecords from '@/views/SummonerRecords.vue' Vue.use(Router) @@ -30,6 +31,11 @@ const router = new Router({ name: 'summonerChampions', component: SummonerChampions }, + { + path: '/summoner/:region/:name/records', + name: 'summonerRecords', + component: SummonerRecords + }, ] }) diff --git a/client/src/store/modules/summoner.js b/client/src/store/modules/summoner.js index 7ab3864..139b7cc 100644 --- a/client/src/store/modules/summoner.js +++ b/client/src/store/modules/summoner.js @@ -1,5 +1,5 @@ import { axios } from '@/plugins/axios' -import { createMatchData, createBasicSummonerData } from '@/helpers/summoner' +import { createMatchData, createBasicSummonerData, createRecordsData } from '@/helpers/summoner' export const namespaced = true @@ -23,12 +23,17 @@ export const state = { list: [], championsLoaded: false }, + records: { + list: [], + recordsLoaded: false + }, } export const mutations = { BASIC_REQUEST(state) { state.basic.status = 'loading' state.champions.championsLoaded = false + state.records.recordsLoaded = false state.overview.loaded = false }, CHAMPIONS_NOT_FOUND(state) { @@ -47,6 +52,7 @@ export const mutations = { state.overview.matchIndex += newMatches.length state.overview.stats = stats state.champions.championsLoaded = false + state.records.recordsLoaded = false }, OVERVIEW_FOUND(state, infos) { state.overview.matches = infos.matches @@ -54,6 +60,10 @@ export const mutations = { state.overview.stats = infos.stats state.overview.loaded = true }, + RECORDS_FOUND(state, { records }) { + state.records.list = records + state.records.recordsLoaded = true + }, SUMMONER_FOUND(state, infos) { state.basic.account = infos.account state.basic.current = infos.current @@ -88,7 +98,7 @@ export const actions = { console.log('Summoner not found - store') } } catch (error) { - if(error.message !== 'Summoner changed') { + if (error.message !== 'Summoner changed') { commit('SUMMONER_NOT_FOUND') } console.log(error) @@ -122,6 +132,14 @@ export const actions = { console.log(resp.data) resp.data.matches = createMatchData(resp.data.matchesDetails) commit('OVERVIEW_FOUND', resp.data) + }, + async recordsRequest({ commit }) { + const resp = await axios(({ url: 'summoner-records', data: { puuid: state.basic.account.puuid }, method: 'POST' })).catch(() => { }) + console.log('---RECORDS---') + console.log(resp.data) + const records = resp.data ? createRecordsData(resp.data) : {} + + commit('RECORDS_FOUND', { records }) } } diff --git a/client/src/views/SummonerRecords.vue b/client/src/views/SummonerRecords.vue new file mode 100644 index 0000000..81bd6f1 --- /dev/null +++ b/client/src/views/SummonerRecords.vue @@ -0,0 +1,197 @@ + + + diff --git a/server/app/Controllers/Http/SummonerController.js b/server/app/Controllers/Http/SummonerController.js index ed7c19b..87336df 100644 --- a/server/app/Controllers/Http/SummonerController.js +++ b/server/app/Controllers/Http/SummonerController.js @@ -104,6 +104,17 @@ class SummonerController { console.timeEnd('championsRequest') return response.json(championStats) } + + /** + * POST: get records view summoner data + */ + async records({ request, response }) { + const puuid = request.input('puuid') + console.time('recordsRequest') + const records = await MatchRepository.records(puuid) + console.timeEnd('recordsRequest') + return response.json(records[0]) + } } module.exports = SummonerController diff --git a/server/app/Repositories/MatchRepository.js b/server/app/Repositories/MatchRepository.js index c911ffa..50e54e4 100644 --- a/server/app/Repositories/MatchRepository.js +++ b/server/app/Repositories/MatchRepository.js @@ -35,12 +35,12 @@ class MatchRepository { count: { $sum: 1 }, wins: { $sum: { - $cond: [{ $eq: ["$result", "Win"] }, 1, 0] + $cond: [{ $eq: ['$result', 'Win'] }, 1, 0] } }, losses: { $sum: { - $cond: [{ $eq: ["$result", "Fail"] }, 1, 0] + $cond: [{ $eq: ['$result', 'Fail'] }, 1, 0] } }, ...groupParams @@ -57,10 +57,10 @@ class MatchRepository { */ championStats(puuid, limit = 5) { const groupParams = { - champion: { $first: "$champion" }, - kills: { $sum: "$stats.kills" }, - deaths: { $sum: "$stats.deaths" }, - assists: { $sum: "$stats.assists" }, + champion: { $first: '$champion' }, + kills: { $sum: '$stats.kills' }, + deaths: { $sum: '$stats.deaths' }, + assists: { $sum: '$stats.assists' }, } const finalSteps = [ { $sort: { 'count': -1 } }, @@ -74,7 +74,7 @@ class MatchRepository { * @param puuid of the summoner */ championClassStats(puuid) { - const groupId = { "$arrayElemAt": ["$champion.roles", 0] } + const groupId = { '$arrayElemAt': ['$champion.roles', 0] } return this._aggregate(puuid, {}, [], groupId, {}, []) } @@ -88,18 +88,18 @@ class MatchRepository { gamemode: { $eq: Number(queue) }, } : {} const groupParams = { - time: { $sum: "$time" }, - gameLength: { $avg: "$time" }, - date: { $max: "$date" }, - champion: { $first: "$champion" }, - kills: { $sum: "$stats.kills" }, - deaths: { $sum: "$stats.deaths" }, - assists: { $sum: "$stats.assists" }, - minions: { $avg: "$stats.minions" }, - gold: { $avg: "$stats.gold" }, - dmgChamp: { $avg: "$stats.dmgChamp" }, - dmgTaken: { $avg: "$stats.dmgTaken" }, - kp: { $avg: "$stats.kp" }, + time: { $sum: '$time' }, + gameLength: { $avg: '$time' }, + date: { $max: '$date' }, + champion: { $first: '$champion' }, + kills: { $sum: '$stats.kills' }, + deaths: { $sum: '$stats.deaths' }, + assists: { $sum: '$stats.assists' }, + minions: { $avg: '$stats.minions' }, + gold: { $avg: '$stats.gold' }, + dmgChamp: { $avg: '$stats.dmgChamp' }, + dmgTaken: { $avg: '$stats.dmgTaken' }, + kp: { $avg: '$stats.kp' }, } const finalSteps = [ { $sort: { 'count': -1 } } @@ -121,17 +121,88 @@ class MatchRepository { */ globalStats(puuid) { const groupParams = { - time: { $sum: "$time" }, - kills: { $sum: "$stats.kills" }, - deaths: { $sum: "$stats.deaths" }, - assists: { $sum: "$stats.assists" }, - minions: { $sum: "$stats.minions" }, - vision: { $sum: "$stats.vision" }, - kp: { $avg: "$stats.kp" }, + time: { $sum: '$time' }, + kills: { $sum: '$stats.kills' }, + deaths: { $sum: '$stats.deaths' }, + assists: { $sum: '$stats.assists' }, + minions: { $sum: '$stats.minions' }, + vision: { $sum: '$stats.vision' }, + kp: { $avg: '$stats.kp' }, } return this._aggregate(puuid, {}, [], null, groupParams, []) } + /** + * Get Summoner's all records + * @param puuid of the summoner + */ + records(puuid) { + return this.Match.query().aggregate([ + { + $match: { + summoner_puuid: puuid, + result: { $not: { $eq: 'Remake' } }, + 'stats.kda': { $not: { $eq: '∞' } }, + gamemode: { $nin: [800, 810, 820, 830, 840, 850] }, + } + }, + { + $group: { + _id: null, + maxKills: { $max: '$stats.kills' }, + maxDeaths: { $max: '$stats.deaths' }, + maxAssists: { $max: '$stats.assists' }, + maxGold: { $max: '$stats.gold' }, + maxTime: { $max: '$time' }, + maxMinions: { $max: '$stats.minions' }, + maxKda: { $max: '$stats.kda' }, + maxDmgTaken: { $max: '$stats.dmgTaken' }, + maxDmgChamp: { $max: '$stats.dmgChamp' }, + maxDmgObj: { $max: '$stats.dmgObj' }, + maxKp: { $max: '$stats.kp' }, + maxVision: { $max: '$stats.vision' }, + docs: { + '$push': { + 'champion': '$champion', + 'gameId': '$gameId', + 'kills': '$stats.kills', + 'deaths': '$stats.deaths', + 'assists': '$stats.assists', + 'gold': '$stats.gold', + 'time': '$time', + 'minions': '$stats.minions', + 'kda': '$stats.kda', + 'dmgTaken': '$stats.dmgTaken', + 'dmgChamp': '$stats.dmgChamp', + 'dmgObj': '$stats.dmgObj', + 'kp': '$stats.kp', + 'vision': '$stats.vision', + 'result': '$result', + 'date': '$date', + } + } + } + }, + { + $project: { + _id: 0, + maxKills: { $arrayElemAt: [{ $filter: { input: '$docs', cond: { $eq: ['$$this.kills', '$maxKills'] } } }, 0] }, + maxDeaths: { $arrayElemAt: [{ $filter: { input: '$docs', cond: { $eq: ['$$this.deaths', '$maxDeaths'] } } }, 0] }, + maxAssists: { $arrayElemAt: [{ $filter: { input: '$docs', cond: { $eq: ['$$this.assists', '$maxAssists'] } } }, 0] }, + maxGold: { $arrayElemAt: [{ $filter: { input: '$docs', cond: { $eq: ['$$this.gold', '$maxGold'] } } }, 0] }, + maxTime: { $arrayElemAt: [{ $filter: { input: '$docs', cond: { $eq: ['$$this.time', '$maxTime'] } } }, 0] }, + maxMinions: { $arrayElemAt: [{ $filter: { input: '$docs', cond: { $eq: ['$$this.minions', '$maxMinions'] } } }, 0] }, + maxKda: { $arrayElemAt: [{ $filter: { input: '$docs', cond: { $eq: ['$$this.kda', '$maxKda'] } } }, 0] }, + maxDmgTaken: { $arrayElemAt: [{ $filter: { input: '$docs', cond: { $eq: ['$$this.dmgTaken', '$maxDmgTaken'] } } }, 0] }, + maxDmgChamp: { $arrayElemAt: [{ $filter: { input: '$docs', cond: { $eq: ['$$this.dmgChamp', '$maxDmgChamp'] } } }, 0] }, + maxDmgObj: { $arrayElemAt: [{ $filter: { input: '$docs', cond: { $eq: ['$$this.dmgObj', '$maxDmgObj'] } } }, 0] }, + maxKp: { $arrayElemAt: [{ $filter: { input: '$docs', cond: { $eq: ['$$this.kp', '$maxKp'] } } }, 0] }, + maxVision: { $arrayElemAt: [{ $filter: { input: '$docs', cond: { $eq: ['$$this.vision', '$maxVision'] } } }, 0] }, + } + } + ]) + } + /** * Get Summoner's statistics for the 5 differnt roles * @param puuid of the summoner @@ -143,10 +214,10 @@ class MatchRepository { const finalSteps = [ { $project: { - role: "$_id", - count: "$count", - wins: "$wins", - losses: "$losses", + role: '$_id', + count: '$count', + wins: '$wins', + losses: '$losses', } } ] @@ -159,17 +230,17 @@ class MatchRepository { */ mates(puuid) { const intermediateSteps = [ - { $unwind: "$allyTeam" }, + { $unwind: '$allyTeam' }, ] const groupParams = { - account_id: { $first: "$account_id" }, - name: { $first: "$allyTeam.name" }, - mateId: { $first: "$allyTeam.account_id" }, + account_id: { $first: '$account_id' }, + name: { $first: '$allyTeam.name' }, + mateId: { $first: '$allyTeam.account_id' }, } const finalSteps = [ { - "$addFields": { - "idEq": { "$eq": ["$mateId", "$account_id"] } + '$addFields': { + 'idEq': { '$eq': ['$mateId', '$account_id'] } } }, { diff --git a/server/start/routes.js b/server/start/routes.js index d02471b..3aadc76 100644 --- a/server/start/routes.js +++ b/server/start/routes.js @@ -28,6 +28,7 @@ Route.get('/', async () => { Route.post('/summoner-basic', 'SummonerController.basic') Route.post('/summoner-overview', 'SummonerController.overview') Route.post('/summoner-champions', 'SummonerController.champions') +Route.post('/summoner-records', 'SummonerController.records') Route.post('/ddragon', 'DDragonController.index') Route.post('/match', 'MatchController.index') Route.post('/match-details', 'MatchController.show')