diff --git a/server-new/app/Models/DetailedMatch.ts b/server-new/app/Models/DetailedMatch.ts index f4e9e3b..f591061 100644 --- a/server-new/app/Models/DetailedMatch.ts +++ b/server-new/app/Models/DetailedMatch.ts @@ -29,10 +29,10 @@ interface Team { export interface Ban { championId: number, pickTurn: number, - champion: Champion + champion: Champion } -interface TeamStats { +export interface TeamStats { kills: number, deaths: number, assists: number, diff --git a/server-new/app/Services/RoleIdentiticationService.ts b/server-new/app/Services/RoleIdentiticationService.ts index f2a2ae2..c350db6 100644 --- a/server-new/app/Services/RoleIdentiticationService.ts +++ b/server-new/app/Services/RoleIdentiticationService.ts @@ -1,20 +1,30 @@ import Redis from '@ioc:Adonis/Addons/Redis' import got from 'got/dist/source' +export interface ChampionsPlayRate { + [champion: string]: { + TOP: number, + JUNGLE: number, + MIDDLE: number, + BOTTOM: number, + UTILITY: number, + } +} + export interface FinalRoleComposition { - 'TOP'?: number, - 'JUNGLE'?: number, - 'MIDDLE'?: number, - 'BOTTOM'?: number, - 'SUPPORT'?: number, + TOP?: number, + JUNGLE?: number, + MIDDLE?: number, + BOTTOM?: number, + SUPPORT?: number, } export interface RoleComposition { - 'TOP'?: number, - 'JUNGLE'?: number, - 'MIDDLE'?: number, - 'BOTTOM'?: number, - 'UTILITY'?: number, + TOP?: number, + JUNGLE?: number, + MIDDLE?: number, + BOTTOM?: number, + UTILITY?: number, } export interface ChampionComposition { @@ -153,7 +163,7 @@ class RoleIdentificationService { /** * Get the CDN data of the champion playrates by role */ - public async pullData () { + public async pullData (): Promise { const url = 'http://cdn.merakianalytics.com/riot/lol/resources/latest/en-US/championrates.json' // Check if cached diff --git a/server-new/app/Transformers/BasicMatchTransformer.ts b/server-new/app/Transformers/BasicMatchTransformer.ts index 59d07b0..b2a376d 100644 --- a/server-new/app/Transformers/BasicMatchTransformer.ts +++ b/server-new/app/Transformers/BasicMatchTransformer.ts @@ -27,8 +27,8 @@ class BasicMatchTransformer extends MatchTransformer { const playerData = super.getPlayerData(match, player, false) // Teams data - const allyTeam:ParticipantBasic[] = [] - const enemyTeam:ParticipantBasic[] = [] + const allyTeam: ParticipantBasic[] = [] + const enemyTeam: ParticipantBasic[] = [] for (let summoner of match.participantIdentities) { const allData = match.participants[summoner.participantId - 1] const playerInfos = { @@ -68,7 +68,7 @@ class BasicMatchTransformer extends MatchTransformer { public async transform (matches: MatchDto[], { puuid, accountId }: { puuid: string, accountId: string }) { await super.getContext() - const finalMatches:MatchModel[] = [] + const finalMatches: MatchModel[] = [] matches.forEach((match, index) => { finalMatches[index] = this.transformOneMatch(match, puuid, accountId) }) diff --git a/server-new/app/Transformers/DetailedMatchTransformer.ts b/server-new/app/Transformers/DetailedMatchTransformer.ts index cbd085a..ad73be0 100644 --- a/server-new/app/Transformers/DetailedMatchTransformer.ts +++ b/server-new/app/Transformers/DetailedMatchTransformer.ts @@ -1,5 +1,4 @@ import { Ban, DetailedMatchModel } from 'App/Models/DetailedMatch' -import { Champion } from 'App/Models/Match' import { MatchDto, TeamStatsDto } from 'App/Services/Jax/src/Endpoints/MatchEndpoint' import MatchTransformer from './MatchTransformer' @@ -37,9 +36,7 @@ class DetailedMatchTransformer extends MatchTransformer { const bans: Ban[] = [] if (team.bans) { for (const ban of team.bans) { - const champion: Champion = (ban.championId === -1) - ? { id: null, name: null } - : super.getChampion(ban.championId) + const champion = (ban.championId === -1) ? { id: null, name: null } : super.getChampion(ban.championId) bans.push({ ...ban, diff --git a/server-new/app/Transformers/MatchTransformer.ts b/server-new/app/Transformers/MatchTransformer.ts index f70b054..ed1bd74 100644 --- a/server-new/app/Transformers/MatchTransformer.ts +++ b/server-new/app/Transformers/MatchTransformer.ts @@ -2,8 +2,9 @@ import { getSeasonNumber, queuesWithRole, sortTeamByRole, supportItems } from 'A import Jax from 'App/Services/Jax' import { MatchDto, ParticipantDto, ParticipantTimelineDto } from 'App/Services/Jax/src/Endpoints/MatchEndpoint' import { Champion, Item, ParticipantBasic, ParticipantDetails, PercentStats, Stats, SummonerSpell } from 'App/Models/Match' -import RoleIdentificationService from 'App/Services/RoleIdentiticationService' +import RoleIdentificationService, { ChampionsPlayRate } from 'App/Services/RoleIdentiticationService' import { ChampionDTO, ItemDTO, PerkDTO, PerkStyleDTO, SummonerSpellDTO } from 'App/Services/Jax/src/Endpoints/CDragonEndpoint' +import { TeamStats } from 'App/Models/DetailedMatch' export interface PlayerRole { champion: number, @@ -17,7 +18,7 @@ export default abstract class MatchTransformer { protected perks: PerkDTO[] protected perkstyles: PerkStyleDTO[] protected summonerSpells: SummonerSpellDTO[] - protected championRoles: any + protected championRoles: ChampionsPlayRate protected sortTeamByRole: (a: ParticipantBasic | ParticipantDetails, b: ParticipantBasic | ParticipantDetails) => number /** * Get global Context with CDragon Data @@ -35,7 +36,7 @@ export default abstract class MatchTransformer { this.perks = perks this.perkstyles = perkstyles.styles this.summonerSpells = summonerSpells - this.championRoles = championRoles + this.championRoles = championRoles as ChampionsPlayRate this.sortTeamByRole = sortTeamByRole } @@ -78,7 +79,7 @@ export default abstract class MatchTransformer { * @param detailed : detailed or not stats * @param teamStats : if detailed, the teamStats argument is mandatory */ - public getPlayerData (match: MatchDto, player: ParticipantDto, detailed: boolean, teamStats: any = {}) { + public getPlayerData (match: MatchDto, player: ParticipantDto, detailed: boolean, teamStats?: TeamStats) { const identity = match.participantIdentities.find(p => p.participantId === player.participantId) const name = identity!.player.summonerName const champion = this.getChampion(player.championId) @@ -112,6 +113,7 @@ export default abstract class MatchTransformer { // Percent stats / Per minute stats : only for detailed match let percentStats: PercentStats if (detailed) { + teamStats = teamStats! percentStats = { minions: +(stats.minions / (match.gameDuration / 60)).toFixed(2), vision: +(stats.vision / (match.gameDuration / 60)).toFixed(2),