Lane-dependant stats (fix #5)
All checks were successful
pipeline / build-and-push-images (push) Successful in 23s
pipeline / deploy (push) Successful in 7s

This commit is contained in:
2024-11-29 18:26:17 +01:00
parent 5b7262877d
commit d8443efd7e
12 changed files with 233 additions and 107 deletions

View File

@@ -46,6 +46,16 @@ type Champion = {
name: String
alias: String
}
type LaneData = {
data: string
count: number
winningMatches: number
losingMatches: number
winrate: number
pickrate: number
runes: Array<Rune>
builds: Builds
}
function handleParticipantRunes(participant, runes: Array<Rune>) {
const primaryStyle = participant.perks.styles[0].style
@@ -141,9 +151,7 @@ async function championInfos(client, patch: number, champion: Champion) {
let winningMatches = 0;
let losingMatches = 0;
let totalMatches = 0;
const lanes : Array<{data: string, count: number}> = [];
const runes : Array<Rune> = [];
const builds : Builds = {tree:treeInit(), start: [], bootsFirst: 0, boots: [], lateGame: []}
const lanes : Array<LaneData> = [];
for await (let match of allMatches) {
totalMatches += 1;
let participantIndex = 0;
@@ -158,16 +166,24 @@ async function championInfos(client, patch: number, champion: Champion) {
losingMatches += 1;
// Lanes
// TODO: make stats lane-dependant
const already = lanes.find((x) => x.data == participant.teamPosition)
if(already == undefined) lanes.push({count:1, data: participant.teamPosition})
else already.count += 1
let lane = lanes.find((x) => x.data == participant.teamPosition)
if(lane == undefined) {
const builds : Builds = {tree:treeInit(), start: [], bootsFirst: 0, boots: [], lateGame: []}
lane = {count:1, data: participant.teamPosition, runes:[], builds:builds, winningMatches: 0, losingMatches: 0, winrate: 0, pickrate: 0}
lanes.push(lane)
}
else lane.count += 1
if(participant.win)
lane.winningMatches += 1;
else
lane.losingMatches += 1;
// Runes
handleParticipantRunes(participant, runes)
handleParticipantRunes(participant, lane.runes)
// Items
handleMatchItems(match.timeline, participantIndex, builds)
handleMatchItems(match.timeline, participantIndex, lane.builds)
break;
}
@@ -179,31 +195,44 @@ async function championInfos(client, patch: number, champion: Champion) {
lanes.sort((a, b) => b.count - a.count)
// Filter runes to keep 3 most played
runes.sort((a, b) => b.count - a.count)
if(runes.length > 3)
runes.splice(3, runes.length - 3)
// Compute runes pickrate
for(let rune of runes)
rune.pickrate = rune.count / totalChampionMatches;
for(let lane of lanes) {
const runes = lane.runes
runes.sort((a, b) => b.count - a.count)
if(runes.length > 3)
runes.splice(3, runes.length - 3)
// Compute runes pickrate
for(let rune of runes)
rune.pickrate = rune.count / lane.count;
}
// Cut item tree branches to keep only 4 branches every time and with percentage threshold
builds.tree.count = totalChampionMatches;
treeCutBranches(builds.tree, 4, 0.05)
treeSort(builds.tree)
for(let lane of lanes) {
const builds = lane.builds
// Cut item start, to only 4 and with percentage threshold
arrayRemovePercentage(builds.start, totalChampionMatches, 0.05)
builds.start.sort((a, b) => b.count - a.count)
if(builds.start.length > 4)
builds.start.splice(4, builds.start.length - 4)
// Cut item tree branches to keep only 4 branches every time and with percentage threshold
builds.tree.count = lane.count;
treeCutBranches(builds.tree, 4, 0.05)
treeSort(builds.tree)
// Cut item start, to only 4 and with percentage threshold
arrayRemovePercentage(builds.start, lane.count, 0.05)
builds.start.sort((a, b) => b.count - a.count)
if(builds.start.length > 4)
builds.start.splice(4, builds.start.length - 4)
// Remove boots that are not within percentage threshold
arrayRemovePercentage(builds.boots, totalChampionMatches, 0.05)
builds.boots.sort((a, b) => b.count - a.count)
// Remove boots that are not within percentage threshold
arrayRemovePercentage(builds.boots, lane.count, 0.05)
builds.boots.sort((a, b) => b.count - a.count)
builds.bootsFirst /= (winningMatches + losingMatches)
builds.bootsFirst /= lane.count
builds.lateGame.sort((a, b) => b.count - a.count)
builds.lateGame.sort((a, b) => b.count - a.count)
}
for(let lane of lanes) {
lane.winrate = lane.winningMatches / lane.count
lane.pickrate = lane.count / totalMatches
}
return {name: champion.name,
alias: champion.alias.toLowerCase(),
@@ -212,8 +241,6 @@ async function championInfos(client, patch: number, champion: Champion) {
winrate: winningMatches / totalChampionMatches,
gameCount: totalChampionMatches,
pickrate: totalChampionMatches/totalMatches,
runes: runes,
builds: builds
};
}