feat: aggregate RecentActivity with matches data

This commit is contained in:
Kalane 2021-09-15 21:17:52 +02:00
parent 1f5afc3f54
commit 2a2fb61c58
6 changed files with 46 additions and 15 deletions

View file

@ -57,6 +57,7 @@
</template> </template>
<script> <script>
import { mapState } from 'vuex'
import Tooltip from '@/components/Common/Tooltip.vue' import Tooltip from '@/components/Common/Tooltip.vue'
export default { export default {
@ -64,15 +65,6 @@ export default {
Tooltip, Tooltip,
}, },
props: {
matches: {
type: Array,
default() {
return []
}
}
},
data() { data() {
return { return {
gridDays: [], gridDays: [],
@ -86,8 +78,14 @@ export default {
} }
}, },
computed: {
...mapState({
recentActivity: state => state.summoner.basic.recentActivity
}),
},
watch: { watch: {
matches() { recentActivity() {
this.fillGrid() this.fillGrid()
} }
}, },
@ -118,16 +116,15 @@ export default {
}, },
fillGrid() { fillGrid() {
// Add all the matches made by the summoner // Add all the matches made by the summoner
for (const key in this.matches) { for (const match of this.recentActivity) {
const match = this.matches[key] const matchTime = new Date(match.day)
const matchTime = new Date(match.timestamp)
const formattedTime = matchTime.toLocaleString(undefined, this.options) const formattedTime = matchTime.toLocaleString(undefined, this.options)
const dayOfTheMatch = this.gridDays.filter( const dayOfTheMatch = this.gridDays.filter(
e => e.date === formattedTime e => e.date === formattedTime
) )
if (dayOfTheMatch.length > 0) { if (dayOfTheMatch.length > 0) {
dayOfTheMatch[0].matches++ dayOfTheMatch[0].matches = match.count
} }
} }

View file

@ -114,7 +114,7 @@
</div> </div>
<div> <div>
<RecentActivity :matches="basic.matchList" /> <RecentActivity />
</div> </div>
</div> </div>
<div class="flex items-center justify-between"> <div class="flex items-center justify-between">

View file

@ -9,6 +9,7 @@ export const state = {
currentSeason: null, currentSeason: null,
matchList: [], matchList: [],
ranked: {}, ranked: {},
recentActivity: [],
seasons: [], seasons: [],
status: '', status: '',
}, },
@ -66,6 +67,7 @@ export const mutations = {
state.overview.matchesLoading = true state.overview.matchesLoading = true
}, },
MATCHES_FOUND(state, { newMatches, stats }) { MATCHES_FOUND(state, { newMatches, stats }) {
state.basic.recentActivity = stats.recentActivity
state.overview.matchesLoading = false state.overview.matchesLoading = false
state.overview.matches = [...state.overview.matches, ...newMatches] state.overview.matches = [...state.overview.matches, ...newMatches]
state.overview.matchIndex += newMatches.length state.overview.matchIndex += newMatches.length
@ -74,6 +76,7 @@ export const mutations = {
state.records.recordsLoaded = false state.records.recordsLoaded = false
}, },
OVERVIEW_FOUND(state, infos) { OVERVIEW_FOUND(state, infos) {
state.basic.recentActivity = infos.stats.recentActivity
state.overview.matches = infos.matches state.overview.matches = infos.matches
state.overview.matchIndex = infos.matches.length state.overview.matchIndex = infos.matches.length
state.overview.stats = infos.stats state.overview.stats = infos.stats
@ -87,6 +90,7 @@ export const mutations = {
state.basic.account = infos.account state.basic.account = infos.account
state.basic.matchList = infos.matchList state.basic.matchList = infos.matchList
state.basic.ranked = infos.ranked state.basic.ranked = infos.ranked
state.basic.recentActivity = infos.recentActivity
state.basic.seasons = infos.seasons.sort((a, b) => b - a) state.basic.seasons = infos.seasons.sort((a, b) => b - a)
state.basic.status = 'found' state.basic.status = 'found'
state.live.match = infos.current state.live.match = infos.current

View file

@ -43,6 +43,9 @@ export default class SummonersController {
// RANKED STATS // RANKED STATS
finalJSON.ranked = await SummonerService.getRanked(account, region) finalJSON.ranked = await SummonerService.getRanked(account, region)
// RECENT ACTIVITY
finalJSON.recentActivity = await StatsService.getRecentActivity(account.puuid)
} catch (e) { } catch (e) {
console.log(e) console.log(e)
console.timeEnd('BASIC_REQUEST') console.timeEnd('BASIC_REQUEST')

View file

@ -12,6 +12,25 @@ class MatchRepository {
AND matches.gamemode NOT IN (800, 810, 820, 830, 840, 850, 2000, 2010, 2020) AND matches.gamemode NOT IN (800, 810, 820, 830, 840, 850, 2000, 2010, 2020)
` `
public async recentActivity(puuid: string) {
const query = `
SELECT
to_timestamp(matches.date/1000)::date as day,
COUNT(match_players.id) as count
FROM
match_players
${this.JOIN_MATCHES}
WHERE
match_players.summoner_puuid = :puuid
GROUP BY
day
ORDER BY
day
`
const { rows } = await Database.rawQuery(query, { puuid })
return rows
}
public async globalStats(puuid: string) { public async globalStats(puuid: string) {
const query = ` const query = `
SELECT SELECT

View file

@ -4,6 +4,9 @@ import MatchRepository from 'App/Repositories/MatchRepository'
import BasicMatchSerializer from 'App/Serializers/BasicMatchSerializer' import BasicMatchSerializer from 'App/Serializers/BasicMatchSerializer'
class StatsService { class StatsService {
public async getRecentActivity(puuid: string) {
return MatchRepository.recentActivity(puuid)
}
public async getSummonerStats(puuid: string, season?: number) { public async getSummonerStats(puuid: string, season?: number) {
console.time('GLOBAL') console.time('GLOBAL')
const globalStats = await MatchRepository.globalStats(puuid) const globalStats = await MatchRepository.globalStats(puuid)
@ -45,6 +48,10 @@ class StatsService {
const mates = await MatchRepository.mates(puuid) const mates = await MatchRepository.mates(puuid)
console.timeEnd('MATES') console.timeEnd('MATES')
console.time('RECENT_ACTIVITY')
const recentActivity = await MatchRepository.recentActivity(puuid)
console.timeEnd('RECENT_ACTIVITY')
return { return {
global: globalStats, global: globalStats,
league: gamemodeStats, league: gamemodeStats,
@ -52,6 +59,7 @@ class StatsService {
champion: championStats, champion: championStats,
class: championClassStats, class: championClassStats,
mates, mates,
recentActivity,
} }
} }
} }