@@ -29,6 +29,13 @@ 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+ pushIncompleteTest ,
36+ resetIncompleteTests ,
37+ setIsTestInvalid ,
38+ setLastResult ,
3239 setResultVisible ,
3340 setWordsHaveNewline ,
3441 setWordsHaveTab ,
@@ -253,10 +260,8 @@ export function restart(options = {} as RestartOptions): void {
253260 const afkseconds = TestStats . calculateAfkSeconds ( testSeconds ) ;
254261 let tt = Numbers . roundTo2 ( testSeconds - afkseconds ) ;
255262 if ( tt < 0 ) tt = 0 ;
256- TestStats . incrementIncompleteSeconds ( tt ) ;
257- TestStats . incrementRestartCount ( ) ;
258263 const acc = Numbers . roundTo2 ( TestStats . calculateAccuracy ( ) ) ;
259- TestStats . pushIncompleteTest ( acc , tt ) ;
264+ pushIncompleteTest ( { acc, seconds : tt } ) ;
260265 }
261266 }
262267
@@ -297,6 +302,7 @@ export function restart(options = {} as RestartOptions): void {
297302 }
298303
299304 TestTimer . clear ( ) ;
305+ setIsTestInvalid ( false ) ;
300306 TestStats . restart ( ) ;
301307 TestInput . restart ( ) ;
302308 TestInput . corrected . reset ( ) ;
@@ -846,12 +852,10 @@ function buildCompletedEvent(
846852 lazyMode : Config . lazyMode ,
847853 timestamp : Date . now ( ) ,
848854 language : language ,
849- restartCount : TestStats . restartCount ,
850- incompleteTests : TestStats . incompleteTests ,
855+ restartCount : getRestartCount ( ) ,
856+ incompleteTests : getIncompleteTests ( ) ,
851857 incompleteTestSeconds :
852- TestStats . incompleteSeconds < 0
853- ? 0
854- : Numbers . roundTo2 ( TestStats . incompleteSeconds ) ,
858+ getIncompleteSeconds ( ) < 0 ? 0 : Numbers . roundTo2 ( getIncompleteSeconds ( ) ) ,
855859 difficulty : Config . difficulty ,
856860 blindMode : Config . blindMode ,
857861 tags : activeTagsIds ,
@@ -1013,7 +1017,7 @@ export async function finish(difficultyFailed = false): Promise<void> {
10131017
10141018 const completedEvent = structuredClone ( ce ) as CompletedEvent ;
10151019
1016- TestStats . setLastResult ( structuredClone ( completedEvent ) ) ;
1020+ setLastResult ( structuredClone ( completedEvent ) ) ;
10171021
10181022 ///////// completed event ready
10191023
@@ -1036,7 +1040,7 @@ export async function finish(difficultyFailed = false): Promise<void> {
10361040 ) {
10371041 showNoticeNotification ( "Test invalid - inconsistent test duration" ) ;
10381042 console . error ( "Test duration inconsistent" , ce . testDuration , dateDur ) ;
1039- TestStats . setInvalid ( ) ;
1043+ setIsTestInvalid ( true ) ;
10401044 dontSave = true ;
10411045 } else if ( difficultyFailed ) {
10421046 showNoticeNotification ( `Test failed - ${ failReason } ` , {
@@ -1063,16 +1067,16 @@ export async function finish(difficultyFailed = false): Promise<void> {
10631067 ( Config . mode === "zen" && completedEvent . testDuration < 15 )
10641068 ) {
10651069 showNoticeNotification ( "Test invalid - too short" ) ;
1066- TestStats . setInvalid ( ) ;
1070+ setIsTestInvalid ( true ) ;
10671071 tooShort = true ;
10681072 dontSave = true ;
10691073 } else if ( afkDetected ) {
10701074 showNoticeNotification ( "Test invalid - AFK detected" ) ;
1071- TestStats . setInvalid ( ) ;
1075+ setIsTestInvalid ( true ) ;
10721076 dontSave = true ;
10731077 } else if ( TestState . isRepeated ) {
10741078 showNoticeNotification ( "Test invalid - repeated" ) ;
1075- TestStats . setInvalid ( ) ;
1079+ setIsTestInvalid ( true ) ;
10761080 dontSave = true ;
10771081 } else if (
10781082 completedEvent . wpm < 0 ||
@@ -1084,7 +1088,7 @@ export async function finish(difficultyFailed = false): Promise<void> {
10841088 completedEvent . mode2 === "10" )
10851089 ) {
10861090 showNoticeNotification ( "Test invalid - wpm" ) ;
1087- TestStats . setInvalid ( ) ;
1091+ setIsTestInvalid ( true ) ;
10881092 dontSave = true ;
10891093 } else if (
10901094 completedEvent . rawWpm < 0 ||
@@ -1096,7 +1100,7 @@ export async function finish(difficultyFailed = false): Promise<void> {
10961100 completedEvent . mode2 === "10" )
10971101 ) {
10981102 showNoticeNotification ( "Test invalid - raw" ) ;
1099- TestStats . setInvalid ( ) ;
1103+ setIsTestInvalid ( true ) ;
11001104 dontSave = true ;
11011105 } else if (
11021106 ( ! DB . getSnapshot ( ) ?. lbOptOut &&
@@ -1105,7 +1109,7 @@ export async function finish(difficultyFailed = false): Promise<void> {
11051109 ( completedEvent . acc < 50 || completedEvent . acc > 100 ) )
11061110 ) {
11071111 showNoticeNotification ( "Test invalid - accuracy" ) ;
1108- TestStats . setInvalid ( ) ;
1112+ setIsTestInvalid ( true ) ;
11091113 dontSave = true ;
11101114 }
11111115
@@ -1118,9 +1122,7 @@ export async function finish(difficultyFailed = false): Promise<void> {
11181122 let tt = Numbers . roundTo2 ( testSeconds - afkseconds ) ;
11191123 if ( tt < 0 ) tt = 0 ;
11201124 const acc = completedEvent . acc ;
1121- TestStats . incrementIncompleteSeconds ( tt ) ;
1122- TestStats . incrementRestartCount ( ) ;
1123- TestStats . pushIncompleteTest ( acc , tt ) ;
1125+ pushIncompleteTest ( { acc, seconds : tt } ) ;
11241126 }
11251127 }
11261128
@@ -1180,7 +1182,7 @@ export async function finish(difficultyFailed = false): Promise<void> {
11801182 if ( dontSave ) {
11811183 void AnalyticsController . log ( "testCompletedInvalid" ) ;
11821184 } else {
1183- TestStats . resetIncomplete ( ) ;
1185+ resetIncompleteTests ( ) ;
11841186
11851187 if ( ! completedEvent . bailedOut ) {
11861188 const challenge = ChallengeContoller . verify ( completedEvent ) ;
0 commit comments