mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 21:07:27 +00:00
feat: roleStats query
This commit is contained in:
parent
23b407e5c4
commit
92abb9de0f
2 changed files with 40 additions and 16 deletions
|
|
@ -68,6 +68,26 @@ class MatchRepository {
|
||||||
const { rows } = await Database.rawQuery(query, { puuid })
|
const { rows } = await Database.rawQuery(query, { puuid })
|
||||||
return rows
|
return rows
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async roleStats(puuid: string) {
|
||||||
|
const query = `
|
||||||
|
SELECT
|
||||||
|
match_players.team_position as role,
|
||||||
|
COUNT(match_players.id) as count,
|
||||||
|
COUNT(case when match_teams.result = 'Win' then 1 else null end) as wins,
|
||||||
|
COUNT(case when match_teams.result = 'Fail' then 1 else null end) as losses
|
||||||
|
FROM
|
||||||
|
match_players
|
||||||
|
INNER JOIN matches ON matches.id = match_players.match_id
|
||||||
|
INNER JOIN match_teams ON match_players.match_id = match_teams.match_id AND match_players.team = match_teams.color
|
||||||
|
WHERE
|
||||||
|
summoner_puuid = :puuid
|
||||||
|
GROUP BY
|
||||||
|
role
|
||||||
|
`
|
||||||
|
const { rows } = await Database.rawQuery(query, { puuid })
|
||||||
|
return rows
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new MatchRepository()
|
export default new MatchRepository()
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
|
import { sortTeamByRole } from 'App/helpers'
|
||||||
|
import { TeamPosition } from 'App/Parsers/ParsedType'
|
||||||
import MatchRepository from 'App/Repositories/MatchRepository'
|
import MatchRepository from 'App/Repositories/MatchRepository'
|
||||||
// import { sortTeamByRole } from 'App/helpers'
|
|
||||||
|
|
||||||
class StatsService {
|
class StatsService {
|
||||||
public async getSummonerStats(puuid: string, season?: number) {
|
public async getSummonerStats(puuid: string, season?: number) {
|
||||||
|
|
@ -9,20 +10,23 @@ class StatsService {
|
||||||
console.time('GAMEMODE')
|
console.time('GAMEMODE')
|
||||||
const gamemodeStats = await MatchRepository.gamemodeStats(puuid)
|
const gamemodeStats = await MatchRepository.gamemodeStats(puuid)
|
||||||
console.timeEnd('GAMEMODE')
|
console.timeEnd('GAMEMODE')
|
||||||
// console.time('ROLE')
|
console.time('ROLE')
|
||||||
// const roleStats = await MatchRepository.roleStats(puuid, season)
|
const roleStats = await MatchRepository.roleStats(puuid)
|
||||||
// // 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', 'UTILITY']
|
||||||
// for (const role of roles) {
|
for (const role of roles) {
|
||||||
// if (!roleStats.find((r) => r.role === role)) {
|
const findedRole = roleStats.find((r) => TeamPosition[r.role] === role)
|
||||||
// roleStats.push({
|
if (findedRole) {
|
||||||
// count: 0,
|
findedRole.role = TeamPosition[findedRole.role]
|
||||||
// losses: 0,
|
} else {
|
||||||
// role,
|
roleStats.push({
|
||||||
// wins: 0,
|
count: 0,
|
||||||
// })
|
losses: 0,
|
||||||
// }
|
role,
|
||||||
// }
|
wins: 0,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
// console.timeEnd('ROLE')
|
// console.timeEnd('ROLE')
|
||||||
// console.time('CHAMPION')
|
// console.time('CHAMPION')
|
||||||
// const championStats = await MatchRepository.championStats(puuid, 5, season)
|
// const championStats = await MatchRepository.championStats(puuid, 5, season)
|
||||||
|
|
@ -37,7 +41,7 @@ class StatsService {
|
||||||
return {
|
return {
|
||||||
global: globalStats,
|
global: globalStats,
|
||||||
league: gamemodeStats,
|
league: gamemodeStats,
|
||||||
// role: roleStats.sort(sortTeamByRole),
|
role: roleStats.sort(sortTeamByRole),
|
||||||
// class: championClassStats,
|
// class: championClassStats,
|
||||||
// mates,
|
// mates,
|
||||||
// champion: championStats,
|
// champion: championStats,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue