2021-09-15 14:04:02 +00:00
|
|
|
import { sortTeamByRole } from 'App/helpers'
|
2021-09-15 14:34:44 +00:00
|
|
|
import { ChampionRoles, TeamPosition } from 'App/Parsers/ParsedType'
|
2021-09-15 13:44:53 +00:00
|
|
|
import MatchRepository from 'App/Repositories/MatchRepository'
|
2021-09-15 14:22:19 +00:00
|
|
|
import BasicMatchSerializer from 'App/Serializers/BasicMatchSerializer'
|
2021-09-15 13:44:53 +00:00
|
|
|
|
|
|
|
|
class StatsService {
|
2021-09-15 19:17:52 +00:00
|
|
|
public async getRecentActivity(puuid: string) {
|
|
|
|
|
return MatchRepository.recentActivity(puuid)
|
|
|
|
|
}
|
2021-09-15 13:44:53 +00:00
|
|
|
public async getSummonerStats(puuid: string, season?: number) {
|
|
|
|
|
console.time('GLOBAL')
|
2021-09-15 13:54:59 +00:00
|
|
|
const globalStats = await MatchRepository.globalStats(puuid)
|
2021-09-15 13:44:53 +00:00
|
|
|
console.timeEnd('GLOBAL')
|
2021-09-15 13:54:59 +00:00
|
|
|
console.time('GAMEMODE')
|
|
|
|
|
const gamemodeStats = await MatchRepository.gamemodeStats(puuid)
|
|
|
|
|
console.timeEnd('GAMEMODE')
|
2021-09-15 14:04:02 +00:00
|
|
|
console.time('ROLE')
|
|
|
|
|
const roleStats = await MatchRepository.roleStats(puuid)
|
|
|
|
|
// Check if all roles are in the array
|
|
|
|
|
const roles = ['TOP', 'JUNGLE', 'MIDDLE', 'BOTTOM', 'UTILITY']
|
|
|
|
|
for (const role of roles) {
|
|
|
|
|
const findedRole = roleStats.find((r) => TeamPosition[r.role] === role)
|
|
|
|
|
if (findedRole) {
|
|
|
|
|
findedRole.role = TeamPosition[findedRole.role]
|
|
|
|
|
} else {
|
|
|
|
|
roleStats.push({
|
|
|
|
|
count: 0,
|
|
|
|
|
losses: 0,
|
|
|
|
|
role,
|
|
|
|
|
wins: 0,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-15 14:22:19 +00:00
|
|
|
console.timeEnd('ROLE')
|
|
|
|
|
console.time('CHAMPION')
|
|
|
|
|
const championStats = await MatchRepository.championStats(puuid, 5)
|
|
|
|
|
for (const champ of championStats) {
|
|
|
|
|
champ.champion = BasicMatchSerializer.getChampion(champ.id)
|
|
|
|
|
}
|
|
|
|
|
console.timeEnd('CHAMPION')
|
2021-09-15 14:34:44 +00:00
|
|
|
console.time('CHAMPION-CLASS')
|
|
|
|
|
const championClassStats = await MatchRepository.championClassStats(puuid)
|
|
|
|
|
for (const champ of championClassStats) {
|
|
|
|
|
champ.id = ChampionRoles[champ.id]
|
|
|
|
|
}
|
|
|
|
|
console.timeEnd('CHAMPION-CLASS')
|
2021-09-15 16:35:39 +00:00
|
|
|
console.time('MATES')
|
|
|
|
|
const mates = await MatchRepository.mates(puuid)
|
|
|
|
|
console.timeEnd('MATES')
|
2021-09-15 13:44:53 +00:00
|
|
|
|
2021-09-15 19:17:52 +00:00
|
|
|
console.time('RECENT_ACTIVITY')
|
|
|
|
|
const recentActivity = await MatchRepository.recentActivity(puuid)
|
|
|
|
|
console.timeEnd('RECENT_ACTIVITY')
|
|
|
|
|
|
2021-09-15 13:44:53 +00:00
|
|
|
return {
|
|
|
|
|
global: globalStats,
|
2021-09-15 13:54:59 +00:00
|
|
|
league: gamemodeStats,
|
2021-09-15 14:04:02 +00:00
|
|
|
role: roleStats.sort(sortTeamByRole),
|
2021-09-15 14:22:19 +00:00
|
|
|
champion: championStats,
|
2021-09-15 16:35:39 +00:00
|
|
|
class: championClassStats,
|
|
|
|
|
mates,
|
2021-09-15 19:17:52 +00:00
|
|
|
recentActivity,
|
2021-09-15 13:44:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default new StatsService()
|