Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion frontend/src/ts/test/test-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ function compareCompletedEvents(
difficulty: ce.difficulty,
duration: ce.testDuration,
funboxes: getActiveFunboxNames().join(","),
version: 18,
version: 19,
data: {
words: TestWords.words.list.join(" "),
events: getAllTestEvents(),
Expand Down Expand Up @@ -2028,6 +2028,7 @@ qs(".pageTest")?.onChild("click", "#restartTestButtonWithSameWordset", () => {
window.addEventListener("focus", () => {
if (
!TestState.isActive &&
!TestState.resultVisible &&
(Config.mode === "time" || Config.mode === "words")
) {
restart({
Expand All @@ -2041,6 +2042,7 @@ document.addEventListener("visibilitychange", () => {
if (document.visibilityState !== "visible") return;
if (
!TestState.isActive &&
!TestState.resultVisible &&
(Config.mode === "time" || Config.mode === "words")
) {
restart({
Expand Down
22 changes: 8 additions & 14 deletions frontend/src/ts/test/test-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export function removeAfkData(): void {
TestInput.rawHistory.splice(testSeconds);
}

function getInputWords(): string[] {
function getInputWords(isTimedTest: boolean): string[] {
const containsKorean = TestState.koreanStatus;

let inputWords = [...TestInput.input.getHistory()];
Expand All @@ -219,7 +219,7 @@ function getInputWords(): string[] {
inputWords = inputWords.map((w) => Hangul.disassemble(w).join(""));
}

for (let i = 0; i < inputWords.length - 1; i++) {
for (let i = 0; i < inputWords.length - (isTimedTest ? 0 : 1); i++) {
if (
getLastChar(inputWords[i] as string) !== "\n" &&
!isFunboxActiveWithProperty("nospace")
Expand All @@ -231,7 +231,7 @@ function getInputWords(): string[] {
return inputWords;
}

function getTargetWords(): string[] {
function getTargetWords(isTimedTest: boolean): string[] {
const containsKorean = TestState.koreanStatus;

let targetWords = [
Expand All @@ -252,7 +252,7 @@ function getTargetWords(): string[] {
targetWords = targetWords.map((w) => Hangul.disassemble(w).join(""));
}

for (let i = 0; i < targetWords.length - 1; i++) {
for (let i = 0; i < targetWords.length - (isTimedTest ? 0 : 1); i++) {
if (
getLastChar(targetWords[i] as string) !== "\n" &&
!isFunboxActiveWithProperty("nospace")
Expand All @@ -271,25 +271,19 @@ function countChars(final = false): CharCount {
let extraChars = 0;
let missedChars = 0;

const inputWords = getInputWords();
const targetWords = getTargetWords();

const isTimedTest =
Config.mode === "time" ||
(Config.mode === "words" && Config.words === 0) ||
(Config.mode === "custom" && CustomText.getLimit().mode === "time");

const inputWords = getInputWords(isTimedTest);
const targetWords = getTargetWords(isTimedTest);

for (let i = 0; i < inputWords.length; i++) {
const inputWord = inputWords[i] as string;
let targetWord = targetWords[i] as string;
const isLastInputWord = i === inputWords.length - 1;

// getTargetWords appends a delimiter to every word except the last in the
// generated list; for the last input word (active in timed/mid-test, or
// the actual last word) drop that delimiter so overshoot counts as extra
if (isLastInputWord && targetWord.endsWith(" ")) {
targetWord = targetWord.slice(0, -1);
}

const { correctWord, allCorrect, incorrect, missed, extra } =
countCharsUtils(
inputWord,
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/src/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const ReportCompletedEventMismatchRequestSchema = z.object({
difficulty: DifficultySchema.optional(),
duration: z.number().max(200).optional(),
funboxes: z.string().max(100).optional(),
version: z.literal(18),
version: z.literal(19),
data: z.object({
words: z.string().max(10000),
events: z.array(z.record(z.unknown())),
Expand Down
Loading