diff --git a/server-v2/app/Repositories/MatchRepository.ts b/server-v2/app/Repositories/MatchRepository.ts index c4bf141..c003a23 100644 --- a/server-v2/app/Repositories/MatchRepository.ts +++ b/server-v2/app/Repositories/MatchRepository.ts @@ -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() diff --git a/server-v2/app/Services/StatsService.ts b/server-v2/app/Services/StatsService.ts index 93eb3c5..fcd1c84 100644 --- a/server-v2/app/Services/StatsService.ts +++ b/server-v2/app/Services/StatsService.ts @@ -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,