Refactor champion stats
All checks were successful
pipeline / build-and-push-images (push) Successful in 24s
pipeline / deploy (push) Successful in 6s

This commit is contained in:
2024-11-27 16:23:30 +01:00
parent 20197bab8a
commit cca1909eb6

View File

@@ -47,31 +47,7 @@ type Champion = {
alias: String alias: String
} }
async function championInfos(client, patch: number, champion: Champion) { function handleParticipantRunes(participant, runes: Array<Rune>) {
const championId = champion.id
const database = client.db("matches");
const matches = database.collection(patch)
const allMatches = matches.find()
let winningMatches = 0;
let losingMatches = 0;
let totalMatches = 0;
const runes : Array<Rune> = [];
const builds : Builds = {tree:treeInit(), start: [], bootsFirst: 0, boots: [], lateGame: []}
for await (let match of allMatches) {
totalMatches += 1;
let participantIndex = 0;
for(let participant of match.info.participants) {
participantIndex += 1
if(participant.championId != championId) continue;
// Winrate
if(participant.win)
winningMatches += 1;
else
losingMatches += 1;
// Runes
const primaryStyle = participant.perks.styles[0].style const primaryStyle = participant.perks.styles[0].style
const secondaryStyle = participant.perks.styles[1].style const secondaryStyle = participant.perks.styles[1].style
const selections : Array<number> = [] const selections : Array<number> = []
@@ -90,10 +66,11 @@ async function championInfos(client, patch: number, champion: Champion) {
} }
} }
if(addRunes) runes.push(gameRunes) if(addRunes) runes.push(gameRunes)
}
// Items function handleMatchItems(timeline, participantIndex : number, builds: Builds) {
const items : Array<number> = [] const items : Array<number> = []
for(let frame of match.timeline.info.frames) { for(let frame of timeline.info.frames) {
for(let event of frame.events) { for(let event of frame.events) {
if(event.participantId != participantIndex) continue; if(event.participantId != participantIndex) continue;
if(event.type == "ITEM_UNDO") { if(event.type == "ITEM_UNDO") {
@@ -153,6 +130,37 @@ async function championInfos(client, patch: number, champion: Champion) {
if(already == undefined) builds.lateGame.push({count:1, data:item}) if(already == undefined) builds.lateGame.push({count:1, data:item})
else already.count += 1 else already.count += 1
} }
}
async function championInfos(client, patch: number, champion: Champion) {
const championId = champion.id
const database = client.db("matches");
const matches = database.collection(patch)
const allMatches = matches.find()
let winningMatches = 0;
let losingMatches = 0;
let totalMatches = 0;
const runes : Array<Rune> = [];
const builds : Builds = {tree:treeInit(), start: [], bootsFirst: 0, boots: [], lateGame: []}
for await (let match of allMatches) {
totalMatches += 1;
let participantIndex = 0;
for(let participant of match.info.participants) {
participantIndex += 1
if(participant.championId != championId) continue;
// Winrate
if(participant.win)
winningMatches += 1;
else
losingMatches += 1;
// Runes
handleParticipantRunes(participant, runes)
// Items
handleMatchItems(match.timeline, participantIndex, builds)
break; break;
} }