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