From 20197bab8a5043c9c65af297becd5e21ce6b699d Mon Sep 17 00:00:00 2001 From: vhaudiquet Date: Wed, 27 Nov 2024 16:14:14 +0100 Subject: [PATCH] Cleanup championstats code --- match_collector/champion_stat.ts | 48 +++++++++++++------------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/match_collector/champion_stat.ts b/match_collector/champion_stat.ts index c13c8b4..6be3cfa 100644 --- a/match_collector/champion_stat.ts +++ b/match_collector/champion_stat.ts @@ -158,52 +158,42 @@ async function championInfos(client, patch: number, champion: Champion) { } } - // Filter runes to keep 3 most played - const maxes = [0, 0, 0] // 24, 2, 1 -> 18 > 1 -> 24, 2, 2 -> 18 > 2 -> 24, 24, 2 - const maxRunes : Array = [null, null, null] - for(let rune of runes) { - let maxcount = 2; - if(rune.count <= maxes[maxcount]) continue; - - while(maxcount > 0 && rune.count > maxes[maxcount]) { - maxes[maxcount] = maxes[maxcount - 1]; - maxRunes[maxcount] = maxRunes[maxcount - 1]; - maxcount--; - } + let totalChampionMatches = winningMatches + losingMatches; - rune.pickrate = rune.count / (winningMatches + losingMatches) - if(rune.count <= maxes[maxcount]) maxcount++; - maxes[maxcount] = rune.count - maxRunes[maxcount] = rune - } + // 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; // Cut item tree branches to keep only 4 branches every time and with percentage threshold - builds.tree.count = (winningMatches + losingMatches) + builds.tree.count = totalChampionMatches; treeCutBranches(builds.tree, 4, 0.05) treeSort(builds.tree) // Cut item start, to only 4 and with percentage threshold - while(builds.start.length > 4) { - let leastUsedItem = builds.start.reduce((a, b) => Math.min(a.count, b.count) == a.count ? a : b, {data:undefined, count: +Infinity}) - builds.start.splice(builds.start.indexOf(leastUsedItem), 1) - } - arrayRemovePercentage(builds.start, (winningMatches + losingMatches), 0.05) + 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) // Remove boots that are not within percentage threshold - arrayRemovePercentage(builds.boots, (winningMatches + losingMatches), 0.05) - + arrayRemovePercentage(builds.boots, totalChampionMatches, 0.05) builds.boots.sort((a, b) => b.count - a.count) + builds.bootsFirst /= (winningMatches + losingMatches) + builds.lateGame.sort((a, b) => b.count - a.count) return {name: champion.name, alias: champion.alias.toLowerCase(), id: championId, - winrate:winningMatches / (winningMatches + losingMatches), - gameCount:(winningMatches + losingMatches), - pickrate:(winningMatches + losingMatches)/totalMatches, - runes: maxRunes.filter((x) => x != null), + winrate: winningMatches / totalChampionMatches, + gameCount: totalChampionMatches, + pickrate: totalChampionMatches/totalMatches, + runes: runes, builds: builds }; }