@@ -52,7 +52,7 @@ const codemirror = () => import(/* webpackChunkName: "cmLoader" */ '@/cmLoader.j
5252 return module .default ;
5353});
5454
55- const DEV = process .env .NODE_ENV !== ' production' ;
55+ const DEV = process .env .NODE_ENV === ' production' ; // dev
5656
5757
5858export default {
@@ -69,6 +69,7 @@ export default {
6969 cm: {},
7070 codeText: ' ' ,
7171 started: false ,
72+ pauseTime: 0 ,
7273 isCompleted: false ,
7374 cmReady: false ,
7475 toFix: 0 ,
@@ -82,6 +83,7 @@ export default {
8283 currentChange: {},
8384 stats: {
8485 history: [],
86+ wpmOverTime: [],
8587 firstCharTime: 0 ,
8688 },
8789 };
@@ -147,9 +149,6 @@ export default {
147149 this .cm .focus ();
148150 }
149151
150- if (this .popUpText === ' resume' ) {
151- this .$emit (' pause' , action);
152- }
153152 this .showPopUp = action;
154153 },
155154 onCmReady (cm ) {
@@ -176,27 +175,6 @@ export default {
176175 text: ' Enter' ,
177176 };
178177
179- if (! this .stats .oneThirdTime && this .currentLine === Math .floor (this .codeInfo .lines / 3 )) {
180- console .log (' one third' );
181- const oneThirdText = this .cm .getRange (
182- { line: 0 , ch: 0 },
183- { line: this .currentLine , ch: 0 },
184- );
185-
186- this .stats .oneThirdCharsCount = oneThirdText .length ;
187- this .stats .oneThirdTime = this .timeElapsed ();
188- } else if (! this .stats .lastThirdStartTime && this .currentLine === Math .floor (this .codeInfo .lines / 3 * 2 )) {
189- console .log (' last third' );
190-
191- const lastThirdText = this .cm .getRange (
192- { line: this .currentLine , ch: 0 },
193- { line: this .codeInfo .lines + 1 , ch: 0 },
194- );
195-
196- this .stats .lastThirdCharsCount = lastThirdText .length ;
197- this .stats .lastThirdStartTime = this .timeElapsed ();
198- }
199-
200178 if (this .currentLine + 1 === this .codeInfo .lines && this .cm .getLine (this .currentLine ).trim ().length === 0 ) {
201179 console .red (' Last line is empty' );
202180 this .stats .history .push (this .currentChange );
@@ -508,6 +486,12 @@ export default {
508486 },
509487 onFocus () {
510488 console .log (' cmFocus' );
489+ if (this .pauseStart ) {
490+ this .$emit (' pause' , false );
491+ this .pauseTime += Date .now () - this .pauseStart ;
492+ this .pauseStart = null ;
493+ }
494+
511495 console .log (this .liveWpmInterval );
512496 if (this .liveWpmInterval === null ) {
513497 this .liveWpmInterval = setInterval (this .updateLiveWpm , this .options .liveWpmRefreshRate );
@@ -518,6 +502,7 @@ export default {
518502 if (DEV ) ev .preventDefault ();
519503 clearInterval (this .liveWpmInterval );
520504 this .liveWpmInterval = null ;
505+ this .pauseStart = Date .now ();
521506 if (! this .isCompleted && this .popUpText !== ' Try again' && ev) {
522507 if (DEV ) this .cm .focus ();
523508 if (ev .relatedTarget !== null ) {
@@ -529,6 +514,8 @@ export default {
529514 } else {
530515 // eslint-disable-next-line no-lonely-if
531516 if (! DEV ) this .popUp (true , ' Resume' );
517+
518+ this .$emit (' pause' , true );
532519 }
533520 }
534521 }
@@ -555,15 +542,18 @@ export default {
555542 }
556543 },
557544 timeElapsed () {
558- return Date .now () - this .stats .firstCharTime ;
545+ return Date .now () - this .stats .firstCharTime - this . pauseTime ;
559546 },
560547 updateLiveWpm () {
561- console .log (' correct: ' , this .freshCorrect );
562- const currentWpm = this .freshCorrect / (this .options .liveWpmRefreshRate / 1000 / 60 ) / 5 ;
563- console .blue (` wpm: ${ currentWpm} ` );
564- this .$emit (' liveWpmUpdate' , currentWpm || 0 );
565-
566- this .freshCorrect = 0 ;
548+ if (this .stats .firstCharTime ) {
549+ console .log (' correct: ' , this .freshCorrect );
550+ const currentWpm = (this .freshCorrect / (this .options .liveWpmRefreshRate / 1000 / 60 ) / 5 ) || 0 ;
551+ console .blue (` wpm: ${ currentWpm} ` );
552+ this .$emit (' liveWpmUpdate' , currentWpm);
553+
554+ this .stats .wpmOverTime .push ([this .timeElapsed (), Math .round (currentWpm)]);
555+ this .freshCorrect = 0 ;
556+ }
567557 },
568558 start (interval ) {
569559 clearInterval (interval);
@@ -652,7 +642,7 @@ export default {
652642 } else {
653643 this .stats = {
654644 ... this .stats ,
655- timeFromFirstInput : this .timeElapsed (),
645+ time : this .timeElapsed (),
656646 correctLines: this .currentLine + 1 ,
657647 codeInfo: {
658648 ... this .codeInfo ,
0 commit comments