feat: filter by season now works 🎉

This commit is contained in:
Valentin Kaelin 2020-02-01 20:17:14 +01:00
parent 7beb635c80
commit d839eed7ad
10 changed files with 223 additions and 164 deletions

View file

@ -6,6 +6,7 @@
dir="rtl"
class="block appearance-none bg-transparent w-full px-4 pr-8 rounded-md cursor-pointer focus:outline-none group-hover:text-white"
>
<option :value="null" class="bg-blue-800">All seasons</option>
<option v-for="(s, index) in seasons" :key="index" :value="s" class="bg-blue-800">Season {{ s }}</option>
</select>
<div
@ -19,7 +20,7 @@
</template>
<script>
import { mapState } from 'vuex'
import { mapActions, mapState } from 'vuex'
export default {
data() {
@ -42,7 +43,9 @@ export default {
methods: {
filterSeason() {
console.log('filter season', this.season)
}
this.updateSeason(this.season)
},
...mapActions('summoner', ['updateSeason'])
}
}
</script>

View file

@ -1,4 +1,6 @@
import axiosHttp from 'axios'
import router from '../router'
import store from '../store'
export const axios = axiosHttp
@ -11,8 +13,16 @@ const axiosSource = CancelToken.source()
axios.defaults.axiosSource = axiosSource
axios.defaults.cancelToken = axiosSource.token
// Add season number to data if the route need it
axios.interceptors.request.use(function (config) {
if (config.url !== 'summoner-basic' && router.currentRoute.meta.season) {
config.data.season = store.state.summoner.basic.currentSeason
}
return config
})
export default {
install (Vue) {
install(Vue) {
Vue.prototype.$axios = axiosHttp
}
}
}

View file

@ -25,17 +25,26 @@ const router = new Router({
{
path: '/summoner/:region/:name',
name: 'summoner',
component: Summoner
component: Summoner,
meta: {
season: true
}
},
{
path: '/summoner/:region/:name/champions',
name: 'summonerChampions',
component: SummonerChampions
component: SummonerChampions,
meta: {
season: true
}
},
{
path: '/summoner/:region/:name/records',
name: 'summonerRecords',
component: SummonerRecords
component: SummonerRecords,
meta: {
season: true
}
},
{
path: '/summoner/:region/:name/live',

View file

@ -6,7 +6,7 @@ export const namespaced = true
export const state = {
basic: {
account: {},
currentSeason: 10,
currentSeason: null,
matchList: [],
ranked: {},
seasons: [],
@ -37,6 +37,7 @@ export const state = {
export const mutations = {
BASIC_REQUEST(state) {
state.basic.status = 'loading'
state.basic.currentSeason = null
state.champions.championsLoaded = false
state.records.recordsLoaded = false
state.overview.loaded = false
@ -93,7 +94,14 @@ export const mutations = {
state.live.match = {}
state.live.playing = false
state.live.liveLoaded = false
}
},
UPDATE_SEASON(state, { season }) {
state.basic.currentSeason = season
state.overview.loaded = false
state.champions.championsLoaded = false
state.records.recordsLoaded = false
},
}
export const actions = {
@ -171,6 +179,9 @@ export const actions = {
const records = resp.data ? createRecordsData(resp.data) : {}
commit('RECORDS_FOUND', { records })
},
updateSeason({ commit }, season) {
commit('UPDATE_SEASON', { season })
}
}

View file

@ -63,6 +63,9 @@ export default {
},
watch: {
overviewLoaded() {
this.fetchData()
},
summonerFound() {
this.fetchData()
}

View file

@ -24,6 +24,7 @@ export default {
data() {
return {
queue: null,
searchChampions: ''
}
},
@ -53,6 +54,9 @@ export default {
},
watch: {
championsLoaded() {
this.fetchData()
},
summonerFound() {
this.fetchData()
}
@ -65,13 +69,13 @@ export default {
methods: {
fetchData() {
if (!this.championsLoaded && this.summonerFound) {
this.championsRequest()
this.championsRequest(this.queue)
}
},
filterByQueue(queue) {
queue = Number(queue)
queue = queue === -1 ? null : queue
this.championsRequest(queue)
this.queue = queue === -1 ? null : queue
this.championsRequest(this.queue)
},
updateSearch(search) {
this.searchChampions = search

View file

@ -1,150 +1,148 @@
<template>
<div key="records" class="">
<div key="records">
<template v-if="!recordsLoaded || (recordsLoaded && records.maxKda)">
<div class="">
<div class="mx-4 text-blue-200 text-2xl border-b-2 border-blue-800 blue-900">basics</div>
<div class="-mx-2 flex flex-wrap">
<template v-if="recordsLoaded">
<RecordCard
color="text-blue-400"
property="kda"
:record="records.maxKda"
title="best kda"
/>
<RecordCard
color="text-green-400"
property="kills"
:record="records.maxKills"
title="most kills"
/>
<RecordCard
color="text-blue-500"
property="assists"
:record="records.maxAssists"
title="most assists"
/>
<RecordCard
color="text-red-500"
property="deaths"
:record="records.maxDeaths"
title="most deaths"
/>
<RecordCard
color="text-yellow-600"
property="gold"
:record="records.maxGold"
title="most gold earned"
/>
<RecordCard
color="text-white"
property="time"
:record="records.maxTime"
title="longest game"
/>
<RecordCard
color="text-pink-500"
property="minions"
:record="records.maxMinions"
title="most minions killed"
/>
</template>
<template v-else>
<div
v-for="index in 7"
:key="index"
style="width: 288px; height: 146px;"
class="mt-6 mx-2"
<div class="mx-4 text-blue-200 text-2xl border-b-2 border-blue-800 blue-900">basics</div>
<div class="-mx-2 flex flex-wrap">
<template v-if="recordsLoaded">
<RecordCard
color="text-blue-400"
property="kda"
:record="records.maxKda"
title="best kda"
/>
<RecordCard
color="text-green-400"
property="kills"
:record="records.maxKills"
title="most kills"
/>
<RecordCard
color="text-blue-500"
property="assists"
:record="records.maxAssists"
title="most assists"
/>
<RecordCard
color="text-red-500"
property="deaths"
:record="records.maxDeaths"
title="most deaths"
/>
<RecordCard
color="text-yellow-600"
property="gold"
:record="records.maxGold"
title="most gold earned"
/>
<RecordCard
color="text-white"
property="time"
:record="records.maxTime"
title="longest game"
/>
<RecordCard
color="text-pink-500"
property="minions"
:record="records.maxMinions"
title="most minions killed"
/>
</template>
<template v-else>
<div
v-for="index in 7"
:key="index"
style="width: 288px; height: 146px;"
class="mt-6 mx-2"
>
<content-loader
:height="146"
:width="288"
:speed="2"
primary-color="#17314f"
secondary-color="#2b6cb0"
>
<content-loader
:height="146"
:width="288"
:speed="2"
primary-color="#17314f"
secondary-color="#2b6cb0"
>
<rect x="0" y="0" rx="8" ry="8" width="288" height="146" />
</content-loader>
</div>
</template>
</div>
<div
class="mt-3 mx-4 text-blue-200 text-2xl border-b-2 border-blue-800 blue-900"
>game impact</div>
<div class="-mx-2 flex flex-wrap">
<template v-if="recordsLoaded">
<RecordCard
color="text-yellow-400"
property="dmgTaken"
:record="records.maxDmgTaken"
title="highest damage taken"
/>
<RecordCard
color="text-red-400"
property="dmgChamp"
:record="records.maxDmgChamp"
title="highest damage to champions"
/>
<RecordCard
color="text-yellow-400"
property="dmgObj"
:record="records.maxDmgObj"
title="highest damage to objectives"
/>
<RecordCard
color="text-green-400"
property="kp"
:record="records.maxKp"
title="highest kill participation"
/>
</template>
<template v-else>
<div
v-for="index in 4"
:key="index"
style="width: 288px; height: 146px;"
class="mt-6 mx-2"
<rect x="0" y="0" rx="8" ry="8" width="288" height="146" />
</content-loader>
</div>
</template>
</div>
<div
class="mt-3 mx-4 text-blue-200 text-2xl border-b-2 border-blue-800 blue-900"
>game impact</div>
<div class="-mx-2 flex flex-wrap">
<template v-if="recordsLoaded">
<RecordCard
color="text-yellow-400"
property="dmgTaken"
:record="records.maxDmgTaken"
title="highest damage taken"
/>
<RecordCard
color="text-red-400"
property="dmgChamp"
:record="records.maxDmgChamp"
title="highest damage to champions"
/>
<RecordCard
color="text-yellow-400"
property="dmgObj"
:record="records.maxDmgObj"
title="highest damage to objectives"
/>
<RecordCard
color="text-green-400"
property="kp"
:record="records.maxKp"
title="highest kill participation"
/>
</template>
<template v-else>
<div
v-for="index in 4"
:key="index"
style="width: 288px; height: 146px;"
class="mt-6 mx-2"
>
<content-loader
:height="146"
:width="288"
:speed="2"
primary-color="#17314f"
secondary-color="#2b6cb0"
>
<content-loader
:height="146"
:width="288"
:speed="2"
primary-color="#17314f"
secondary-color="#2b6cb0"
>
<rect x="0" y="0" rx="8" ry="8" width="288" height="146" />
</content-loader>
</div>
</template>
</div>
<div class="mt-3 mx-4 text-blue-200 text-2xl border-b-2 border-blue-800 blue-900">team work</div>
<div class="-mx-2 flex flex-wrap">
<template v-if="recordsLoaded">
<RecordCard
color="text-blue-500"
property="vision"
:record="records.maxVision"
title="highest vision score"
/>
</template>
<template v-else>
<div
v-for="index in 1"
:key="index"
style="width: 288px; height: 146px;"
class="mt-6 mx-2"
<rect x="0" y="0" rx="8" ry="8" width="288" height="146" />
</content-loader>
</div>
</template>
</div>
<div class="mt-3 mx-4 text-blue-200 text-2xl border-b-2 border-blue-800 blue-900">team work</div>
<div class="-mx-2 flex flex-wrap">
<template v-if="recordsLoaded">
<RecordCard
color="text-blue-500"
property="vision"
:record="records.maxVision"
title="highest vision score"
/>
</template>
<template v-else>
<div
v-for="index in 1"
:key="index"
style="width: 288px; height: 146px;"
class="mt-6 mx-2"
>
<content-loader
:height="146"
:width="288"
:speed="2"
primary-color="#17314f"
secondary-color="#2b6cb0"
>
<content-loader
:height="146"
:width="288"
:speed="2"
primary-color="#17314f"
secondary-color="#2b6cb0"
>
<rect x="0" y="0" rx="8" ry="8" width="288" height="146" />
</content-loader>
</div>
</template>
</div>
<rect x="0" y="0" rx="8" ry="8" width="288" height="146" />
</content-loader>
</div>
</template>
</div>
</template>
<template v-if="recordsLoaded && !records.maxKda">
@ -176,6 +174,9 @@ export default {
},
watch: {
recordsLoaded() {
this.fetchData()
},
summonerFound() {
this.fetchData()
}

View file

@ -87,12 +87,17 @@ class SummonerController {
)
// MATCHES BASIC
const gameIds = summonerDB.matchList.slice(0, 10).map(({ gameId }) => gameId)
const gameIds = summonerDB.matchList.slice(0)
.filter(m => {
return season ? m.seasonMatch === season : true
})
.slice(0, 10)
.map(({ gameId }) => gameId)
finalJSON.matchesDetails = await MatchService.getMatches(account, gameIds, summonerDB)
// STATS
console.time('STATS')
finalJSON.stats = await StatsService.getSummonerStats(account)
finalJSON.stats = await StatsService.getSummonerStats(account, season)
console.timeEnd('STATS')
// SAVE IN DB
@ -108,8 +113,9 @@ class SummonerController {
async champions({ request, response }) {
const puuid = request.input('puuid')
const queue = request.input('queue')
const season = request.input('season')
console.time('championsRequest')
const championStats = await MatchRepository.championCompleteStats(puuid, queue)
const championStats = await MatchRepository.championCompleteStats(puuid, queue, season)
console.timeEnd('championsRequest')
return response.json(championStats)
}
@ -119,8 +125,9 @@ class SummonerController {
*/
async records({ request, response }) {
const puuid = request.input('puuid')
const season = request.input('season')
console.time('recordsRequest')
const records = await MatchRepository.records(puuid)
const records = await MatchRepository.records(puuid, season)
console.timeEnd('recordsRequest')
return response.json(records[0])
}

View file

@ -18,6 +18,7 @@ class MatchRepository {
summoner_puuid: puuid,
result: { $not: { $eq: 'Remake' } },
gamemode: { $nin: [800, 810, 820, 830, 840, 850] },
season: this.season ? this.season : { $exists: true }
}
}
@ -92,11 +93,15 @@ class MatchRepository {
* Get Summoner's complete statistics for the all played champs
* @param puuid of the summoner
* @param queue of the matches to fetch, if null get all matches
* @param season of the matches to fetch, if null get all seasons
*/
championCompleteStats(puuid, queue) {
const matchParams = queue ? {
gamemode: { $eq: Number(queue) },
} : {}
championCompleteStats(puuid, queue, season) {
const matchParams = {}
if (queue) {
matchParams.gamemode = { $eq: Number(queue) }
}
this.season = season
const groupParams = {
time: { $sum: '$time' },
gameLength: { $avg: '$time' },
@ -145,8 +150,11 @@ class MatchRepository {
/**
* Get Summoner's all records
* @param puuid of the summoner
* @param season of the matches to fetch, if null get all seasons
*/
records(puuid) {
records(puuid, season) {
this.season = season
return this.Match.query().aggregate([
{
$match: {
@ -235,6 +243,8 @@ class MatchRepository {
* @param puuid of the summoner
*/
seasons(puuid) {
this.season = null
return this.Match.query().aggregate([
{
$match: {

View file

@ -8,7 +8,8 @@ class StatsService {
this.matchRepository = MatchRepository
}
async getSummonerStats(account) {
async getSummonerStats(account, season) {
this.matchRepository.season = season
const globalStats = await this.matchRepository.globalStats(account.puuid)
const gamemodeStats = await this.matchRepository.gamemodeStats(account.puuid)
const roleStats = await this.matchRepository.roleStats(account.puuid)