mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 12:57:28 +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 { getCurrentSeason } from 'App/helpers'
|
||||
import Summoner from 'App/Models/Summoner'
|
||||
import MatchRepository from 'App/Repositories/MatchRepository'
|
||||
import Jax from 'App/Services/Jax'
|
||||
import MatchService from 'App/Services/MatchService'
|
||||
import StatsService from 'App/Services/StatsService'
|
||||
import SummonerService from 'App/Services/SummonerService'
|
||||
import SummonerBasicValidator from 'App/Validators/SummonerBasicValidator'
|
||||
import SummonerOverviewValidator from 'App/Validators/SummonerOverviewValidator'
|
||||
|
|
@ -74,9 +74,7 @@ export default class SummonersController {
|
|||
|
||||
// TODO: STATS
|
||||
console.time('STATS')
|
||||
finalJSON.stats = {
|
||||
global: await MatchRepository.globalStats(puuid),
|
||||
}
|
||||
finalJSON.stats = await StatsService.getSummonerStats(puuid, season)
|
||||
console.timeEnd('STATS')
|
||||
|
||||
console.timeEnd('OVERVIEW_REQUEST')
|
||||
|
|
|
|||
|
|
@ -2,23 +2,51 @@ import Database from '@ioc:Adonis/Lucid/Database'
|
|||
|
||||
class MatchRepository {
|
||||
public async globalStats(puuid: string, season?: number) {
|
||||
// TODO: add wins/losses
|
||||
return Database.from('match_players')
|
||||
.where('summoner_puuid', puuid)
|
||||
.join('matches', 'match_players.match_id', 'matches.id')
|
||||
.sum({
|
||||
assists: 'assists',
|
||||
deaths: 'deaths',
|
||||
kills: 'kills',
|
||||
minions: 'minions',
|
||||
time: 'matches.game_duration',
|
||||
vision: 'vision_score',
|
||||
})
|
||||
.count({
|
||||
count: 'assists',
|
||||
})
|
||||
.avg('kp')
|
||||
.first()
|
||||
const query = `
|
||||
SELECT
|
||||
SUM(assists) as assists,
|
||||
SUM(deaths) as deaths,
|
||||
SUM(kills) as kills,
|
||||
SUM(minions) as minions,
|
||||
SUM(matches.game_duration) as time,
|
||||
SUM(vision_score) as vision,
|
||||
COUNT(match_players.id) as count,
|
||||
AVG(kp) as kp,
|
||||
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 matches.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')
|
||||
// .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