mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 21:07:27 +00:00
feat: get stats by champion class from api
This commit is contained in:
parent
48d2fade07
commit
33ff97a7ac
3 changed files with 158 additions and 101 deletions
|
|
@ -53,7 +53,7 @@ class SummonerController {
|
||||||
const matchList = summonerDB.matchList
|
const matchList = summonerDB.matchList
|
||||||
finalJSON.allMatches = matchList
|
finalJSON.allMatches = matchList
|
||||||
|
|
||||||
// MATCHES DETAILS
|
// MATCHES BASIC
|
||||||
const gameIds = matchList.slice(0, 10).map(({ gameId }) => gameId)
|
const gameIds = matchList.slice(0, 10).map(({ gameId }) => gameId)
|
||||||
finalJSON.matchesDetails = await MatchHelper.getMatches(account, gameIds, summonerDB)
|
finalJSON.matchesDetails = await MatchHelper.getMatches(account, gameIds, summonerDB)
|
||||||
|
|
||||||
|
|
@ -65,71 +65,9 @@ class SummonerController {
|
||||||
|
|
||||||
// STATS
|
// STATS
|
||||||
console.time('STATS')
|
console.time('STATS')
|
||||||
const gamemodeStats = await Match.query().aggregate([
|
const globalStats = await Match.globalStats(account.puuid)
|
||||||
{
|
const gamemodeStats = await Match.gamemodeStats(account.puuid)
|
||||||
$match: {
|
const roleStats = await Match.roleStats(account.puuid)
|
||||||
summoner_puuid: account.puuid
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$group: {
|
|
||||||
_id: "$gamemode",
|
|
||||||
count: { $sum: 1 },
|
|
||||||
wins: {
|
|
||||||
$sum: {
|
|
||||||
$cond: [
|
|
||||||
{ $eq: ["$result", "Win"] }, 1, 0
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
losses: {
|
|
||||||
$sum: {
|
|
||||||
$cond: [
|
|
||||||
{ $eq: ["$result", "Fail"] }, 1, 0
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
])
|
|
||||||
|
|
||||||
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
|
// Check if all roles are in the array
|
||||||
const roles = ['TOP', 'JUNGLE', 'MIDDLE', 'BOTTOM', 'SUPPORT']
|
const roles = ['TOP', 'JUNGLE', 'MIDDLE', 'BOTTOM', 'SUPPORT']
|
||||||
for (const role of roles) {
|
for (const role of roles) {
|
||||||
|
|
@ -142,45 +80,13 @@ class SummonerController {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const championClassStats = await Match.championClassStats(account.puuid);
|
||||||
|
|
||||||
const globalStats = await Match.query().aggregate([
|
|
||||||
{
|
|
||||||
$match: {
|
|
||||||
summoner_puuid: account.puuid
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$group: {
|
|
||||||
_id: null,
|
|
||||||
count: { $sum: 1 },
|
|
||||||
time: { $sum: "$time" },
|
|
||||||
wins: {
|
|
||||||
$sum: {
|
|
||||||
$cond: [
|
|
||||||
{ $eq: ["$result", "Win"] }, 1, 0
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
losses: {
|
|
||||||
$sum: {
|
|
||||||
$cond: [
|
|
||||||
{ $eq: ["$result", "Fail"] }, 1, 0
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
kills: { $sum: "$stats.kills" },
|
|
||||||
deaths: { $sum: "$stats.deaths" },
|
|
||||||
assists: { $sum: "$stats.assists" },
|
|
||||||
minions: { $sum: "$stats.minions" },
|
|
||||||
vision: { $sum: "$stats.vision" },
|
|
||||||
kp: { $avg: "$stats.kp" },
|
|
||||||
}
|
|
||||||
}
|
|
||||||
])
|
|
||||||
finalJSON.stats = {
|
finalJSON.stats = {
|
||||||
global: globalStats[0],
|
global: globalStats[0],
|
||||||
league: gamemodeStats,
|
league: gamemodeStats,
|
||||||
role: roleStats.sort(MatchHelper.sortTeamByRole),
|
role: roleStats.sort(MatchHelper.sortTeamByRole),
|
||||||
|
class: championClassStats,
|
||||||
}
|
}
|
||||||
console.timeEnd('STATS')
|
console.timeEnd('STATS')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,157 @@
|
||||||
const Model = use('Model')
|
const Model = use('Model')
|
||||||
|
|
||||||
class Match extends Model {
|
class Match extends Model {
|
||||||
|
/**
|
||||||
|
* Get Summoner's statistics for all played champion classes
|
||||||
|
* @param puuid of the summoner
|
||||||
|
*/
|
||||||
|
static championClassStats(puuid) {
|
||||||
|
return Match.query().aggregate([
|
||||||
|
{
|
||||||
|
$match: {
|
||||||
|
summoner_puuid: puuid
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$group: {
|
||||||
|
_id: { "$arrayElemAt": [ "$champion.tags", 0 ] },
|
||||||
|
count: { $sum: 1 },
|
||||||
|
wins: {
|
||||||
|
$sum: {
|
||||||
|
$cond: [
|
||||||
|
{ $eq: ["$result", "Win"] }, 1, 0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
losses: {
|
||||||
|
$sum: {
|
||||||
|
$cond: [
|
||||||
|
{ $eq: ["$result", "Fail"] }, 1, 0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Summoner's statistics for all played modes
|
||||||
|
* @param puuid of the summoner
|
||||||
|
*/
|
||||||
|
static gamemodeStats(puuid) {
|
||||||
|
return Match.query().aggregate([
|
||||||
|
{
|
||||||
|
$match: {
|
||||||
|
summoner_puuid: puuid
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$group: {
|
||||||
|
_id: "$gamemode",
|
||||||
|
count: { $sum: 1 },
|
||||||
|
wins: {
|
||||||
|
$sum: {
|
||||||
|
$cond: [
|
||||||
|
{ $eq: ["$result", "Win"] }, 1, 0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
losses: {
|
||||||
|
$sum: {
|
||||||
|
$cond: [
|
||||||
|
{ $eq: ["$result", "Fail"] }, 1, 0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get global Summoner's statistics
|
||||||
|
* @param puuid of the summoner
|
||||||
|
*/
|
||||||
|
static globalStats(puuid) {
|
||||||
|
return Match.query().aggregate([
|
||||||
|
{
|
||||||
|
$match: {
|
||||||
|
summoner_puuid: puuid
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$group: {
|
||||||
|
_id: null,
|
||||||
|
count: { $sum: 1 },
|
||||||
|
time: { $sum: "$time" },
|
||||||
|
wins: {
|
||||||
|
$sum: {
|
||||||
|
$cond: [
|
||||||
|
{ $eq: ["$result", "Win"] }, 1, 0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
losses: {
|
||||||
|
$sum: {
|
||||||
|
$cond: [
|
||||||
|
{ $eq: ["$result", "Fail"] }, 1, 0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
kills: { $sum: "$stats.kills" },
|
||||||
|
deaths: { $sum: "$stats.deaths" },
|
||||||
|
assists: { $sum: "$stats.assists" },
|
||||||
|
minions: { $sum: "$stats.minions" },
|
||||||
|
vision: { $sum: "$stats.vision" },
|
||||||
|
kp: { $avg: "$stats.kp" },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Summoner's statistics for the 5 differnt roles
|
||||||
|
* @param puuid of the summoner
|
||||||
|
*/
|
||||||
|
static roleStats(puuid) {
|
||||||
|
return Match.query().aggregate([
|
||||||
|
{
|
||||||
|
$match: {
|
||||||
|
summoner_puuid: 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",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Match
|
module.exports = Match
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ class MatchTransformer {
|
||||||
getPlayerData(player, detailed, teamStats = {}) {
|
getPlayerData(player, detailed, teamStats = {}) {
|
||||||
const identity = this.match.participantIdentities.find(p => p.participantId === player.participantId)
|
const identity = this.match.participantIdentities.find(p => p.participantId === player.participantId)
|
||||||
const name = identity.player.summonerName
|
const name = identity.player.summonerName
|
||||||
const champion = (({ id, name }) => ({ id, name }))(Object.entries(this.champions).find(([, champion]) => Number(champion.key) === player.championId)[1])
|
const champion = (({ id, name, tags }) => ({ id, name, tags }))(Object.entries(this.champions).find(([, champion]) => Number(champion.key) === player.championId)[1])
|
||||||
const role = this.MatchHelper.getRoleName(player.timeline)
|
const role = this.MatchHelper.getRoleName(player.timeline)
|
||||||
const level = player.stats.champLevel
|
const level = player.stats.champLevel
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue