impr(result): rework burst heatmap speed brackets (keenemeck) (#4741)

This commit is contained in:
keenemeck 2023-10-27 09:51:26 -04:00 committed by GitHub
parent 8942ee2813
commit a30b36718c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1108,20 +1108,6 @@ export async function applyBurstHeatmap(): Promise<void> {
burstlist[index] = Math.round(typingSpeedUnit.fromWpm(burst));
});
if (
TestInput.input.getHistory(TestInput.input.getHistory().length - 1)
?.length !== TestWords.words.getCurrent()?.length
) {
burstlist = burstlist.splice(0, burstlist.length - 1);
}
const median = Misc.median(burstlist);
const adatm: number[] = [];
burstlist.forEach((burst) => {
adatm.push(Math.abs(median - burst));
});
const step = Misc.mean(adatm);
const themeColors = await ThemeColors.getAll();
let colors = [
@ -1148,25 +1134,28 @@ export async function applyBurstHeatmap(): Promise<void> {
unreachedColor = themeColors.subAlt;
}
const burstlistSorted = burstlist.sort((a, b) => a - b);
const burstlistLength = burstlist.length;
const steps = [
{
val: 0,
colorId: 0,
},
{
val: median - step * 1.5,
val: burstlistSorted[(burstlistLength * 0.15) | 0],
colorId: 1,
},
{
val: median - step * 0.5,
val: burstlistSorted[(burstlistLength * 0.35) | 0],
colorId: 2,
},
{
val: median + step * 0.5,
val: burstlistSorted[(burstlistLength * 0.65) | 0],
colorId: 3,
},
{
val: median + step * 1.5,
val: burstlistSorted[(burstlistLength * 0.85) | 0],
colorId: 4,
},
];
@ -1176,11 +1165,15 @@ export async function applyBurstHeatmap(): Promise<void> {
if (index === 0) {
string = `<${Math.round(steps[index + 1].val)}`;
} else if (index === 4) {
string = `${Math.round(step.val - 1)}+`;
string = `${Math.round(step.val)}+`;
} else {
string = `${Math.round(step.val)}-${
Math.round(steps[index + 1].val) - 1
}`;
if (step.val != steps[index + 1].val) {
string = `${Math.round(step.val)}-${
Math.round(steps[index + 1].val) - 1
}`;
} else {
string = `${Math.round(step.val)}-${Math.round(step.val)}`;
}
}
$("#resultWordsHistory .heatmapLegend .box" + index).html(