2019-11-03 17:49:58 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
|
|
const MatchTransformer = use('App/Transformers/MatchTransformer')
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* DetailedMatchTransformer class
|
|
|
|
|
*
|
|
|
|
|
* @class DetailedMatchTransformer
|
|
|
|
|
*/
|
|
|
|
|
class DetailedMatchTransformer extends MatchTransformer {
|
|
|
|
|
/**
|
2019-11-03 19:59:21 +00:00
|
|
|
* Transform raw data from Riot API
|
|
|
|
|
* @param match data from Riot API
|
2019-11-03 17:49:58 +00:00
|
|
|
*/
|
2019-11-16 16:43:55 +00:00
|
|
|
async transform(match) {
|
|
|
|
|
await super.getContext()
|
2019-11-03 17:49:58 +00:00
|
|
|
|
|
|
|
|
// Global data
|
2019-11-16 16:43:55 +00:00
|
|
|
const globalInfos = super.getGameInfos(match)
|
2019-11-03 17:49:58 +00:00
|
|
|
|
|
|
|
|
// Teams
|
2019-11-16 16:43:55 +00:00
|
|
|
const firstTeam = this.getTeamData(match, match.teams[0])
|
|
|
|
|
const secondTeam = this.getTeamData(match, match.teams[1])
|
2019-11-03 17:49:58 +00:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
gameId: match.gameId,
|
|
|
|
|
season: match.seasonId,
|
|
|
|
|
blueTeam: firstTeam.color === 'Blue' ? firstTeam : secondTeam,
|
|
|
|
|
redTeam: firstTeam.color === 'Blue' ? secondTeam : firstTeam,
|
2019-11-03 19:59:21 +00:00
|
|
|
...globalInfos
|
2019-11-03 17:49:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get all data of one team
|
2019-11-16 16:43:55 +00:00
|
|
|
* @param match raw match data from Riot API
|
2019-11-03 17:49:58 +00:00
|
|
|
* @param team raw team data from Riot API
|
|
|
|
|
*/
|
2019-11-16 16:43:55 +00:00
|
|
|
getTeamData(match, team) {
|
2019-11-03 17:49:58 +00:00
|
|
|
let win = team.win
|
2019-11-16 16:43:55 +00:00
|
|
|
if (match.gameDuration < 300) {
|
2019-11-03 17:49:58 +00:00
|
|
|
win = 'Remake'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Global stats of the team
|
2019-11-16 16:43:55 +00:00
|
|
|
const teamPlayers = match.participants.filter(p => p.teamId === team.teamId)
|
2019-11-03 17:49:58 +00:00
|
|
|
const teamStats = teamPlayers.reduce((prev, cur) => {
|
|
|
|
|
prev.kills += cur.stats.kills
|
|
|
|
|
prev.deaths += cur.stats.deaths
|
|
|
|
|
prev.assists += cur.stats.assists
|
|
|
|
|
prev.gold += cur.stats.goldEarned
|
|
|
|
|
prev.dmgChamp += cur.stats.totalDamageDealtToChampions
|
|
|
|
|
prev.dmgObj += cur.stats.damageDealtToObjectives
|
|
|
|
|
prev.dmgTaken += cur.stats.totalDamageTaken
|
|
|
|
|
return prev;
|
|
|
|
|
}, { kills: 0, deaths: 0, assists: 0, gold: 0, dmgChamp: 0, dmgObj: 0, dmgTaken: 0 });
|
|
|
|
|
|
|
|
|
|
// Bans
|
|
|
|
|
let bans = null
|
|
|
|
|
if (team.bans) {
|
|
|
|
|
bans = team.bans.map(b => {
|
|
|
|
|
if (b.championId === -1) {
|
|
|
|
|
b.champion = {
|
|
|
|
|
id: null,
|
|
|
|
|
name: null
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2019-11-25 20:15:52 +00:00
|
|
|
b.champion = super.getChampion(b.championId)
|
2019-11-03 17:49:58 +00:00
|
|
|
}
|
|
|
|
|
return b
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Players
|
|
|
|
|
const players = teamPlayers
|
2019-11-16 16:43:55 +00:00
|
|
|
.map(p => super.getPlayerData(match, p, true, teamStats))
|
2019-12-01 14:20:49 +00:00
|
|
|
.sort(this.sortTeamByRole)
|
2019-11-03 17:49:58 +00:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
bans,
|
|
|
|
|
barons: team.baronKills,
|
|
|
|
|
color: team.teamId === 100 ? 'Blue' : 'Red',
|
|
|
|
|
dragons: team.dragonKills,
|
|
|
|
|
inhibitors: team.inhibitorKills,
|
|
|
|
|
players,
|
|
|
|
|
result: win,
|
|
|
|
|
riftHerald: team.riftHeraldKills,
|
|
|
|
|
teamStats,
|
|
|
|
|
towers: team.towerKills,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = new DetailedMatchTransformer()
|