Cleanup championstats code
This commit is contained in:
@@ -158,52 +158,42 @@ async function championInfos(client, patch: number, champion: Champion) {
|
||||
}
|
||||
}
|
||||
|
||||
let totalChampionMatches = winningMatches + losingMatches;
|
||||
|
||||
// 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<Rune | null> = [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--;
|
||||
}
|
||||
|
||||
rune.pickrate = rune.count / (winningMatches + losingMatches)
|
||||
if(rune.count <= maxes[maxcount]) maxcount++;
|
||||
maxes[maxcount] = rune.count
|
||||
maxRunes[maxcount] = rune
|
||||
}
|
||||
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
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user