Stat
@@ -48,16 +71,18 @@
>
{{ name }}
{{ stat }}
-
{{ (stat / (globalStats.time / 60)).toFixed(2) }}
-
{{ (stat / globalStats.count).toFixed(2) }}
+
{{ (stat / (stats.global.time / 60)).toFixed(2) }}
+
{{ (stat / stats.global.count).toFixed(2) }}
kill participation
- {{ globalStats.kp|percent }}
+ {{ stats.global.kp|percent }}
kda
- {{ (globalStats.kills + globalStats.assists) / globalStats.deaths|round }}
+ {{ (stats.global.kills + stats.global.assists) / stats.global.deaths|round }}
@@ -128,17 +153,14 @@ export default {
},
computed: {
- globalStats() {
- return this.stats.find(s => s._id === null)
+ mostPlayedRole() {
+ return Math.max(...this.stats.role.map(r => r.count), 0)
},
globalStatsKeys() {
// eslint-disable-next-line no-unused-vars
- const { _id, wins, losses, count, time, kp, ...rest } = this.globalStats
+ const { _id, wins, losses, count, time, kp, ...rest } = this.stats.global
return rest
},
- leagueStats() {
- return this.stats.filter(s => s._id !== null)
- },
...mapState({
stats: state => state.summoner.infos.stats
}),
@@ -154,7 +176,7 @@ export default {
}
},
leagueStatsByType(typeName) {
- return this.leagueStats
+ return this.stats.league
.map(l => {
return { ...l, ...gameModes[l._id] }
})
diff --git a/server/app/Controllers/Http/SummonerController.js b/server/app/Controllers/Http/SummonerController.js
index b08ffab..7042b9f 100644
--- a/server/app/Controllers/Http/SummonerController.js
+++ b/server/app/Controllers/Http/SummonerController.js
@@ -93,6 +93,56 @@ class SummonerController {
}
])
+ const roleStats = await Match.query().aggregate([
+ {
+ $match: {
+ summoner_puuid: account.puuid,
+ role: { $not: { $eq: 'NONE' } }
+ }
+ },
+ {
+ $group: {
+ _id: "$role",
+ count: { $sum: 1 },
+ wins: {
+ $sum: {
+ $cond: [
+ { $eq: ["$result", "Win"] }, 1, 0
+ ]
+ }
+ },
+ losses: {
+ $sum: {
+ $cond: [
+ { $eq: ["$result", "Fail"] }, 1, 0
+ ]
+ }
+ }
+ },
+ },
+ {
+ $project: {
+ role: "$_id",
+ count: "$count",
+ wins: "$wins",
+ losses: "$losses",
+ }
+ }
+ ])
+
+ // Check if all roles are in the array
+ const roles = ['TOP', 'JUNGLE', 'MIDDLE', 'BOTTOM', 'SUPPORT']
+ for (const role of roles) {
+ if (!roleStats.find(r => r.role === role)) {
+ roleStats.push({
+ count: 0,
+ losses: 0,
+ role,
+ wins: 0
+ })
+ }
+ }
+
const globalStats = await Match.query().aggregate([
{
$match: {
@@ -127,7 +177,11 @@ class SummonerController {
}
}
])
- finalJSON.stats = [...globalStats, ...gamemodeStats]
+ finalJSON.stats = {
+ global: globalStats[0],
+ league: gamemodeStats,
+ role: roleStats.sort(MatchHelper.sortTeamByRole),
+ }
console.timeEnd('STATS')
// SAVE IN DB