mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 12:57:28 +00:00
feat: very beggining of overview-stats
This commit is contained in:
parent
68e3cb821b
commit
d9d470efdd
2 changed files with 31 additions and 3 deletions
|
|
@ -1,6 +1,7 @@
|
|||
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 SummonerService from 'App/Services/SummonerService'
|
||||
|
|
@ -72,9 +73,11 @@ export default class SummonersController {
|
|||
finalJSON.matchesDetails = await MatchService.getMatches(region, matchIds, puuid)
|
||||
|
||||
// TODO: STATS
|
||||
// console.time('STATS')
|
||||
// finalJSON.stats = 'todo'
|
||||
// console.timeEnd('STATS')
|
||||
console.time('STATS')
|
||||
finalJSON.stats = {
|
||||
global: await MatchRepository.globalStats(puuid),
|
||||
}
|
||||
console.timeEnd('STATS')
|
||||
|
||||
console.timeEnd('OVERVIEW_REQUEST')
|
||||
return response.json(finalJSON)
|
||||
|
|
|
|||
25
server-v2/app/Repositories/MatchRepository.ts
Normal file
25
server-v2/app/Repositories/MatchRepository.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
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()
|
||||
}
|
||||
}
|
||||
|
||||
export default new MatchRepository()
|
||||
Loading…
Reference in a new issue