MCPcopy
hub / github.com/monkeytypegame/monkeytype / getStartToFirstKeypressMs

Function getStartToFirstKeypressMs

frontend/src/ts/test/events/stats.ts:141–173  ·  view source on GitHub ↗
(eventLog: EventLog)

Source from the content-addressed store, hash-verified

139}
140
141export function getStartToFirstKeypressMs(eventLog: EventLog): number {
142 if (eventLog.context.mode === "zen") return 0;
143
144 const { events } = eventLog;
145
146 let firstKeypress: number | undefined;
147 let start: number | undefined;
148
149 for (const event of events) {
150 if (firstKeypress !== undefined && start !== undefined) {
151 break;
152 }
153
154 if (firstKeypress === undefined && event.type === "keydown") {
155 firstKeypress = event.testMs;
156 }
157
158 if (
159 start === undefined &&
160 event.type === "timer" &&
161 event.data.event === "start"
162 ) {
163 start = event.testMs;
164 }
165 }
166
167 if (firstKeypress === undefined || start === undefined) {
168 return 0;
169 }
170
171 const calc = firstKeypress - start;
172 return calc < 0 ? 0 : roundTo2(calc);
173}
174
175// raw version is needed internally by getTestDurationMs to adjust
176// duration in zen/bailout — the public version returns 0 for zen

Callers 2

buildCompletedEventFunction · 0.90
stats.spec.tsFile · 0.90

Calls 1

roundTo2Function · 0.90

Tested by

no test coverage detected