diff --git a/client/src/views/Summoner.vue b/client/src/views/Summoner.vue index 3698b09..415d4a8 100644 --- a/client/src/views/Summoner.vue +++ b/client/src/views/Summoner.vue @@ -10,9 +10,10 @@ class="z-40 sidebar" container-selector=".vue-sticky-container" > - + +
@@ -56,9 +57,9 @@ import LiveMatch from '@/components/Match/LiveMatch.vue' import LoadingButton from '@/components/Form/LoadingButton.vue' import Match from '@/components/Match/Match.vue' import OverviewLoader from '@/components/Summoner/Overview/OverviewLoader.vue' -import SummonerChampions from '@/components/Summoner/Overview/SummonerChampions.vue' -import SummonerMates from '@/components/Summoner/Overview/SummonerMates.vue' -import SummonerStats from '@/components/Summoner/Overview/SummonerStats.vue' +// import SummonerChampions from '@/components/Summoner/Overview/SummonerChampions.vue' +// import SummonerMates from '@/components/Summoner/Overview/SummonerMates.vue' +// import SummonerStats from '@/components/Summoner/Overview/SummonerStats.vue' import VueStickySidebar from 'vue-sticky-sidebar' export default { @@ -67,9 +68,9 @@ export default { LoadingButton, Match, OverviewLoader, - SummonerChampions, - SummonerMates, - SummonerStats, + // SummonerChampions, + // SummonerMates, + // SummonerStats, VueStickySidebar }, diff --git a/server-v2/app/Parsers/MatchParser.ts b/server-v2/app/Parsers/MatchParser.ts index 2490d0f..c7782fc 100644 --- a/server-v2/app/Parsers/MatchParser.ts +++ b/server-v2/app/Parsers/MatchParser.ts @@ -2,6 +2,8 @@ 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 CDragonService from 'App/Services/CDragonService' +import { ChampionRoles } from './ParsedType' class MatchParser { public async parseOneMatch(match: MatchDto) { // Parse + store in database @@ -25,7 +27,7 @@ class MatchParser { result = 'Remake' } const teamColor = team.teamId === 100 ? 'blueTeam' : 'redTeam' - parsedMatch.related(teamColor).create({ + await parsedMatch.related(teamColor).create({ matchId: match.metadata.matchId, color: team.teamId, result: result, @@ -64,6 +66,9 @@ class MatchParser { } } + const originalChampionData = CDragonService.champions.find((c) => c.id === player.championId)! + const champRoles = originalChampionData.roles + matchPlayers.push({ match_id: match.metadata.matchId, participant_id: player.participantId, @@ -79,8 +84,8 @@ class MatchParser { kp: kp, champ_level: player.champLevel, champion_id: player.championId, - champion_role1: 0, // TODO - champion_role2: 0, // TODO + champion_role1: ChampionRoles[champRoles[0]], + champion_role2: ChampionRoles[champRoles[1]], double_kills: player.doubleKills, triple_kills: player.tripleKills, quadra_kills: player.quadraKills, @@ -113,6 +118,11 @@ class MatchParser { }) } await Database.table('match_players').multiInsert(matchPlayers) + + // Load Match relations + await parsedMatch.load((loader) => { + loader.load('blueTeam').load('redTeam').load('players') + }) return parsedMatch } diff --git a/server-v2/app/Parsers/ParsedType.ts b/server-v2/app/Parsers/ParsedType.ts new file mode 100644 index 0000000..d197a9d --- /dev/null +++ b/server-v2/app/Parsers/ParsedType.ts @@ -0,0 +1,11 @@ +export enum ChampionRoles { + assassin, + fighter, + mage, + marksman, + support, + tank, +} + +// TODO +export enum TeamPosition {} diff --git a/server-v2/app/Serializers/BasicMatchSerializer.ts b/server-v2/app/Serializers/BasicMatchSerializer.ts index be6b3c4..b48c22e 100644 --- a/server-v2/app/Serializers/BasicMatchSerializer.ts +++ b/server-v2/app/Serializers/BasicMatchSerializer.ts @@ -1,6 +1,7 @@ import { getSeasonNumber, sortTeamByRole } from 'App/helpers' import Match from 'App/Models/Match' import MatchPlayer from 'App/Models/MatchPlayer' +import CDragonService from 'App/Services/CDragonService' import MatchSerializer from './MatchSerializer' import { SerializedMatch, @@ -17,7 +18,7 @@ class BasicMatchSerializer extends MatchSerializer { * @param id of the champion */ protected getChampion(id: number): SerializedMatchChampion { - const originalChampionData = this.champions.find((c) => c.id === id) + const originalChampionData = CDragonService.champions.find((c) => c.id === id) const icon = 'https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/' + originalChampionData!.squarePortraitPath.split('/assets/')[1].toLowerCase() @@ -53,7 +54,7 @@ class BasicMatchSerializer extends MatchSerializer { continue } - const item = this.items.find((i) => i.id === id) + const item = CDragonService.items.find((i) => i.id === id) if (!item) { items.push(null) continue @@ -104,19 +105,7 @@ class BasicMatchSerializer extends MatchSerializer { } } - public async serializeOneMatch(match: Match, puuid: string): Promise { - // TODO: use a CDragon Service - await super.getContext() - - // TODO: do we really need to... - if (!match.players) { - console.log('NEED TO LOAD') - - await match.load('players') - await match.load('blueTeam') - await match.load('redTeam') - } - + public serializeOneMatch(match: Match, puuid: string): SerializedMatch { const identity = match.players.find((p) => p.summonerPuuid === puuid)! const allyTeamColor = identity.team === 100 ? 'blueTeam' : 'redTeam' @@ -126,7 +115,7 @@ class BasicMatchSerializer extends MatchSerializer { const enemyPlayers: MatchPlayer[] = [] for (const p of match.players) { - p.team === allyTeam.color ? allyPlayers.push(p) : enemyPlayers.push(p) + p.team === identity.team ? allyPlayers.push(p) : enemyPlayers.push(p) } return { @@ -144,7 +133,7 @@ class BasicMatchSerializer extends MatchSerializer { perks: this.getPerks(identity), region: match.region, result: allyTeam.result, - role: identity.teamPosition, + role: identity.teamPosition.length ? identity.teamPosition : 'NONE', season: getSeasonNumber(match.date), secondSum: identity.summoner2Id, stats: this.getStats(identity), @@ -153,10 +142,8 @@ class BasicMatchSerializer extends MatchSerializer { time: match.gameDuration, } } - public async serialize(matches: Match[], puuid: string): Promise { - await super.getContext() - - return await Promise.all(matches.map((match) => this.serializeOneMatch(match, puuid))) + public serialize(matches: Match[], puuid: string): SerializedMatch[] { + return matches.map((match) => this.serializeOneMatch(match, puuid)) } } diff --git a/server-v2/app/Serializers/MatchSerializer.ts b/server-v2/app/Serializers/MatchSerializer.ts index abb3327..e4eff02 100644 --- a/server-v2/app/Serializers/MatchSerializer.ts +++ b/server-v2/app/Serializers/MatchSerializer.ts @@ -1,43 +1 @@ -import Jax from 'App/Services/Jax' -import { - ChampionDTO, - ItemDTO, - PerkDTO, - PerkStyleDTO, - SummonerSpellDTO, -} from 'App/Services/Jax/src/Endpoints/CDragonEndpoint' -import RoleIdentificationService, { - ChampionsPlayRate, -} from 'App/Services/RoleIdentificationService' - -export default abstract class MatchSerializer { - protected champions: ChampionDTO[] - protected items: ItemDTO[] - protected perks: PerkDTO[] - protected perkstyles: PerkStyleDTO[] - protected summonerSpells: SummonerSpellDTO[] - protected championRoles: ChampionsPlayRate - - /** - * Get global Context with CDragon Data - */ - public async getContext() { - if (this.champions) { - return - } - - const items = await Jax.CDragon.items() - const champions = await Jax.CDragon.champions() - const perks = await Jax.CDragon.perks() - const perkstyles = await Jax.CDragon.perkstyles() - const summonerSpells = await Jax.CDragon.summonerSpells() - const championRoles = await RoleIdentificationService.pullData().catch(() => {}) - - this.champions = champions - this.items = items - this.perks = perks - this.perkstyles = perkstyles.styles - this.summonerSpells = summonerSpells - this.championRoles = championRoles as ChampionsPlayRate - } -} +export default abstract class MatchSerializer {} diff --git a/server-v2/app/Services/CDragonService.ts b/server-v2/app/Services/CDragonService.ts new file mode 100644 index 0000000..d604604 --- /dev/null +++ b/server-v2/app/Services/CDragonService.ts @@ -0,0 +1,45 @@ +import Jax from 'App/Services/Jax' +import { + ChampionDTO, + ItemDTO, + PerkDTO, + PerkStyleDTO, + SummonerSpellDTO, +} from 'App/Services/Jax/src/Endpoints/CDragonEndpoint' +import RoleIdentificationService, { + ChampionsPlayRate, +} from 'App/Services/RoleIdentificationService' + +class CDragonService { + public champions: ChampionDTO[] + public items: ItemDTO[] + public perks: PerkDTO[] + public perkstyles: PerkStyleDTO[] + public summonerSpells: SummonerSpellDTO[] + public championRoles: ChampionsPlayRate + + /** + * Get global Context with CDragon Data + */ + public async getContext() { + if (this.champions) { + return + } + + const items = await Jax.CDragon.items() + const champions = await Jax.CDragon.champions() + const perks = await Jax.CDragon.perks() + const perkstyles = await Jax.CDragon.perkstyles() + const summonerSpells = await Jax.CDragon.summonerSpells() + const championRoles = await RoleIdentificationService.pullData().catch(() => {}) + + this.champions = champions + this.items = items + this.perks = perks + this.perkstyles = perkstyles.styles + this.summonerSpells = summonerSpells + this.championRoles = championRoles as ChampionsPlayRate + } +} + +export default new CDragonService() diff --git a/server-v2/app/Services/MatchService.ts b/server-v2/app/Services/MatchService.ts index cb8a779..8dda51e 100644 --- a/server-v2/app/Services/MatchService.ts +++ b/server-v2/app/Services/MatchService.ts @@ -98,7 +98,7 @@ class MatchService { if (matchSaved) { // TODO: Serialize match from DB + put it in Redis + push it in "matches" - matches.push(await BasicMatchSerializer.serializeOneMatch(matchSaved, summonerDB.puuid)) + matches.push(BasicMatchSerializer.serializeOneMatch(matchSaved, summonerDB.puuid)) } else { matchesToGetFromRiot.push(matchList[i].matchId) } @@ -113,10 +113,7 @@ class MatchService { const parsedMatches: any = await MatchParser.parse(matchesFromApi) // TODO: Serialize match from DB + put it in Redis + push it in "matches" - const serializedMatches = await BasicMatchSerializer.serialize( - parsedMatches, - summonerDB.puuid - ) + const serializedMatches = BasicMatchSerializer.serialize(parsedMatches, summonerDB.puuid) matches = [...matches, ...serializedMatches] } diff --git a/server-v2/providers/AppProvider.ts b/server-v2/providers/AppProvider.ts index d7d587e..666253d 100644 --- a/server-v2/providers/AppProvider.ts +++ b/server-v2/providers/AppProvider.ts @@ -9,6 +9,10 @@ export default class AppProvider { public async boot() { // IoC container is ready + + // Load CDragon Service + const CDragon = await import('App/Services/CDragonService') + await CDragon.default.getContext() } public async ready() {