feat: championClassStats query

This commit is contained in:
Kalane 2021-09-15 16:34:44 +02:00
parent 35af575af1
commit 72872b9040
5 changed files with 32 additions and 13 deletions

View file

@ -58,10 +58,7 @@ export default class MatchPlayer extends BaseModel {
public championId: number public championId: number
@column() @column()
public championRole1: number public championRole: number
@column()
public championRole2: number
@column() @column()
public doubleKills: number public doubleKills: number

View file

@ -99,8 +99,7 @@ class MatchParser {
kp: kp, kp: kp,
champ_level: player.champLevel, champ_level: player.champLevel,
champion_id: player.championId, champion_id: player.championId,
champion_role1: ChampionRoles[champRoles[0]], champion_role: ChampionRoles[champRoles[0]],
champion_role2: ChampionRoles[champRoles[1]],
double_kills: player.doubleKills, double_kills: player.doubleKills,
triple_kills: player.tripleKills, triple_kills: player.tripleKills,
quadra_kills: player.quadraKills, quadra_kills: player.quadraKills,

View file

@ -113,6 +113,27 @@ class MatchRepository {
const { rows } = await Database.rawQuery(query, { puuid, limit }) const { rows } = await Database.rawQuery(query, { puuid, limit })
return rows return rows
} }
public async championClassStats(puuid: string) {
const query = `
SELECT
match_players.champion_role as id,
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_role
ORDER BY
count DESC
`
const { rows } = await Database.rawQuery(query, { puuid })
return rows
}
} }
export default new MatchRepository() export default new MatchRepository()

View file

@ -1,5 +1,5 @@
import { sortTeamByRole } from 'App/helpers' import { sortTeamByRole } from 'App/helpers'
import { TeamPosition } from 'App/Parsers/ParsedType' import { ChampionRoles, TeamPosition } from 'App/Parsers/ParsedType'
import MatchRepository from 'App/Repositories/MatchRepository' import MatchRepository from 'App/Repositories/MatchRepository'
import BasicMatchSerializer from 'App/Serializers/BasicMatchSerializer' import BasicMatchSerializer from 'App/Serializers/BasicMatchSerializer'
@ -35,9 +35,12 @@ class StatsService {
champ.champion = BasicMatchSerializer.getChampion(champ.id) champ.champion = BasicMatchSerializer.getChampion(champ.id)
} }
console.timeEnd('CHAMPION') console.timeEnd('CHAMPION')
// console.time('CHAMPION-CLASS') console.time('CHAMPION-CLASS')
// const championClassStats = await MatchRepository.championClassStats(puuid, season) const championClassStats = await MatchRepository.championClassStats(puuid)
// console.timeEnd('CHAMPION-CLASS') for (const champ of championClassStats) {
champ.id = ChampionRoles[champ.id]
}
console.timeEnd('CHAMPION-CLASS')
// console.time('MATES') // console.time('MATES')
// const mates = await MatchRepository.mates(puuid, season) // const mates = await MatchRepository.mates(puuid, season)
// console.timeEnd('MATES') // console.timeEnd('MATES')
@ -46,7 +49,7 @@ class StatsService {
global: globalStats, global: globalStats,
league: gamemodeStats, league: gamemodeStats,
role: roleStats.sort(sortTeamByRole), role: roleStats.sort(sortTeamByRole),
// class: championClassStats, class: championClassStats,
// mates, // mates,
champion: championStats, champion: championStats,
} }

View file

@ -24,8 +24,7 @@ export default class MatchPlayers extends BaseSchema {
table.integer('champ_level').notNullable() table.integer('champ_level').notNullable()
table.integer('champion_id').notNullable() table.integer('champion_id').notNullable()
table.integer('champion_role1').notNullable() table.integer('champion_role').notNullable()
table.integer('champion_role2').nullable()
table.integer('double_kills').notNullable() table.integer('double_kills').notNullable()
table.integer('triple_kills').notNullable() table.integer('triple_kills').notNullable()