diff --git a/client/src/components/Summoner/SummonerMates.vue b/client/src/components/Summoner/SummonerMates.vue
index 19d8c3e..654192e 100644
--- a/client/src/components/Summoner/SummonerMates.vue
+++ b/client/src/components/Summoner/SummonerMates.vue
@@ -19,21 +19,21 @@
-
{{ mate.name }}
+ >{{ mate._id }}
{{ mate.wins }} / {{ mate.losses }}
@@ -43,9 +43,9 @@
Winrate
{{ mate.winrate }}
+ >{{ winrate(mate.wins, mate.count)|percent }}
@@ -82,13 +82,13 @@ export default {
return this.mates.length > 0
},
...mapState({
- mates: state => state.summoner.infos.mates
+ mates: state => state.summoner.infos.stats.mates
}),
},
methods: {
- getWinrateColor(winrate, background = true) {
- winrate = winrate.slice(0, -1)
+ getWinrateColor(wins, count, background = true) {
+ const winrate = this.winrate(wins, count)
if (winrate >= 70) {
return background ? 'bg-yellow-400' : 'text-yellow-400'
} else if (winrate >= 60) {
@@ -97,6 +97,9 @@ export default {
return background ? 'bg-teal-300' : 'text-teal-300'
}
return background ? 'bg-teal-200' : 'text-teal-200'
+ },
+ winrate(wins, count) {
+ return wins * 100 / count
}
}
}
diff --git a/client/src/helpers/summoner.js b/client/src/helpers/summoner.js
index 19cdb09..a0d101b 100644
--- a/client/src/helpers/summoner.js
+++ b/client/src/helpers/summoner.js
@@ -99,7 +99,6 @@ export function createSummonerData(RiotData) {
ranked: RiotData.ranked,
matchList: RiotData.allMatches,
matches: createMatchData(RiotData.matchesDetails),
- mates: createMatesData(RiotData.mates),
playing: RiotData.playing,
stats: RiotData.stats,
}
diff --git a/client/src/store/modules/summoner.js b/client/src/store/modules/summoner.js
index 8860aa9..6af7170 100644
--- a/client/src/store/modules/summoner.js
+++ b/client/src/store/modules/summoner.js
@@ -39,7 +39,6 @@ export const mutations = {
state.infos.matches = infos.matches
state.infos.ranked = infos.ranked
state.infos.matchIndex = infos.matches.length
- state.infos.mates = infos.mates
state.infos.playing = infos.playing
state.infos.stats = infos.stats
state.status = 'found'
diff --git a/server/app/Controllers/Http/MatchController.js b/server/app/Controllers/Http/MatchController.js
index 6b004aa..3100c02 100644
--- a/server/app/Controllers/Http/MatchController.js
+++ b/server/app/Controllers/Http/MatchController.js
@@ -3,6 +3,7 @@
const Jax = use('Jax')
const DetailedMatch = use('App/Models/DetailedMatch')
const DetailedMatchTransformer = use('App/Transformers/DetailedMatchTransformer')
+const Match = use('App/Models/Match')
const MatchHelper = use('App/Helpers/MatchHelper')
const Summoner = use('App/Models/Summoner')
@@ -22,7 +23,7 @@ class MatchController {
return response.json({
matches,
- mates: summonerDB.mates.filter(m => m.wins + m.losses > 1)
+ mates: await Match.mates(account.puuid, account.name)
})
}
diff --git a/server/app/Controllers/Http/SummonerController.js b/server/app/Controllers/Http/SummonerController.js
index 7afa260..3fb751a 100644
--- a/server/app/Controllers/Http/SummonerController.js
+++ b/server/app/Controllers/Http/SummonerController.js
@@ -57,9 +57,6 @@ class SummonerController {
const gameIds = matchList.slice(0, 10).map(({ gameId }) => gameId)
finalJSON.matchesDetails = await MatchHelper.getMatches(account, gameIds, summonerDB)
- // MATES
- finalJSON.mates = summonerDB.mates.filter(m => m.wins + m.losses > 1)
-
// PATCH VERSION
finalJSON.version = Jax.DDragon.Version
@@ -80,13 +77,15 @@ class SummonerController {
})
}
}
- const championClassStats = await Match.championClassStats(account.puuid);
+ const championClassStats = await Match.championClassStats(account.puuid)
+ const mates = await Match.mates(account.puuid, account.name)
finalJSON.stats = {
global: globalStats[0],
league: gamemodeStats,
role: roleStats.sort(MatchHelper.sortTeamByRole),
class: championClassStats,
+ mates,
}
console.timeEnd('STATS')
diff --git a/server/app/Helpers/MatchHelper.js b/server/app/Helpers/MatchHelper.js
index 2be946f..d3bfcae 100644
--- a/server/app/Helpers/MatchHelper.js
+++ b/server/app/Helpers/MatchHelper.js
@@ -3,7 +3,6 @@
const Logger = use('Logger')
const Jax = use('Jax')
const BasicMatchTransformer = use('App/Transformers/BasicMatchTransformer')
-const SummonerHelper = use('App/Helpers/SummonerHelper')
class MatchHelper {
/**
@@ -118,10 +117,6 @@ class MatchHelper {
console.log(matchesFromApi.length)
Logger.transport('file').info(matchesFromApi)
-
- // Update teamMates
- SummonerHelper.updatePlayedWith(account, summonerDB, matchesFromApi)
-
matchesDetails = [...matchesDetails, ...matchesFromApi]
/* Save all matches from Riot Api in db */
diff --git a/server/app/Helpers/SummonerHelper.js b/server/app/Helpers/SummonerHelper.js
deleted file mode 100644
index de48cdc..0000000
--- a/server/app/Helpers/SummonerHelper.js
+++ /dev/null
@@ -1,42 +0,0 @@
-'use strict'
-
-const Logger = use('Logger')
-const Summoner = use('App/Models/Summoner')
-
-class SummonerHelper {
- /**
- * Update the mates' list of the Summoner
- * @param account of the summoner
- * @param summonerDB summoner in the database
- * @param matches all new matches
- */
- updatePlayedWith(account, summonerDB, matches) {
- let teamMates = summonerDB.mates || []
-
- for (const match of matches) {
- if(match.result === 'Remake') continue
- const win = match.result === 'Win'
-
- for (const ally of match.allyTeam) {
- if (ally.name === account.name) continue
-
- const mate = teamMates.find(m => m.name === ally.name)
- if (mate) {
- win ? mate.wins++ : mate.losses++
- } else {
- teamMates.push({
- name: ally.name,
- wins: win ? 1 : 0,
- losses: win ? 0 : 1,
- creation: Date.now()
- })
- }
- }
- }
-
- // Save new mates'list
- summonerDB.mates = teamMates
- }
-}
-
-module.exports = new SummonerHelper()
diff --git a/server/app/Models/Match.js b/server/app/Models/Match.js
index 301f05d..419d145 100644
--- a/server/app/Models/Match.js
+++ b/server/app/Models/Match.js
@@ -17,7 +17,7 @@ class Match extends Model {
},
{
$group: {
- _id: { "$arrayElemAt": [ "$champion.tags", 0 ] },
+ _id: { "$arrayElemAt": ["$champion.tags", 0] },
count: { $sum: 1 },
wins: {
$sum: {
@@ -155,6 +155,50 @@ class Match extends Model {
}
])
}
+
+ /**
+ * Get Summoner's mates list
+ * @param puuid of the summoner
+ * @param summonerName of the summoner
+ */
+ static mates(puuid, summonerName) {
+ return Match.query().aggregate([
+ {
+ $match: {
+ summoner_puuid: puuid
+ }
+ },
+ { $unwind: "$allyTeam" },
+ {
+ $group: {
+ _id: "$allyTeam.name",
+ count: { $sum: 1 },
+ wins: {
+ $sum: {
+ $cond: [
+ { $eq: ["$result", "Win"] }, 1, 0
+ ]
+ }
+ },
+ losses: {
+ $sum: {
+ $cond: [
+ { $eq: ["$result", "Fail"] }, 1, 0
+ ]
+ }
+ }
+ },
+ },
+ {
+ $match: {
+ _id: { $not: { $eq: summonerName } },
+ 'count': { $gte: 2 }
+ }
+ },
+ { $sort: { 'count': -1 } },
+ { $limit: 15 },
+ ])
+ }
}
module.exports = Match