mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 12:57:28 +00:00
feat: gamemodeStats query
This commit is contained in:
parent
3cb2366c00
commit
23b407e5c4
2 changed files with 29 additions and 9 deletions
|
|
@ -1,9 +1,9 @@
|
|||
import Database from '@ioc:Adonis/Lucid/Database'
|
||||
|
||||
class MatchRepository {
|
||||
public async globalStats(puuid: string, season?: number) {
|
||||
public async globalStats(puuid: string) {
|
||||
const query = `
|
||||
SELECT
|
||||
SELECT
|
||||
SUM(assists) as assists,
|
||||
SUM(deaths) as deaths,
|
||||
SUM(kills) as kills,
|
||||
|
|
@ -17,12 +17,12 @@ class MatchRepository {
|
|||
FROM
|
||||
match_players
|
||||
INNER JOIN matches ON matches.id = match_players.match_id
|
||||
INNER JOIN match_teams ON matches.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
|
||||
summoner_puuid = :puuid
|
||||
LIMIT
|
||||
1
|
||||
`
|
||||
`
|
||||
const { rows } = await Database.rawQuery(query, { puuid })
|
||||
return rows[0]
|
||||
// return Database.from('match_players')
|
||||
|
|
@ -48,6 +48,26 @@ class MatchRepository {
|
|||
// .avg('kp')
|
||||
// .first()
|
||||
}
|
||||
|
||||
public async gamemodeStats(puuid: string) {
|
||||
const query = `
|
||||
SELECT
|
||||
matches.gamemode 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 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
|
||||
GROUP BY
|
||||
matches.gamemode
|
||||
`
|
||||
const { rows } = await Database.rawQuery(query, { puuid })
|
||||
return rows
|
||||
}
|
||||
}
|
||||
|
||||
export default new MatchRepository()
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@ import MatchRepository from 'App/Repositories/MatchRepository'
|
|||
class StatsService {
|
||||
public async getSummonerStats(puuid: string, season?: number) {
|
||||
console.time('GLOBAL')
|
||||
const globalStats = await MatchRepository.globalStats(puuid, season)
|
||||
const globalStats = await MatchRepository.globalStats(puuid)
|
||||
console.timeEnd('GLOBAL')
|
||||
// console.time('GAMEMODE')
|
||||
// const gamemodeStats = await MatchRepository.gamemodeStats(puuid, season)
|
||||
// console.timeEnd('GAMEMODE')
|
||||
console.time('GAMEMODE')
|
||||
const gamemodeStats = await MatchRepository.gamemodeStats(puuid)
|
||||
console.timeEnd('GAMEMODE')
|
||||
// console.time('ROLE')
|
||||
// const roleStats = await MatchRepository.roleStats(puuid, season)
|
||||
// // Check if all roles are in the array
|
||||
|
|
@ -36,7 +36,7 @@ class StatsService {
|
|||
|
||||
return {
|
||||
global: globalStats,
|
||||
// league: gamemodeStats,
|
||||
league: gamemodeStats,
|
||||
// role: roleStats.sort(sortTeamByRole),
|
||||
// class: championClassStats,
|
||||
// mates,
|
||||
|
|
|
|||
Loading…
Reference in a new issue