mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-18 03:26:07 +08:00
added start to first
This commit is contained in:
parent
5cfc79f578
commit
1a47ca9b00
3 changed files with 17 additions and 3 deletions
|
@ -55,6 +55,7 @@ const RESULT_SCHEMA = joi
|
|||
),
|
||||
keyOverlap: joi.number().min(0),
|
||||
lastKeyToEnd: joi.number().min(0),
|
||||
startToFirstKey: joi.number().min(0),
|
||||
lang: joi.string(),
|
||||
stringified: joi.string(),
|
||||
language: joi.string().required(),
|
||||
|
|
|
@ -62,6 +62,7 @@ interface Keypress {
|
|||
|
||||
interface KeypressTimings {
|
||||
spacing: {
|
||||
first: number;
|
||||
last: number;
|
||||
array: number[];
|
||||
};
|
||||
|
@ -216,6 +217,7 @@ export let accuracy = {
|
|||
};
|
||||
export let keypressTimings: KeypressTimings = {
|
||||
spacing: {
|
||||
first: -1,
|
||||
last: -1,
|
||||
array: [],
|
||||
},
|
||||
|
@ -329,8 +331,10 @@ export function recordKeydownTime(key: string): void {
|
|||
|
||||
if (keyDownData[key] !== undefined) return;
|
||||
|
||||
const now = performance.now();
|
||||
|
||||
keyDownData[key] = {
|
||||
timestamp: performance.now(),
|
||||
timestamp: now,
|
||||
index: keypressTimings.duration.array.length,
|
||||
};
|
||||
keypressTimings.duration.array.push(0);
|
||||
|
@ -338,7 +342,7 @@ export function recordKeydownTime(key: string): void {
|
|||
updateOverlap(keyDownData[key].timestamp);
|
||||
|
||||
if (keypressTimings.spacing.last !== -1) {
|
||||
const diff = Math.abs(performance.now() - keypressTimings.spacing.last);
|
||||
const diff = Math.abs(now - keypressTimings.spacing.last);
|
||||
keypressTimings.spacing.array.push(roundTo2(diff));
|
||||
if (spacingDebug) {
|
||||
console.log(
|
||||
|
@ -352,7 +356,10 @@ export function recordKeydownTime(key: string): void {
|
|||
);
|
||||
}
|
||||
}
|
||||
keypressTimings.spacing.last = performance.now();
|
||||
keypressTimings.spacing.last = now;
|
||||
if (keypressTimings.spacing.first === -1) {
|
||||
keypressTimings.spacing.first = now;
|
||||
}
|
||||
}
|
||||
|
||||
function updateOverlap(now: number): void {
|
||||
|
@ -372,6 +379,7 @@ function updateOverlap(now: number): void {
|
|||
export function resetKeypressTimings(): void {
|
||||
keypressTimings = {
|
||||
spacing: {
|
||||
first: -1,
|
||||
last: -1,
|
||||
array: [],
|
||||
},
|
||||
|
@ -432,6 +440,7 @@ export function restart(): void {
|
|||
};
|
||||
keypressTimings = {
|
||||
spacing: {
|
||||
first: -1,
|
||||
last: -1,
|
||||
array: [],
|
||||
},
|
||||
|
|
|
@ -1306,6 +1306,7 @@ interface CompletedEvent extends MonkeyTypes.Result<MonkeyTypes.Mode> {
|
|||
challenge?: string | null;
|
||||
keyOverlap: number;
|
||||
lastKeyToEnd: number;
|
||||
startToFirstKey: number;
|
||||
}
|
||||
|
||||
type PartialCompletedEvent = Omit<Partial<CompletedEvent>, "chartData"> & {
|
||||
|
@ -1382,6 +1383,9 @@ function buildCompletedEvent(difficultyFailed: boolean): CompletedEvent {
|
|||
lastKeyToEnd: Misc.roundTo2(
|
||||
TestStats.end - TestInput.keypressTimings.spacing.last
|
||||
),
|
||||
startToFirstKey: Misc.roundTo2(
|
||||
TestInput.keypressTimings.spacing.first - TestStats.start
|
||||
),
|
||||
consistency: undefined,
|
||||
keyConsistency: undefined,
|
||||
funbox: Config.funbox,
|
||||
|
|
Loading…
Add table
Reference in a new issue