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
|
// 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
|
runes.sort((a, b) => b.count - a.count)
|
||||||
const maxRunes : Array<Rune | null> = [null, null, null]
|
if(runes.length > 3)
|
||||||
for(let rune of runes) {
|
runes.splice(3, runes.length - 3)
|
||||||
let maxcount = 2;
|
// Compute runes pickrate
|
||||||
if(rune.count <= maxes[maxcount]) continue;
|
for(let rune of runes)
|
||||||
|
rune.pickrate = rune.count / totalChampionMatches;
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cut item tree branches to keep only 4 branches every time and with percentage threshold
|
// 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)
|
treeCutBranches(builds.tree, 4, 0.05)
|
||||||
treeSort(builds.tree)
|
treeSort(builds.tree)
|
||||||
|
|
||||||
// Cut item start, to only 4 and with percentage threshold
|
// Cut item start, to only 4 and with percentage threshold
|
||||||
while(builds.start.length > 4) {
|
arrayRemovePercentage(builds.start, totalChampionMatches, 0.05)
|
||||||
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)
|
|
||||||
builds.start.sort((a, b) => b.count - a.count)
|
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
|
// 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.boots.sort((a, b) => b.count - a.count)
|
||||||
|
|
||||||
builds.bootsFirst /= (winningMatches + losingMatches)
|
builds.bootsFirst /= (winningMatches + losingMatches)
|
||||||
|
|
||||||
builds.lateGame.sort((a, b) => b.count - a.count)
|
builds.lateGame.sort((a, b) => b.count - a.count)
|
||||||
|
|
||||||
return {name: champion.name,
|
return {name: champion.name,
|
||||||
alias: champion.alias.toLowerCase(),
|
alias: champion.alias.toLowerCase(),
|
||||||
id: championId,
|
id: championId,
|
||||||
winrate:winningMatches / (winningMatches + losingMatches),
|
winrate: winningMatches / totalChampionMatches,
|
||||||
gameCount:(winningMatches + losingMatches),
|
gameCount: totalChampionMatches,
|
||||||
pickrate:(winningMatches + losingMatches)/totalMatches,
|
pickrate: totalChampionMatches/totalMatches,
|
||||||
runes: maxRunes.filter((x) => x != null),
|
runes: runes,
|
||||||
builds: builds
|
builds: builds
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user