@@ -29,6 +29,17 @@ import { clearQuoteStats } from "../states/quote-rate";
2929import * as Result from "./result" ;
3030import { getActivePage , isAuthenticated } from "../states/core" ;
3131import {
32+ getIncompleteSeconds ,
33+ getIncompleteTests ,
34+ getRestartCount ,
35+ incrementIncompleteSeconds ,
36+ incrementRestartCount ,
37+ pushIncompleteTest ,
38+ resetIncompleteSeconds ,
39+ resetIncompleteTests ,
40+ resetRestartCount ,
41+ setIsTestInvalid ,
42+ setLastResult ,
3243 setResultVisible ,
3344 setWordsHaveNewline ,
3445 setWordsHaveTab ,
@@ -253,10 +264,10 @@ export function restart(options = {} as RestartOptions): void {
253264 const afkseconds = TestStats . calculateAfkSeconds ( testSeconds ) ;
254265 let tt = Numbers . roundTo2 ( testSeconds - afkseconds ) ;
255266 if ( tt < 0 ) tt = 0 ;
256- TestStats . incrementIncompleteSeconds ( tt ) ;
257- TestStats . incrementRestartCount ( ) ;
267+ incrementIncompleteSeconds ( tt ) ;
268+ incrementRestartCount ( ) ;
258269 const acc = Numbers . roundTo2 ( TestStats . calculateAccuracy ( ) ) ;
259- TestStats . pushIncompleteTest ( acc , tt ) ;
270+ pushIncompleteTest ( { acc, seconds : tt } ) ;
260271 }
261272 }
262273
@@ -297,6 +308,7 @@ export function restart(options = {} as RestartOptions): void {
297308 }
298309
299310 TestTimer . clear ( ) ;
311+ setIsTestInvalid ( false ) ;
300312 TestStats . restart ( ) ;
301313 TestInput . restart ( ) ;
302314 TestInput . corrected . reset ( ) ;
@@ -846,12 +858,10 @@ function buildCompletedEvent(
846858 lazyMode : Config . lazyMode ,
847859 timestamp : Date . now ( ) ,
848860 language : language ,
849- restartCount : TestStats . restartCount ,
850- incompleteTests : TestStats . incompleteTests ,
861+ restartCount : getRestartCount ( ) ,
862+ incompleteTests : getIncompleteTests ( ) ,
851863 incompleteTestSeconds :
852- TestStats . incompleteSeconds < 0
853- ? 0
854- : Numbers . roundTo2 ( TestStats . incompleteSeconds ) ,
864+ getIncompleteSeconds ( ) < 0 ? 0 : Numbers . roundTo2 ( getIncompleteSeconds ( ) ) ,
855865 difficulty : Config . difficulty ,
856866 blindMode : Config . blindMode ,
857867 tags : activeTagsIds ,
@@ -1013,7 +1023,7 @@ export async function finish(difficultyFailed = false): Promise<void> {
10131023
10141024 const completedEvent = structuredClone ( ce ) as CompletedEvent ;
10151025
1016- TestStats . setLastResult ( structuredClone ( completedEvent ) ) ;
1026+ setLastResult ( structuredClone ( completedEvent ) ) ;
10171027
10181028 ///////// completed event ready
10191029
@@ -1036,7 +1046,7 @@ export async function finish(difficultyFailed = false): Promise<void> {
10361046 ) {
10371047 showNoticeNotification ( "Test invalid - inconsistent test duration" ) ;
10381048 console . error ( "Test duration inconsistent" , ce . testDuration , dateDur ) ;
1039- TestStats . setInvalid ( ) ;
1049+ setIsTestInvalid ( true ) ;
10401050 dontSave = true ;
10411051 } else if ( difficultyFailed ) {
10421052 showNoticeNotification ( `Test failed - ${ failReason } ` , {
@@ -1063,16 +1073,16 @@ export async function finish(difficultyFailed = false): Promise<void> {
10631073 ( Config . mode === "zen" && completedEvent . testDuration < 15 )
10641074 ) {
10651075 showNoticeNotification ( "Test invalid - too short" ) ;
1066- TestStats . setInvalid ( ) ;
1076+ setIsTestInvalid ( true ) ;
10671077 tooShort = true ;
10681078 dontSave = true ;
10691079 } else if ( afkDetected ) {
10701080 showNoticeNotification ( "Test invalid - AFK detected" ) ;
1071- TestStats . setInvalid ( ) ;
1081+ setIsTestInvalid ( true ) ;
10721082 dontSave = true ;
10731083 } else if ( TestState . isRepeated ) {
10741084 showNoticeNotification ( "Test invalid - repeated" ) ;
1075- TestStats . setInvalid ( ) ;
1085+ setIsTestInvalid ( true ) ;
10761086 dontSave = true ;
10771087 } else if (
10781088 completedEvent . wpm < 0 ||
@@ -1084,7 +1094,7 @@ export async function finish(difficultyFailed = false): Promise<void> {
10841094 completedEvent . mode2 === "10" )
10851095 ) {
10861096 showNoticeNotification ( "Test invalid - wpm" ) ;
1087- TestStats . setInvalid ( ) ;
1097+ setIsTestInvalid ( true ) ;
10881098 dontSave = true ;
10891099 } else if (
10901100 completedEvent . rawWpm < 0 ||
@@ -1096,7 +1106,7 @@ export async function finish(difficultyFailed = false): Promise<void> {
10961106 completedEvent . mode2 === "10" )
10971107 ) {
10981108 showNoticeNotification ( "Test invalid - raw" ) ;
1099- TestStats . setInvalid ( ) ;
1109+ setIsTestInvalid ( true ) ;
11001110 dontSave = true ;
11011111 } else if (
11021112 ( ! DB . getSnapshot ( ) ?. lbOptOut &&
@@ -1105,7 +1115,7 @@ export async function finish(difficultyFailed = false): Promise<void> {
11051115 ( completedEvent . acc < 50 || completedEvent . acc > 100 ) )
11061116 ) {
11071117 showNoticeNotification ( "Test invalid - accuracy" ) ;
1108- TestStats . setInvalid ( ) ;
1118+ setIsTestInvalid ( true ) ;
11091119 dontSave = true ;
11101120 }
11111121
@@ -1118,9 +1128,9 @@ export async function finish(difficultyFailed = false): Promise<void> {
11181128 let tt = Numbers . roundTo2 ( testSeconds - afkseconds ) ;
11191129 if ( tt < 0 ) tt = 0 ;
11201130 const acc = completedEvent . acc ;
1121- TestStats . incrementIncompleteSeconds ( tt ) ;
1122- TestStats . incrementRestartCount ( ) ;
1123- TestStats . pushIncompleteTest ( acc , tt ) ;
1131+ incrementIncompleteSeconds ( tt ) ;
1132+ incrementRestartCount ( ) ;
1133+ pushIncompleteTest ( { acc, seconds : tt } ) ;
11241134 }
11251135 }
11261136
@@ -1180,7 +1190,9 @@ export async function finish(difficultyFailed = false): Promise<void> {
11801190 if ( dontSave ) {
11811191 void AnalyticsController . log ( "testCompletedInvalid" ) ;
11821192 } else {
1183- TestStats . resetIncomplete ( ) ;
1193+ resetIncompleteTests ( ) ;
1194+ resetRestartCount ( ) ;
1195+ resetIncompleteSeconds ( ) ;
11841196
11851197 if ( ! completedEvent . bailedOut ) {
11861198 const challenge = ChallengeContoller . verify ( completedEvent ) ;
0 commit comments