mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 12:57:28 +00:00
feat: championStats query
This commit is contained in:
parent
92abb9de0f
commit
35af575af1
3 changed files with 36 additions and 7 deletions
|
|
@ -78,7 +78,6 @@ class MatchRepository {
|
||||||
COUNT(case when match_teams.result = 'Fail' then 1 else null end) as losses
|
COUNT(case when match_teams.result = 'Fail' then 1 else null end) as losses
|
||||||
FROM
|
FROM
|
||||||
match_players
|
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
|
INNER JOIN match_teams ON match_players.match_id = match_teams.match_id AND match_players.team = match_teams.color
|
||||||
WHERE
|
WHERE
|
||||||
summoner_puuid = :puuid
|
summoner_puuid = :puuid
|
||||||
|
|
@ -88,6 +87,32 @@ class MatchRepository {
|
||||||
const { rows } = await Database.rawQuery(query, { puuid })
|
const { rows } = await Database.rawQuery(query, { puuid })
|
||||||
return rows
|
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()
|
export default new MatchRepository()
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ class BasicMatchSerializer extends MatchSerializer {
|
||||||
* Get champion specific data
|
* Get champion specific data
|
||||||
* @param id of the champion
|
* @param id of the champion
|
||||||
*/
|
*/
|
||||||
protected getChampion(id: number): SerializedMatchChampion {
|
public getChampion(id: number): SerializedMatchChampion {
|
||||||
const originalChampionData = CDragonService.champions[id]
|
const originalChampionData = CDragonService.champions[id]
|
||||||
const icon =
|
const icon =
|
||||||
CDragonService.BASE_URL +
|
CDragonService.BASE_URL +
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { sortTeamByRole } from 'App/helpers'
|
import { sortTeamByRole } from 'App/helpers'
|
||||||
import { TeamPosition } from 'App/Parsers/ParsedType'
|
import { TeamPosition } from 'App/Parsers/ParsedType'
|
||||||
import MatchRepository from 'App/Repositories/MatchRepository'
|
import MatchRepository from 'App/Repositories/MatchRepository'
|
||||||
|
import BasicMatchSerializer from 'App/Serializers/BasicMatchSerializer'
|
||||||
|
|
||||||
class StatsService {
|
class StatsService {
|
||||||
public async getSummonerStats(puuid: string, season?: number) {
|
public async getSummonerStats(puuid: string, season?: number) {
|
||||||
|
|
@ -27,10 +28,13 @@ class StatsService {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// console.timeEnd('ROLE')
|
console.timeEnd('ROLE')
|
||||||
// console.time('CHAMPION')
|
console.time('CHAMPION')
|
||||||
// const championStats = await MatchRepository.championStats(puuid, 5, season)
|
const championStats = await MatchRepository.championStats(puuid, 5)
|
||||||
// console.timeEnd('CHAMPION')
|
for (const champ of championStats) {
|
||||||
|
champ.champion = BasicMatchSerializer.getChampion(champ.id)
|
||||||
|
}
|
||||||
|
console.timeEnd('CHAMPION')
|
||||||
// console.time('CHAMPION-CLASS')
|
// console.time('CHAMPION-CLASS')
|
||||||
// const championClassStats = await MatchRepository.championClassStats(puuid, season)
|
// const championClassStats = await MatchRepository.championClassStats(puuid, season)
|
||||||
// console.timeEnd('CHAMPION-CLASS')
|
// console.timeEnd('CHAMPION-CLASS')
|
||||||
|
|
@ -44,7 +48,7 @@ class StatsService {
|
||||||
role: roleStats.sort(sortTeamByRole),
|
role: roleStats.sort(sortTeamByRole),
|
||||||
// class: championClassStats,
|
// class: championClassStats,
|
||||||
// mates,
|
// mates,
|
||||||
// champion: championStats,
|
champion: championStats,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue