Skip to content

Commit ace96b3

Browse files
Leonabcd123Miodec
andauthored
impr(burst-history): Use end time when calculating burst if test ended (@Leonabcd123) (#7302)
### Description Use the time when test ended to calculate burst instead of current time, so that burst history matches more closely actual wpm . Example bug fixed: When typing a single letter, wpm will be infinity but burst history will be ~90. --------- Co-authored-by: Jack <[email protected]>
1 parent d2c9379 commit ace96b3

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

frontend/src/ts/test/test-logic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ export async function finish(difficultyFailed = false): Promise<void> {
904904

905905
//need one more calculation for the last word if test auto ended
906906
if (TestInput.burstHistory.length !== TestInput.input.getHistory()?.length) {
907-
const burst = TestStats.calculateBurst();
907+
const burst = TestStats.calculateBurst(now);
908908
TestInput.pushBurstToHistory(burst);
909909
}
910910

frontend/src/ts/test/test-stats.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ export function setLastSecondNotRound(): void {
217217
lastSecondNotRound = true;
218218
}
219219

220-
export function calculateBurst(): number {
220+
export function calculateBurst(endTime: number = performance.now()): number {
221221
const containsKorean = TestInput.input.getKoreanStatus();
222-
const timeToWrite = (performance.now() - TestInput.currentBurstStart) / 1000;
222+
const timeToWrite = (endTime - TestInput.currentBurstStart) / 1000;
223223
let wordLength: number;
224224
wordLength = !containsKorean
225225
? TestInput.input.current.length

frontend/src/ts/test/test-ui.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,8 +1436,7 @@ export async function applyBurstHeatmap(): Promise<void> {
14361436

14371437
let burstlist = [...TestInput.burstHistory];
14381438

1439-
burstlist = burstlist.filter((x) => x !== Infinity);
1440-
burstlist = burstlist.filter((x) => x < 500);
1439+
burstlist = burstlist.map((x) => (x >= 1000 ? Infinity : x));
14411440

14421441
const typingSpeedUnit = getTypingSpeedUnit(Config.typingSpeedUnit);
14431442
burstlist.forEach((burst, index) => {
@@ -1508,7 +1507,7 @@ export async function applyBurstHeatmap(): Promise<void> {
15081507
}
15091508

15101509
$("#resultWordsHistory .heatmapLegend .box" + index).html(
1511-
`<div>${string}</div>`,
1510+
`<div>${Misc.escapeHTML(string)}</div>`,
15121511
);
15131512
});
15141513

@@ -1977,7 +1976,7 @@ $(".pageTest #resultWordsHistory").on("mouseenter", ".words .word", (e) => {
19771976
.replace(/>/g, "&gt")}
19781977
</div>
19791978
<div class="speed">
1980-
${Format.typingSpeed(burst, { showDecimalPlaces: false })}
1979+
${isNaN(burst) || burst >= 1000 ? "Infinite" : Format.typingSpeed(burst, { showDecimalPlaces: false })}
19811980
${Config.typingSpeedUnit}
19821981
</div>
19831982
</div>`,

0 commit comments

Comments
 (0)