mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-11-06 11:01:00 +08:00
moved afk history into its own variable
This commit is contained in:
parent
b659a68d9b
commit
35a6b910aa
5 changed files with 21 additions and 11 deletions
|
|
@ -871,7 +871,7 @@ $(document).keydown(async (event) => {
|
|||
return;
|
||||
}
|
||||
|
||||
TestInput.setKeypressNotAfk();
|
||||
TestInput.setCurrentNotAfk();
|
||||
|
||||
//blocking firefox from going back in history with backspace
|
||||
if (event.key === "Backspace") {
|
||||
|
|
@ -1108,7 +1108,7 @@ $("#wordsInput").on("input", (event) => {
|
|||
const popupVisible = Misc.isAnyPopupVisible();
|
||||
if (popupVisible) return;
|
||||
|
||||
TestInput.setKeypressNotAfk();
|
||||
TestInput.setCurrentNotAfk();
|
||||
|
||||
if (
|
||||
(Config.layout === "default" || Config.layout === "korean") &&
|
||||
|
|
|
|||
|
|
@ -74,7 +74,6 @@ const keysToTrack = [
|
|||
|
||||
interface Keypress {
|
||||
count: number;
|
||||
afk: boolean;
|
||||
}
|
||||
|
||||
interface KeypressTimings {
|
||||
|
|
@ -224,7 +223,6 @@ export const corrected = new Corrected();
|
|||
export let keypressPerSecond: Keypress[] = [];
|
||||
let currentSecondKeypressData: Keypress = {
|
||||
count: 0,
|
||||
afk: true,
|
||||
};
|
||||
export let currentBurstStart = 0;
|
||||
export let missedWords: {
|
||||
|
|
@ -257,6 +255,9 @@ let currentErrorHistory: ErrorHistoryObject = {
|
|||
words: [],
|
||||
};
|
||||
|
||||
export let afkHistory: boolean[] = [];
|
||||
let currentAfk = true;
|
||||
|
||||
export let spacingDebug = false;
|
||||
export function enableSpacingDebug(): void {
|
||||
spacingDebug = true;
|
||||
|
|
@ -267,8 +268,8 @@ export function incrementKeypressCount(): void {
|
|||
currentSecondKeypressData.count++;
|
||||
}
|
||||
|
||||
export function setKeypressNotAfk(): void {
|
||||
currentSecondKeypressData.afk = false;
|
||||
export function setCurrentNotAfk(): void {
|
||||
currentAfk = false;
|
||||
}
|
||||
|
||||
export function incrementKeypressErrors(): void {
|
||||
|
|
@ -287,10 +288,14 @@ export function pushKeypressesToHistory(): void {
|
|||
keypressPerSecond.push(currentSecondKeypressData);
|
||||
currentSecondKeypressData = {
|
||||
count: 0,
|
||||
afk: true,
|
||||
};
|
||||
}
|
||||
|
||||
export function pushAfkToHistory(): void {
|
||||
afkHistory.push(currentAfk);
|
||||
currentAfk = true;
|
||||
}
|
||||
|
||||
export function pushErrorToHistory(): void {
|
||||
errorHistory.push(currentErrorHistory);
|
||||
currentErrorHistory = {
|
||||
|
|
@ -488,8 +493,9 @@ export function restart(): void {
|
|||
keypressPerSecond = [];
|
||||
currentSecondKeypressData = {
|
||||
count: 0,
|
||||
afk: true,
|
||||
};
|
||||
afkHistory = [];
|
||||
currentAfk = true;
|
||||
errorHistory = [];
|
||||
currentErrorHistory = {
|
||||
count: 0,
|
||||
|
|
|
|||
|
|
@ -196,6 +196,7 @@ export function restart(options = {} as RestartOptions): void {
|
|||
if (TestState.savingEnabled) {
|
||||
TestInput.pushKeypressesToHistory();
|
||||
TestInput.pushErrorToHistory();
|
||||
TestInput.pushAfkToHistory();
|
||||
const testSeconds = TestStats.calculateTestSeconds(performance.now());
|
||||
const afkseconds = TestStats.calculateAfkSeconds(testSeconds);
|
||||
let tt = Misc.roundTo2(testSeconds - afkseconds);
|
||||
|
|
@ -864,6 +865,7 @@ function buildCompletedEvent(difficultyFailed: boolean): CompletedEvent {
|
|||
TestInput.pushToRawHistory(wpmAndRaw.raw);
|
||||
TestInput.pushKeypressesToHistory();
|
||||
TestInput.pushErrorToHistory();
|
||||
TestInput.pushAfkToHistory();
|
||||
}
|
||||
|
||||
//consistency
|
||||
|
|
@ -1043,8 +1045,8 @@ export async function finish(difficultyFailed = false): Promise<void> {
|
|||
///////// completed event ready
|
||||
|
||||
//afk check
|
||||
const kps = TestInput.keypressPerSecond.slice(-5);
|
||||
let afkDetected = kps.every((second) => second.afk);
|
||||
const kps = TestInput.afkHistory.slice(-5);
|
||||
let afkDetected = kps.every((afk) => afk === true);
|
||||
if (TestState.bailedOut) afkDetected = false;
|
||||
|
||||
const mode2Number = parseInt(completedEvent.mode2);
|
||||
|
|
@ -1402,6 +1404,7 @@ export function fail(reason: string): void {
|
|||
// corrected.pushHistory();
|
||||
TestInput.pushKeypressesToHistory();
|
||||
TestInput.pushErrorToHistory();
|
||||
TestInput.pushAfkToHistory();
|
||||
finish(true);
|
||||
if (!TestState.savingEnabled) return;
|
||||
const testSeconds = TestStats.calculateTestSeconds(performance.now());
|
||||
|
|
|
|||
|
|
@ -260,7 +260,7 @@ export function calculateAfkSeconds(testSeconds: number): number {
|
|||
// `gonna add extra ${extraAfk} seconds of afk because of no keypress data`
|
||||
// );
|
||||
}
|
||||
const ret = TestInput.keypressPerSecond.filter((x) => x.afk).length;
|
||||
const ret = TestInput.afkHistory.filter((afk) => afk === true).length;
|
||||
return ret + extraAfk;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -126,6 +126,7 @@ function checkIfFailed(
|
|||
if (timerDebug) console.time("fail conditions");
|
||||
TestInput.pushKeypressesToHistory();
|
||||
TestInput.pushErrorToHistory();
|
||||
TestInput.pushAfkToHistory();
|
||||
if (
|
||||
Config.minWpm === "custom" &&
|
||||
wpmAndRaw.wpm < Config.minWpmCustomSpeed &&
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue