mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 21:07:27 +00:00
feat: globalStats query
This commit is contained in:
parent
d9d470efdd
commit
3cb2366c00
3 changed files with 95 additions and 21 deletions
|
|
@ -1,9 +1,9 @@
|
||||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||||
import { getCurrentSeason } from 'App/helpers'
|
import { getCurrentSeason } from 'App/helpers'
|
||||||
import Summoner from 'App/Models/Summoner'
|
import Summoner from 'App/Models/Summoner'
|
||||||
import MatchRepository from 'App/Repositories/MatchRepository'
|
|
||||||
import Jax from 'App/Services/Jax'
|
import Jax from 'App/Services/Jax'
|
||||||
import MatchService from 'App/Services/MatchService'
|
import MatchService from 'App/Services/MatchService'
|
||||||
|
import StatsService from 'App/Services/StatsService'
|
||||||
import SummonerService from 'App/Services/SummonerService'
|
import SummonerService from 'App/Services/SummonerService'
|
||||||
import SummonerBasicValidator from 'App/Validators/SummonerBasicValidator'
|
import SummonerBasicValidator from 'App/Validators/SummonerBasicValidator'
|
||||||
import SummonerOverviewValidator from 'App/Validators/SummonerOverviewValidator'
|
import SummonerOverviewValidator from 'App/Validators/SummonerOverviewValidator'
|
||||||
|
|
@ -74,9 +74,7 @@ export default class SummonersController {
|
||||||
|
|
||||||
// TODO: STATS
|
// TODO: STATS
|
||||||
console.time('STATS')
|
console.time('STATS')
|
||||||
finalJSON.stats = {
|
finalJSON.stats = await StatsService.getSummonerStats(puuid, season)
|
||||||
global: await MatchRepository.globalStats(puuid),
|
|
||||||
}
|
|
||||||
console.timeEnd('STATS')
|
console.timeEnd('STATS')
|
||||||
|
|
||||||
console.timeEnd('OVERVIEW_REQUEST')
|
console.timeEnd('OVERVIEW_REQUEST')
|
||||||
|
|
|
||||||
|
|
@ -2,23 +2,51 @@ import Database from '@ioc:Adonis/Lucid/Database'
|
||||||
|
|
||||||
class MatchRepository {
|
class MatchRepository {
|
||||||
public async globalStats(puuid: string, season?: number) {
|
public async globalStats(puuid: string, season?: number) {
|
||||||
// TODO: add wins/losses
|
const query = `
|
||||||
return Database.from('match_players')
|
SELECT
|
||||||
.where('summoner_puuid', puuid)
|
SUM(assists) as assists,
|
||||||
.join('matches', 'match_players.match_id', 'matches.id')
|
SUM(deaths) as deaths,
|
||||||
.sum({
|
SUM(kills) as kills,
|
||||||
assists: 'assists',
|
SUM(minions) as minions,
|
||||||
deaths: 'deaths',
|
SUM(matches.game_duration) as time,
|
||||||
kills: 'kills',
|
SUM(vision_score) as vision,
|
||||||
minions: 'minions',
|
COUNT(match_players.id) as count,
|
||||||
time: 'matches.game_duration',
|
AVG(kp) as kp,
|
||||||
vision: 'vision_score',
|
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
|
||||||
.count({
|
FROM
|
||||||
count: 'assists',
|
match_players
|
||||||
})
|
INNER JOIN matches ON matches.id = match_players.match_id
|
||||||
.avg('kp')
|
INNER JOIN match_teams ON matches.id = match_teams.match_id AND match_players.team = match_teams.color
|
||||||
.first()
|
WHERE
|
||||||
|
summoner_puuid = :puuid
|
||||||
|
LIMIT
|
||||||
|
1
|
||||||
|
`
|
||||||
|
const { rows } = await Database.rawQuery(query, { puuid })
|
||||||
|
return rows[0]
|
||||||
|
// return Database.from('match_players')
|
||||||
|
// .where('summoner_puuid', puuid)
|
||||||
|
// .join('matches', 'match_players.match_id', 'matches.id')
|
||||||
|
// .join('match_teams', (query) => {
|
||||||
|
// query
|
||||||
|
// .on('match_teams.match_id', '=', 'match_players.match_id')
|
||||||
|
// .andOn('match_teams.color', '=', 'match_players.team')
|
||||||
|
// })
|
||||||
|
// .sum({
|
||||||
|
// assists: 'assists',
|
||||||
|
// deaths: 'deaths',
|
||||||
|
// kills: 'kills',
|
||||||
|
// minions: 'minions',
|
||||||
|
// time: 'matches.game_duration',
|
||||||
|
// vision: 'vision_score',
|
||||||
|
// result: 'match_teams.result',
|
||||||
|
// })
|
||||||
|
// .count({
|
||||||
|
// count: 'assists',
|
||||||
|
// })
|
||||||
|
// .avg('kp')
|
||||||
|
// .first()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
48
server-v2/app/Services/StatsService.ts
Normal file
48
server-v2/app/Services/StatsService.ts
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
import MatchRepository from 'App/Repositories/MatchRepository'
|
||||||
|
// import { sortTeamByRole } from 'App/helpers'
|
||||||
|
|
||||||
|
class StatsService {
|
||||||
|
public async getSummonerStats(puuid: string, season?: number) {
|
||||||
|
console.time('GLOBAL')
|
||||||
|
const globalStats = await MatchRepository.globalStats(puuid, season)
|
||||||
|
console.timeEnd('GLOBAL')
|
||||||
|
// console.time('GAMEMODE')
|
||||||
|
// const gamemodeStats = await MatchRepository.gamemodeStats(puuid, season)
|
||||||
|
// console.timeEnd('GAMEMODE')
|
||||||
|
// console.time('ROLE')
|
||||||
|
// const roleStats = await MatchRepository.roleStats(puuid, season)
|
||||||
|
// // Check if all roles are in the array
|
||||||
|
// const roles = ['TOP', 'JUNGLE', 'MIDDLE', 'BOTTOM', 'SUPPORT']
|
||||||
|
// for (const role of roles) {
|
||||||
|
// if (!roleStats.find((r) => r.role === role)) {
|
||||||
|
// roleStats.push({
|
||||||
|
// count: 0,
|
||||||
|
// losses: 0,
|
||||||
|
// role,
|
||||||
|
// wins: 0,
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// console.timeEnd('ROLE')
|
||||||
|
// console.time('CHAMPION')
|
||||||
|
// const championStats = await MatchRepository.championStats(puuid, 5, season)
|
||||||
|
// console.timeEnd('CHAMPION')
|
||||||
|
// console.time('CHAMPION-CLASS')
|
||||||
|
// const championClassStats = await MatchRepository.championClassStats(puuid, season)
|
||||||
|
// console.timeEnd('CHAMPION-CLASS')
|
||||||
|
// console.time('MATES')
|
||||||
|
// const mates = await MatchRepository.mates(puuid, season)
|
||||||
|
// console.timeEnd('MATES')
|
||||||
|
|
||||||
|
return {
|
||||||
|
global: globalStats,
|
||||||
|
// league: gamemodeStats,
|
||||||
|
// role: roleStats.sort(sortTeamByRole),
|
||||||
|
// class: championClassStats,
|
||||||
|
// mates,
|
||||||
|
// champion: championStats,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new StatsService()
|
||||||
Loading…
Reference in a new issue