refactor: store teamPositions in int in database

This commit is contained in:
Kalane 2021-09-14 16:03:08 +02:00
parent 537a2eb183
commit 134cbfad0b
12 changed files with 40 additions and 19 deletions

View file

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -40,7 +40,7 @@ export function secToTime(seconds) {
* Sort an array of players by role
*/
export function sortTeamByRole(a, b) {
const sortingArr = ['TOP', 'JUNGLE', 'MIDDLE', 'BOTTOM', 'SUPPORT']
const sortingArr = ['TOP', 'JUNGLE', 'MIDDLE', 'BOTTOM', 'UTILITY']
return sortingArr.indexOf(a.role) - sortingArr.indexOf(b.role)
}

View file

@ -32,7 +32,7 @@ export default new Vuex.Store({
'tr': 'tr1',
'ru': 'ru'
},
roles: ['TOP', 'JUNGLE', 'MIDDLE', 'BOTTOM', 'SUPPORT']
roles: ['TOP', 'JUNGLE', 'MIDDLE', 'BOTTOM', 'UTILITY']
},
strict: debug
})

View file

@ -34,7 +34,7 @@ export default class MatchPlayer extends BaseModel {
public team: number
@column()
public teamPosition: string
public teamPosition: number
@column()
public kills: number

View file

@ -30,8 +30,8 @@ export default class MatchTeam extends BaseModel {
public riftHeralds: number
@column()
public bans: number[]
public bans?: number[]
@column()
public banOrders: number[]
public banOrders?: number[]
}

View file

@ -1,9 +1,9 @@
import Database from '@ioc:Adonis/Lucid/Database'
import { MatchDto } from 'App/Services/Jax/src/Endpoints/MatchEndpoint'
import Match from 'App/Models/Match'
import { getSeasonNumber } from 'App/helpers'
import { getSeasonNumber, queuesWithRole } from 'App/helpers'
import CDragonService from 'App/Services/CDragonService'
import { ChampionRoles } from './ParsedType'
import { ChampionRoles, TeamPosition } from './ParsedType'
class MatchParser {
public async parseOneMatch(match: MatchDto) {
// Parse + store in database
@ -34,8 +34,8 @@ class MatchParser {
dragons: team.objectives.dragon.kills,
inhibitors: team.objectives.inhibitor.kills,
riftHeralds: team.objectives.riftHerald.kills,
bans: team.bans.map((ban) => ban.championId),
banOrders: team.bans.map((ban) => ban.pickTurn),
bans: team.bans.length ? team.bans.map((ban) => ban.championId) : undefined,
banOrders: team.bans.length ? team.bans.map((ban) => ban.pickTurn) : undefined,
})
}
@ -65,6 +65,17 @@ class MatchParser {
}
}
// Fix championId bug in older matches
if (player.championId > 1000) {
console.log('CHAMPION ID NOT FOUND: ' + player.championId)
console.log('FROM MATCH ' + match.metadata.matchId)
const championId = Object.keys(CDragonService.champions).find(
(key) => CDragonService.champions[key].name === player.championName
)
player.championId = championId ? Number(championId) : 1
console.log('CHAMPION ID FROM NAME : ' + championId)
}
const originalChampionData = CDragonService.champions[player.championId]
const champRoles = originalChampionData.roles
@ -75,7 +86,10 @@ class MatchParser {
summoner_puuid: player.puuid,
summoner_name: player.summonerName,
team: player.teamId,
team_position: player.teamPosition,
team_position:
player.teamPosition.length && queuesWithRole.includes(match.info.queueId)
? TeamPosition[player.teamPosition]
: TeamPosition.NONE,
kills: player.kills,
deaths: player.deaths,
assists: player.assists,

View file

@ -7,5 +7,11 @@ export enum ChampionRoles {
tank,
}
// TODO
export enum TeamPosition {}
export enum TeamPosition {
NONE,
TOP,
JUNGLE,
MIDDLE,
BOTTOM,
UTILITY,
}

View file

@ -1,6 +1,7 @@
import { getSeasonNumber, sortTeamByRole } from 'App/helpers'
import Match from 'App/Models/Match'
import MatchPlayer from 'App/Models/MatchPlayer'
import { TeamPosition } from 'App/Parsers/ParsedType'
import CDragonService from 'App/Services/CDragonService'
import MatchSerializer from './MatchSerializer'
import {
@ -38,7 +39,7 @@ class BasicMatchSerializer extends MatchSerializer {
puuid: player.summonerPuuid,
champion: this.getChampion(player.championId),
name: player.summonerName,
role: player.teamPosition,
role: TeamPosition[player.teamPosition],
}
}
@ -149,7 +150,7 @@ class BasicMatchSerializer extends MatchSerializer {
perks: this.getPerks(identity),
region: match.region,
result: allyTeam.result,
role: identity.teamPosition.length ? identity.teamPosition : 'NONE',
role: TeamPosition[identity.teamPosition],
season: getSeasonNumber(match.date),
stats: this.getStats(identity),
summonerId: identity.summonerId,

View file

@ -15,7 +15,7 @@ interface Identifiable {
}
export interface CDragonCache<T> {
[id: number]: T
[id: string]: T
}
class CDragonService {

View file

@ -105,6 +105,6 @@ export function getCurrentSeason(): number {
* @param b second player
*/
export function sortTeamByRole(a: SerializedMatchTeamPlayer, b: SerializedMatchTeamPlayer) {
const sortingArr = ['TOP', 'JUNGLE', 'MIDDLE', 'BOTTOM', 'SUPPORT']
const sortingArr = ['TOP', 'JUNGLE', 'MIDDLE', 'BOTTOM', 'UTILITY']
return sortingArr.indexOf(a.role) - sortingArr.indexOf(b.role)
}

View file

@ -14,7 +14,7 @@ export default class MatchPlayers extends BaseSchema {
table.string('summoner_name', 16).notNullable()
table.integer('team').notNullable()
table.string('team_position', 8).notNullable()
table.integer('team_position').notNullable()
table.integer('kills').notNullable()
table.integer('deaths').notNullable()

View file

@ -16,8 +16,8 @@ export default class MatchTeams extends BaseSchema {
table.integer('inhibitors').notNullable()
table.integer('rift_heralds').notNullable()
table.specificType('bans', 'INT[]').notNullable()
table.specificType('ban_orders', 'INT[]').notNullable()
table.specificType('bans', 'INT[]').nullable()
table.specificType('ban_orders', 'INT[]').nullable()
})
}