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,7 +1,7 @@
|
||||||
import Database from '@ioc:Adonis/Lucid/Database'
|
import Database from '@ioc:Adonis/Lucid/Database'
|
||||||
|
|
||||||
class MatchRepository {
|
class MatchRepository {
|
||||||
public async globalStats(puuid: string, season?: number) {
|
public async globalStats(puuid: string) {
|
||||||
const query = `
|
const query = `
|
||||||
SELECT
|
SELECT
|
||||||
SUM(assists) as assists,
|
SUM(assists) as assists,
|
||||||
|
|
@ -17,7 +17,7 @@ class MatchRepository {
|
||||||
FROM
|
FROM
|
||||||
match_players
|
match_players
|
||||||
INNER JOIN matches ON matches.id = match_players.match_id
|
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
|
WHERE
|
||||||
summoner_puuid = :puuid
|
summoner_puuid = :puuid
|
||||||
LIMIT
|
LIMIT
|
||||||
|
|
@ -48,6 +48,26 @@ class MatchRepository {
|
||||||
// .avg('kp')
|
// .avg('kp')
|
||||||
// .first()
|
// .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()
|
export default new MatchRepository()
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,11 @@ import MatchRepository from 'App/Repositories/MatchRepository'
|
||||||
class StatsService {
|
class StatsService {
|
||||||
public async getSummonerStats(puuid: string, season?: number) {
|
public async getSummonerStats(puuid: string, season?: number) {
|
||||||
console.time('GLOBAL')
|
console.time('GLOBAL')
|
||||||
const globalStats = await MatchRepository.globalStats(puuid, season)
|
const globalStats = await MatchRepository.globalStats(puuid)
|
||||||
console.timeEnd('GLOBAL')
|
console.timeEnd('GLOBAL')
|
||||||
// console.time('GAMEMODE')
|
console.time('GAMEMODE')
|
||||||
// const gamemodeStats = await MatchRepository.gamemodeStats(puuid, season)
|
const gamemodeStats = await MatchRepository.gamemodeStats(puuid)
|
||||||
// console.timeEnd('GAMEMODE')
|
console.timeEnd('GAMEMODE')
|
||||||
// console.time('ROLE')
|
// console.time('ROLE')
|
||||||
// const roleStats = await MatchRepository.roleStats(puuid, season)
|
// const roleStats = await MatchRepository.roleStats(puuid, season)
|
||||||
// // Check if all roles are in the array
|
// // Check if all roles are in the array
|
||||||
|
|
@ -36,7 +36,7 @@ class StatsService {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
global: globalStats,
|
global: globalStats,
|
||||||
// league: gamemodeStats,
|
league: gamemodeStats,
|
||||||
// role: roleStats.sort(sortTeamByRole),
|
// role: roleStats.sort(sortTeamByRole),
|
||||||
// class: championClassStats,
|
// class: championClassStats,
|
||||||
// mates,
|
// mates,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue