feat: championStats query

This commit is contained in:
Kalane 2021-09-15 16:22:19 +02:00
parent 92abb9de0f
commit 35af575af1
3 changed files with 36 additions and 7 deletions

View file

@ -78,7 +78,6 @@ class MatchRepository {
COUNT(case when match_teams.result = 'Fail' then 1 else null end) as losses
FROM
match_players
INNER JOIN matches ON matches.id = match_players.match_id
INNER JOIN match_teams ON match_players.match_id = match_teams.match_id AND match_players.team = match_teams.color
WHERE
summoner_puuid = :puuid
@ -88,6 +87,32 @@ class MatchRepository {
const { rows } = await Database.rawQuery(query, { puuid })
return rows
}
public async championStats(puuid: string, limit: number) {
const query = `
SELECT
match_players.champion_id as id,
SUM(assists) as assists,
SUM(deaths) as deaths,
SUM(kills) as kills,
COUNT(match_players.id) as count,
COUNT(case when match_teams.result = 'Win' then 1 else null end) as wins,
COUNT(case when match_teams.result = 'Fail' then 1 else null end) as losses
FROM
match_players
INNER JOIN match_teams ON match_players.match_id = match_teams.match_id AND match_players.team = match_teams.color
WHERE
summoner_puuid = :puuid
GROUP BY
match_players.champion_id
ORDER BY
count DESC
LIMIT
:limit
`
const { rows } = await Database.rawQuery(query, { puuid, limit })
return rows
}
}
export default new MatchRepository()

View file

@ -19,7 +19,7 @@ class BasicMatchSerializer extends MatchSerializer {
* Get champion specific data
* @param id of the champion
*/
protected getChampion(id: number): SerializedMatchChampion {
public getChampion(id: number): SerializedMatchChampion {
const originalChampionData = CDragonService.champions[id]
const icon =
CDragonService.BASE_URL +

View file

@ -1,6 +1,7 @@
import { sortTeamByRole } from 'App/helpers'
import { TeamPosition } from 'App/Parsers/ParsedType'
import MatchRepository from 'App/Repositories/MatchRepository'
import BasicMatchSerializer from 'App/Serializers/BasicMatchSerializer'
class StatsService {
public async getSummonerStats(puuid: string, season?: number) {
@ -27,10 +28,13 @@ class StatsService {
})
}
}
// console.timeEnd('ROLE')
// console.time('CHAMPION')
// const championStats = await MatchRepository.championStats(puuid, 5, season)
// console.timeEnd('CHAMPION')
console.timeEnd('ROLE')
console.time('CHAMPION')
const championStats = await MatchRepository.championStats(puuid, 5)
for (const champ of championStats) {
champ.champion = BasicMatchSerializer.getChampion(champ.id)
}
console.timeEnd('CHAMPION')
// console.time('CHAMPION-CLASS')
// const championClassStats = await MatchRepository.championClassStats(puuid, season)
// console.timeEnd('CHAMPION-CLASS')
@ -44,7 +48,7 @@ class StatsService {
role: roleStats.sort(sortTeamByRole),
// class: championClassStats,
// mates,
// champion: championStats,
champion: championStats,
}
}
}