mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 12:57:28 +00:00
feat: parsing of match + its two teams and change in models/migration
This commit is contained in:
parent
2b73d29f6a
commit
45750d64eb
4 changed files with 50 additions and 11 deletions
|
|
@ -12,10 +12,10 @@ export default class MatchTeam extends BaseModel {
|
||||||
public match: BelongsTo<typeof Match>
|
public match: BelongsTo<typeof Match>
|
||||||
|
|
||||||
@column()
|
@column()
|
||||||
public color: string
|
public color: number
|
||||||
|
|
||||||
@column()
|
@column()
|
||||||
public result: number
|
public result: string
|
||||||
|
|
||||||
@column()
|
@column()
|
||||||
public barons: number
|
public barons: number
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,56 @@
|
||||||
import { MatchDto } from 'App/Services/Jax/src/Endpoints/MatchEndpoint'
|
import { MatchDto } from 'App/Services/Jax/src/Endpoints/MatchEndpoint'
|
||||||
|
import Match from 'App/Models/Match'
|
||||||
|
import { getSeasonNumber } from 'App/helpers'
|
||||||
class MatchParser {
|
class MatchParser {
|
||||||
public async parseOneMatch(match: MatchDto) {
|
public async parseOneMatch(match: MatchDto) {
|
||||||
// TODO: parse + store in database
|
// TODO: parse + store in database
|
||||||
// From the MatchDto, we need these Models in the DB:
|
// From the MatchDto, we need these Models in the DB:
|
||||||
|
|
||||||
// - 1x Match
|
// - 1x Match
|
||||||
// - 10x MatchPlayer
|
const parsedMatch = await Match.create({
|
||||||
// - 2x MatchTeam
|
id: match.metadata.matchId,
|
||||||
|
gameId: match.info.gameId,
|
||||||
|
map: match.info.mapId,
|
||||||
|
gamemode: match.info.queueId,
|
||||||
|
date: match.info.gameCreation,
|
||||||
|
region: match.info.platformId.toLowerCase(),
|
||||||
|
result: 0, // TODO
|
||||||
|
season: getSeasonNumber(match.info.gameCreation),
|
||||||
|
gameDuration: match.info.gameDuration,
|
||||||
|
})
|
||||||
|
|
||||||
|
// - 2x MatchTeam : Red and Blue
|
||||||
|
let result = 'Remake'
|
||||||
|
for (let team of match.info.teams) {
|
||||||
|
if (match.info.gameDuration >= 300) {
|
||||||
|
result = team.win ? 'Win' : 'Fail'
|
||||||
|
}
|
||||||
|
const teamColor = team.teamId === 100 ? 'blueTeam' : 'redTeam'
|
||||||
|
parsedMatch.related(teamColor).create({
|
||||||
|
matchId: match.metadata.matchId,
|
||||||
|
color: team.teamId,
|
||||||
|
result: result,
|
||||||
|
barons: team.objectives.baron.kills,
|
||||||
|
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),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// - 10x MatchPlayer // TODO
|
||||||
|
|
||||||
|
return parsedMatch
|
||||||
}
|
}
|
||||||
|
|
||||||
public async parse(matches: MatchDto[]) {
|
public async parse(matches: MatchDto[]) {
|
||||||
// TODO
|
// Loop on all matches and call .parseOneMatch on it
|
||||||
// Loop on all matches and call .parse on it
|
const parsedMatches: Match[] = []
|
||||||
|
for (const match of matches) {
|
||||||
|
parsedMatches.push(await this.parseOneMatch(match))
|
||||||
|
}
|
||||||
|
return parsedMatches
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,10 @@ export default class Matches extends BaseSchema {
|
||||||
public async up() {
|
public async up() {
|
||||||
this.schema.createTable(this.tableName, (table) => {
|
this.schema.createTable(this.tableName, (table) => {
|
||||||
table.string('id', 15).primary()
|
table.string('id', 15).primary()
|
||||||
table.integer('game_id').notNullable()
|
table.bigInteger('game_id').notNullable()
|
||||||
table.integer('map').notNullable()
|
table.integer('map').notNullable()
|
||||||
table.integer('gamemode').notNullable()
|
table.integer('gamemode').notNullable()
|
||||||
table.integer('date').notNullable()
|
table.bigInteger('date').notNullable()
|
||||||
table.string('region', 4).notNullable()
|
table.string('region', 4).notNullable()
|
||||||
table.integer('result').notNullable()
|
table.integer('result').notNullable()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ export default class MatchTeams extends BaseSchema {
|
||||||
table.increments('id')
|
table.increments('id')
|
||||||
table.string('match_id', 15)
|
table.string('match_id', 15)
|
||||||
|
|
||||||
table.string('color', 4).notNullable()
|
table.integer('color').notNullable() // 100 ou 200
|
||||||
table.integer('result').notNullable()
|
table.string('result', 6) // Win - Remake - Fail
|
||||||
|
|
||||||
table.integer('barons').notNullable()
|
table.integer('barons').notNullable()
|
||||||
table.integer('dragons').notNullable()
|
table.integer('dragons').notNullable()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue