diff --git a/server/app/Services/RoleIdentificationService.js b/server/app/Services/RoleIdentificationService.js index ef7fd99..2e8bd29 100644 --- a/server/app/Services/RoleIdentificationService.js +++ b/server/app/Services/RoleIdentificationService.js @@ -142,13 +142,18 @@ class RoleIdentificationService { * Get roles for the 5 players of a team * @param championPositions * @param composition + * @param jungle */ - getRoles (championPositions, composition) { + getRoles (championPositions, composition, jungle = null) { const identified = {} let positions = {} let secondaryPositions = null let secondaryMetric = -Infinity + if(jungle) { + identified['JUNGLE'] = jungle + } + while (Object.keys(identified).length < composition.length - 1) { let { bestPositions, bestMetric: metric, secondBestPositions: sbp } = this._getPositions(championPositions, composition, diff --git a/server/app/Transformers/LiveMatchTransformer.js b/server/app/Transformers/LiveMatchTransformer.js index c515d0e..63e7faa 100644 --- a/server/app/Transformers/LiveMatchTransformer.js +++ b/server/app/Transformers/LiveMatchTransformer.js @@ -23,6 +23,13 @@ class LiveMatchTransformer extends MatchTransformer { return participant } + _getTeamRoles(team) { + const teamJunglers = team.filter(p => p.jungle) + const jungle = teamJunglers.length === 1 ? teamJunglers[0].champion : null + + return RoleIdentificationService.getRoles(this.championRoles, team.map(p => p.champion), jungle) + } + /** * Transform raw data from Riot API * @param match data from Riot API, one live match @@ -37,10 +44,12 @@ class LiveMatchTransformer extends MatchTransformer { let redRoles = [] if (this.championRoles) { match.participants.map(p => { - p.teamId === 100 ? blueTeam.push(p.championId) : redTeam.push(p.championId) + const playerRole = { champion: p.championId, jungle: p.spell1Id === 11 || p.spell2Id === 11 } + p.teamId === 100 ? blueTeam.push(playerRole) : redTeam.push(playerRole) }) - blueRoles = RoleIdentificationService.getRoles(this.championRoles, blueTeam) - redRoles = RoleIdentificationService.getRoles(this.championRoles, redTeam) + + blueRoles = this._getTeamRoles(blueTeam) + redRoles = this._getTeamRoles(redTeam) } for (const participant of match.participants) {