Skip to content

Commit

Permalink
impr(result): rework burst heatmap speed brackets (keenemeck) (#4741)
Browse files Browse the repository at this point in the history
  • Loading branch information
keenemeck committed Oct 27, 2023
1 parent 8942ee2 commit a30b367
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions frontend/src/ts/test/test-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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,
},
];
Expand All @@ -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(
Expand Down

0 comments on commit a30b367

Please sign in to comment.