feat: overview endpoint looks good

This commit is contained in:
Kalane 2021-09-14 00:06:12 +02:00
parent f428b77e0e
commit ac10c94be2
8 changed files with 93 additions and 80 deletions

View file

@ -10,9 +10,10 @@
class="z-40 sidebar" class="z-40 sidebar"
container-selector=".vue-sticky-container" container-selector=".vue-sticky-container"
> >
<SummonerChampions /> <!-- TODO: add it back when implemented -->
<!-- <SummonerChampions />
<SummonerStats /> <SummonerStats />
<SummonerMates /> <SummonerMates /> -->
</VueStickySidebar> </VueStickySidebar>
<div class="w-9/12"> <div class="w-9/12">
<div v-if="current && current.participants" class="mb-4"> <div v-if="current && current.participants" class="mb-4">
@ -56,9 +57,9 @@ import LiveMatch from '@/components/Match/LiveMatch.vue'
import LoadingButton from '@/components/Form/LoadingButton.vue' import LoadingButton from '@/components/Form/LoadingButton.vue'
import Match from '@/components/Match/Match.vue' import Match from '@/components/Match/Match.vue'
import OverviewLoader from '@/components/Summoner/Overview/OverviewLoader.vue' import OverviewLoader from '@/components/Summoner/Overview/OverviewLoader.vue'
import SummonerChampions from '@/components/Summoner/Overview/SummonerChampions.vue' // import SummonerChampions from '@/components/Summoner/Overview/SummonerChampions.vue'
import SummonerMates from '@/components/Summoner/Overview/SummonerMates.vue' // import SummonerMates from '@/components/Summoner/Overview/SummonerMates.vue'
import SummonerStats from '@/components/Summoner/Overview/SummonerStats.vue' // import SummonerStats from '@/components/Summoner/Overview/SummonerStats.vue'
import VueStickySidebar from 'vue-sticky-sidebar' import VueStickySidebar from 'vue-sticky-sidebar'
export default { export default {
@ -67,9 +68,9 @@ export default {
LoadingButton, LoadingButton,
Match, Match,
OverviewLoader, OverviewLoader,
SummonerChampions, // SummonerChampions,
SummonerMates, // SummonerMates,
SummonerStats, // SummonerStats,
VueStickySidebar VueStickySidebar
}, },

View file

@ -2,6 +2,8 @@ import Database from '@ioc:Adonis/Lucid/Database'
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 Match from 'App/Models/Match'
import { getSeasonNumber } from 'App/helpers' import { getSeasonNumber } from 'App/helpers'
import CDragonService from 'App/Services/CDragonService'
import { ChampionRoles } from './ParsedType'
class MatchParser { class MatchParser {
public async parseOneMatch(match: MatchDto) { public async parseOneMatch(match: MatchDto) {
// Parse + store in database // Parse + store in database
@ -25,7 +27,7 @@ class MatchParser {
result = 'Remake' result = 'Remake'
} }
const teamColor = team.teamId === 100 ? 'blueTeam' : 'redTeam' const teamColor = team.teamId === 100 ? 'blueTeam' : 'redTeam'
parsedMatch.related(teamColor).create({ await parsedMatch.related(teamColor).create({
matchId: match.metadata.matchId, matchId: match.metadata.matchId,
color: team.teamId, color: team.teamId,
result: result, result: result,
@ -64,6 +66,9 @@ class MatchParser {
} }
} }
const originalChampionData = CDragonService.champions.find((c) => c.id === player.championId)!
const champRoles = originalChampionData.roles
matchPlayers.push({ matchPlayers.push({
match_id: match.metadata.matchId, match_id: match.metadata.matchId,
participant_id: player.participantId, participant_id: player.participantId,
@ -79,8 +84,8 @@ class MatchParser {
kp: kp, kp: kp,
champ_level: player.champLevel, champ_level: player.champLevel,
champion_id: player.championId, champion_id: player.championId,
champion_role1: 0, // TODO champion_role1: ChampionRoles[champRoles[0]],
champion_role2: 0, // TODO champion_role2: ChampionRoles[champRoles[1]],
double_kills: player.doubleKills, double_kills: player.doubleKills,
triple_kills: player.tripleKills, triple_kills: player.tripleKills,
quadra_kills: player.quadraKills, quadra_kills: player.quadraKills,
@ -113,6 +118,11 @@ class MatchParser {
}) })
} }
await Database.table('match_players').multiInsert(matchPlayers) await Database.table('match_players').multiInsert(matchPlayers)
// Load Match relations
await parsedMatch.load((loader) => {
loader.load('blueTeam').load('redTeam').load('players')
})
return parsedMatch return parsedMatch
} }

View file

@ -0,0 +1,11 @@
export enum ChampionRoles {
assassin,
fighter,
mage,
marksman,
support,
tank,
}
// TODO
export enum TeamPosition {}

View file

@ -1,6 +1,7 @@
import { getSeasonNumber, sortTeamByRole } from 'App/helpers' import { getSeasonNumber, sortTeamByRole } from 'App/helpers'
import Match from 'App/Models/Match' import Match from 'App/Models/Match'
import MatchPlayer from 'App/Models/MatchPlayer' import MatchPlayer from 'App/Models/MatchPlayer'
import CDragonService from 'App/Services/CDragonService'
import MatchSerializer from './MatchSerializer' import MatchSerializer from './MatchSerializer'
import { import {
SerializedMatch, SerializedMatch,
@ -17,7 +18,7 @@ class BasicMatchSerializer extends MatchSerializer {
* @param id of the champion * @param id of the champion
*/ */
protected getChampion(id: number): SerializedMatchChampion { 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 = const icon =
'https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/' + 'https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/' +
originalChampionData!.squarePortraitPath.split('/assets/')[1].toLowerCase() originalChampionData!.squarePortraitPath.split('/assets/')[1].toLowerCase()
@ -53,7 +54,7 @@ class BasicMatchSerializer extends MatchSerializer {
continue continue
} }
const item = this.items.find((i) => i.id === id) const item = CDragonService.items.find((i) => i.id === id)
if (!item) { if (!item) {
items.push(null) items.push(null)
continue continue
@ -104,19 +105,7 @@ class BasicMatchSerializer extends MatchSerializer {
} }
} }
public async serializeOneMatch(match: Match, puuid: string): Promise<SerializedMatch> { public serializeOneMatch(match: Match, puuid: string): SerializedMatch {
// 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')
}
const identity = match.players.find((p) => p.summonerPuuid === puuid)! const identity = match.players.find((p) => p.summonerPuuid === puuid)!
const allyTeamColor = identity.team === 100 ? 'blueTeam' : 'redTeam' const allyTeamColor = identity.team === 100 ? 'blueTeam' : 'redTeam'
@ -126,7 +115,7 @@ class BasicMatchSerializer extends MatchSerializer {
const enemyPlayers: MatchPlayer[] = [] const enemyPlayers: MatchPlayer[] = []
for (const p of match.players) { 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 { return {
@ -144,7 +133,7 @@ class BasicMatchSerializer extends MatchSerializer {
perks: this.getPerks(identity), perks: this.getPerks(identity),
region: match.region, region: match.region,
result: allyTeam.result, result: allyTeam.result,
role: identity.teamPosition, role: identity.teamPosition.length ? identity.teamPosition : 'NONE',
season: getSeasonNumber(match.date), season: getSeasonNumber(match.date),
secondSum: identity.summoner2Id, secondSum: identity.summoner2Id,
stats: this.getStats(identity), stats: this.getStats(identity),
@ -153,10 +142,8 @@ class BasicMatchSerializer extends MatchSerializer {
time: match.gameDuration, time: match.gameDuration,
} }
} }
public async serialize(matches: Match[], puuid: string): Promise<SerializedMatch[]> { public serialize(matches: Match[], puuid: string): SerializedMatch[] {
await super.getContext() return matches.map((match) => this.serializeOneMatch(match, puuid))
return await Promise.all(matches.map((match) => this.serializeOneMatch(match, puuid)))
} }
} }

View file

@ -1,43 +1 @@
import Jax from 'App/Services/Jax' export default abstract class MatchSerializer {}
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
}
}

View file

@ -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()

View file

@ -98,7 +98,7 @@ class MatchService {
if (matchSaved) { if (matchSaved) {
// TODO: Serialize match from DB + put it in Redis + push it in "matches" // 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 { } else {
matchesToGetFromRiot.push(matchList[i].matchId) matchesToGetFromRiot.push(matchList[i].matchId)
} }
@ -113,10 +113,7 @@ class MatchService {
const parsedMatches: any = await MatchParser.parse(matchesFromApi) const parsedMatches: any = await MatchParser.parse(matchesFromApi)
// TODO: Serialize match from DB + put it in Redis + push it in "matches" // TODO: Serialize match from DB + put it in Redis + push it in "matches"
const serializedMatches = await BasicMatchSerializer.serialize( const serializedMatches = BasicMatchSerializer.serialize(parsedMatches, summonerDB.puuid)
parsedMatches,
summonerDB.puuid
)
matches = [...matches, ...serializedMatches] matches = [...matches, ...serializedMatches]
} }

View file

@ -9,6 +9,10 @@ export default class AppProvider {
public async boot() { public async boot() {
// IoC container is ready // IoC container is ready
// Load CDragon Service
const CDragon = await import('App/Services/CDragonService')
await CDragon.default.getContext()
} }
public async ready() { public async ready() {