mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 12:57:28 +00:00
feat: aggregate RecentActivity with matches data
This commit is contained in:
parent
1f5afc3f54
commit
2a2fb61c58
6 changed files with 46 additions and 15 deletions
|
|
@ -57,6 +57,7 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { mapState } from 'vuex'
|
||||
import Tooltip from '@/components/Common/Tooltip.vue'
|
||||
|
||||
export default {
|
||||
|
|
@ -64,15 +65,6 @@ export default {
|
|||
Tooltip,
|
||||
},
|
||||
|
||||
props: {
|
||||
matches: {
|
||||
type: Array,
|
||||
default() {
|
||||
return []
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
gridDays: [],
|
||||
|
|
@ -86,8 +78,14 @@ export default {
|
|||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
...mapState({
|
||||
recentActivity: state => state.summoner.basic.recentActivity
|
||||
}),
|
||||
},
|
||||
|
||||
watch: {
|
||||
matches() {
|
||||
recentActivity() {
|
||||
this.fillGrid()
|
||||
}
|
||||
},
|
||||
|
|
@ -118,16 +116,15 @@ export default {
|
|||
},
|
||||
fillGrid() {
|
||||
// Add all the matches made by the summoner
|
||||
for (const key in this.matches) {
|
||||
const match = this.matches[key]
|
||||
const matchTime = new Date(match.timestamp)
|
||||
for (const match of this.recentActivity) {
|
||||
const matchTime = new Date(match.day)
|
||||
const formattedTime = matchTime.toLocaleString(undefined, this.options)
|
||||
|
||||
const dayOfTheMatch = this.gridDays.filter(
|
||||
e => e.date === formattedTime
|
||||
)
|
||||
if (dayOfTheMatch.length > 0) {
|
||||
dayOfTheMatch[0].matches++
|
||||
dayOfTheMatch[0].matches = match.count
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@
|
|||
</div>
|
||||
|
||||
<div>
|
||||
<RecentActivity :matches="basic.matchList" />
|
||||
<RecentActivity />
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center justify-between">
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ export const state = {
|
|||
currentSeason: null,
|
||||
matchList: [],
|
||||
ranked: {},
|
||||
recentActivity: [],
|
||||
seasons: [],
|
||||
status: '',
|
||||
},
|
||||
|
|
@ -66,6 +67,7 @@ export const mutations = {
|
|||
state.overview.matchesLoading = true
|
||||
},
|
||||
MATCHES_FOUND(state, { newMatches, stats }) {
|
||||
state.basic.recentActivity = stats.recentActivity
|
||||
state.overview.matchesLoading = false
|
||||
state.overview.matches = [...state.overview.matches, ...newMatches]
|
||||
state.overview.matchIndex += newMatches.length
|
||||
|
|
@ -74,6 +76,7 @@ export const mutations = {
|
|||
state.records.recordsLoaded = false
|
||||
},
|
||||
OVERVIEW_FOUND(state, infos) {
|
||||
state.basic.recentActivity = infos.stats.recentActivity
|
||||
state.overview.matches = infos.matches
|
||||
state.overview.matchIndex = infos.matches.length
|
||||
state.overview.stats = infos.stats
|
||||
|
|
@ -87,6 +90,7 @@ export const mutations = {
|
|||
state.basic.account = infos.account
|
||||
state.basic.matchList = infos.matchList
|
||||
state.basic.ranked = infos.ranked
|
||||
state.basic.recentActivity = infos.recentActivity
|
||||
state.basic.seasons = infos.seasons.sort((a, b) => b - a)
|
||||
state.basic.status = 'found'
|
||||
state.live.match = infos.current
|
||||
|
|
|
|||
|
|
@ -43,6 +43,9 @@ export default class SummonersController {
|
|||
|
||||
// RANKED STATS
|
||||
finalJSON.ranked = await SummonerService.getRanked(account, region)
|
||||
|
||||
// RECENT ACTIVITY
|
||||
finalJSON.recentActivity = await StatsService.getRecentActivity(account.puuid)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
console.timeEnd('BASIC_REQUEST')
|
||||
|
|
|
|||
|
|
@ -12,6 +12,25 @@ class MatchRepository {
|
|||
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) {
|
||||
const query = `
|
||||
SELECT
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@ import MatchRepository from 'App/Repositories/MatchRepository'
|
|||
import BasicMatchSerializer from 'App/Serializers/BasicMatchSerializer'
|
||||
|
||||
class StatsService {
|
||||
public async getRecentActivity(puuid: string) {
|
||||
return MatchRepository.recentActivity(puuid)
|
||||
}
|
||||
public async getSummonerStats(puuid: string, season?: number) {
|
||||
console.time('GLOBAL')
|
||||
const globalStats = await MatchRepository.globalStats(puuid)
|
||||
|
|
@ -45,6 +48,10 @@ class StatsService {
|
|||
const mates = await MatchRepository.mates(puuid)
|
||||
console.timeEnd('MATES')
|
||||
|
||||
console.time('RECENT_ACTIVITY')
|
||||
const recentActivity = await MatchRepository.recentActivity(puuid)
|
||||
console.timeEnd('RECENT_ACTIVITY')
|
||||
|
||||
return {
|
||||
global: globalStats,
|
||||
league: gamemodeStats,
|
||||
|
|
@ -52,6 +59,7 @@ class StatsService {
|
|||
champion: championStats,
|
||||
class: championClassStats,
|
||||
mates,
|
||||
recentActivity,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue