From 49f16c287ba313baf0ad794ded6b1e95808e6262 Mon Sep 17 00:00:00 2001 From: Lazar Date: Mon, 13 Sep 2021 00:17:53 +0200 Subject: [PATCH] feat: parsing matchPlayers + change in model/migration --- server-v2/app/Models/MatchPlayer.ts | 2 +- server-v2/app/Parsers/MatchParser.ts | 55 ++++++++++++++++++- .../migrations/1631392766690_match_players.ts | 2 +- 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/server-v2/app/Models/MatchPlayer.ts b/server-v2/app/Models/MatchPlayer.ts index 74b9c8d..a9a2918 100644 --- a/server-v2/app/Models/MatchPlayer.ts +++ b/server-v2/app/Models/MatchPlayer.ts @@ -16,7 +16,7 @@ export default class MatchPlayer extends BaseModel { public participantId: number @column() - public summonerId: number + public summonerId: string @column() public summonerPuuid: string diff --git a/server-v2/app/Parsers/MatchParser.ts b/server-v2/app/Parsers/MatchParser.ts index 18db9db..04f931f 100644 --- a/server-v2/app/Parsers/MatchParser.ts +++ b/server-v2/app/Parsers/MatchParser.ts @@ -1,5 +1,6 @@ import { MatchDto } from 'App/Services/Jax/src/Endpoints/MatchEndpoint' import Match from 'App/Models/Match' +import MatchPlayer from 'App/Models/MatchPlayer' import { getSeasonNumber } from 'App/helpers' class MatchParser { public async parseOneMatch(match: MatchDto) { @@ -21,7 +22,7 @@ class MatchParser { // - 2x MatchTeam : Red and Blue let result = 'Remake' - for (let team of match.info.teams) { + for (const team of match.info.teams) { if (match.info.gameDuration >= 300) { result = team.win ? 'Win' : 'Fail' } @@ -41,6 +42,58 @@ class MatchParser { // - 10x MatchPlayer // TODO + const matchPlayers = match.info.participants.map( + (p) => ({ + matchId: match.metadata.matchId, + participantId: p.participantId, + summonerId: p.summonerId, + summonerPuuid: p.puuid, + summonerName: p.summonerName, + team: p.teamId, + teamPosition: p.teamPosition, + kills: p.kills, + deaths: p.deaths, + assists: p.assists, + kda: 100, + kp: 100, + champLevel: p.champLevel, + championId: p.championId, + championRole1: 1, + championRole2: 2, + doubleKills: p.doubleKills, + tripleKills: p.tripleKills, + quadraKills: p.quadraKills, + pentaKills: p.pentaKills, + baronKills: p.baronKills, + dragonKills: p.dragonKills, + turretKills: p.turretKills, + visionScore: p.visionScore, + gold: p.goldEarned, + summoner1Id: p.summoner1Id, + summoner2Id: p.summoner2Id, + item0: p.item0, + item1: p.item1, + item2: p.item2, + item3: p.item3, + item4: p.item4, + item5: p.item5, + item6: p.item6, + damageDealtObjectives: p.damageDealtToObjectives, + damageDealtChampions: p.totalDamageDealtToChampions, + damageTaken: p.totalDamageTaken, + heal: p.totalHeal, + minions: p.totalMinionsKilled, + criticalStrike: p.largestCriticalStrike, + killingSpree: p.killingSprees, + timeSpentLiving: p.longestTimeSpentLiving, + perksPrimaryStyle: 100, + perksSecondaryStyle: 100, + perksSelected: [1, 2, 3], + }) + ) + + parsedMatch.related('players').createMany(matchPlayers) + return parsedMatch } diff --git a/server-v2/database/migrations/1631392766690_match_players.ts b/server-v2/database/migrations/1631392766690_match_players.ts index 360ebd2..cb9a30e 100644 --- a/server-v2/database/migrations/1631392766690_match_players.ts +++ b/server-v2/database/migrations/1631392766690_match_players.ts @@ -9,7 +9,7 @@ export default class MatchPlayers extends BaseSchema { table.string('match_id', 15).notNullable() table.integer('participant_id').notNullable() - table.integer('summoner_id').notNullable() + table.string('summoner_id', 78).notNullable() // check length table.string('summoner_puuid', 78).notNullable() table.string('summoner_name', 16).notNullable()