mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 12:57:28 +00:00
refactor(role-identification): add types to ChampionPlayRate
This commit is contained in:
parent
8769d9b5bc
commit
02360b4e92
5 changed files with 33 additions and 24 deletions
|
|
@ -29,10 +29,10 @@ interface Team {
|
|||
export interface Ban {
|
||||
championId: number,
|
||||
pickTurn: number,
|
||||
champion: Champion<null, null>
|
||||
champion: Champion<null | number, null | string>
|
||||
}
|
||||
|
||||
interface TeamStats {
|
||||
export interface TeamStats {
|
||||
kills: number,
|
||||
deaths: number,
|
||||
assists: number,
|
||||
|
|
|
|||
|
|
@ -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<ChampionsPlayRate> {
|
||||
const url = 'http://cdn.merakianalytics.com/riot/lol/resources/latest/en-US/championrates.json'
|
||||
|
||||
// Check if cached
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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<null, null> = (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,
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
Loading…
Reference in a new issue