diff --git a/server-v2/app/Models/MatchPlayer.ts b/server-v2/app/Models/MatchPlayer.ts index 2d9f84c..c4ff31d 100644 --- a/server-v2/app/Models/MatchPlayer.ts +++ b/server-v2/app/Models/MatchPlayer.ts @@ -58,10 +58,7 @@ export default class MatchPlayer extends BaseModel { public championId: number @column() - public championRole1: number - - @column() - public championRole2: number + public championRole: number @column() public doubleKills: number diff --git a/server-v2/app/Parsers/MatchParser.ts b/server-v2/app/Parsers/MatchParser.ts index fde3782..0f83700 100644 --- a/server-v2/app/Parsers/MatchParser.ts +++ b/server-v2/app/Parsers/MatchParser.ts @@ -99,8 +99,7 @@ class MatchParser { kp: kp, champ_level: player.champLevel, champion_id: player.championId, - champion_role1: ChampionRoles[champRoles[0]], - champion_role2: ChampionRoles[champRoles[1]], + champion_role: ChampionRoles[champRoles[0]], double_kills: player.doubleKills, triple_kills: player.tripleKills, quadra_kills: player.quadraKills, diff --git a/server-v2/app/Repositories/MatchRepository.ts b/server-v2/app/Repositories/MatchRepository.ts index 8e9c91c..e6d5405 100644 --- a/server-v2/app/Repositories/MatchRepository.ts +++ b/server-v2/app/Repositories/MatchRepository.ts @@ -113,6 +113,27 @@ class MatchRepository { const { rows } = await Database.rawQuery(query, { puuid, limit }) return rows } + + public async championClassStats(puuid: string) { + const query = ` + SELECT + match_players.champion_role 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 match_teams ON match_players.match_id = match_teams.match_id AND match_players.team = match_teams.color + WHERE + summoner_puuid = :puuid + GROUP BY + match_players.champion_role + ORDER BY + count DESC + ` + 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 1b182cc..2e58853 100644 --- a/server-v2/app/Services/StatsService.ts +++ b/server-v2/app/Services/StatsService.ts @@ -1,5 +1,5 @@ import { sortTeamByRole } from 'App/helpers' -import { TeamPosition } from 'App/Parsers/ParsedType' +import { ChampionRoles, TeamPosition } from 'App/Parsers/ParsedType' import MatchRepository from 'App/Repositories/MatchRepository' import BasicMatchSerializer from 'App/Serializers/BasicMatchSerializer' @@ -35,9 +35,12 @@ class StatsService { champ.champion = BasicMatchSerializer.getChampion(champ.id) } console.timeEnd('CHAMPION') - // console.time('CHAMPION-CLASS') - // const championClassStats = await MatchRepository.championClassStats(puuid, season) - // console.timeEnd('CHAMPION-CLASS') + console.time('CHAMPION-CLASS') + const championClassStats = await MatchRepository.championClassStats(puuid) + for (const champ of championClassStats) { + champ.id = ChampionRoles[champ.id] + } + console.timeEnd('CHAMPION-CLASS') // console.time('MATES') // const mates = await MatchRepository.mates(puuid, season) // console.timeEnd('MATES') @@ -46,7 +49,7 @@ class StatsService { global: globalStats, league: gamemodeStats, role: roleStats.sort(sortTeamByRole), - // class: championClassStats, + class: championClassStats, // mates, champion: championStats, } diff --git a/server-v2/database/migrations/1631392766690_match_players.ts b/server-v2/database/migrations/1631392766690_match_players.ts index b5f85e8..bbaff02 100644 --- a/server-v2/database/migrations/1631392766690_match_players.ts +++ b/server-v2/database/migrations/1631392766690_match_players.ts @@ -24,8 +24,7 @@ export default class MatchPlayers extends BaseSchema { table.integer('champ_level').notNullable() table.integer('champion_id').notNullable() - table.integer('champion_role1').notNullable() - table.integer('champion_role2').nullable() + table.integer('champion_role').notNullable() table.integer('double_kills').notNullable() table.integer('triple_kills').notNullable()