@@ -5,15 +5,9 @@ data.consecutive = 5;
5
5
data . word_length = 7 ;
6
6
data . current_layout = "qwerty" ;
7
7
8
- var hits_correct = 0 ;
9
- var hits_wrong = 0 ;
10
- var start_time = 0 ;
11
- /* not sure what it means */
12
- var hpm = 0 ;
13
- /* not sure what ratio refers to */
14
- var ratio = 0 ;
15
8
16
9
10
+ /* cos'è un layout, sembra una stringa e basta, ma non mi è chiara l associazione con la ui, è l'ordine con cui devo padroneggiare le lettere? */
17
11
var layouts = { } ;
18
12
layouts [ "qwerty" ] = " jfkdlsahgyturieowpqbnvmcxz6758493021`-=[]\\;',./ABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$%^&*()_+{}|:\"<>?" ;
19
13
layouts [ "azerty" ] = " jfkdlsmqhgyturieozpabnvcxw6758493021`-=[]\\;',./ABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$%^&*()_+{}|:\"<>?" ;
@@ -33,21 +27,37 @@ $(document).ready(function() {
33
27
} ) ;
34
28
35
29
/* TODO */
30
+ var start_time = 0 ;
31
+ /* - viene chiamata in keyHandler, on keypress
32
+ - div.stats
33
+ */
36
34
function start_stats ( ) {
35
+ /*
36
+ quando start_time è 0, assegna il tempo in sec
37
+ quando start_time è > 0, assegna
38
+ */
37
39
start_time = start_time || Math . floor ( new Date ( ) . getTime ( ) / 1000 ) ;
38
40
}
39
41
42
+ /* TODO */
43
+ var hpm = 0 ; /* hits per minute */
44
+ var ratio = 0 ;
45
+ var hits_correct = 0 ;
46
+ var hits_wrong = 0 ;
40
47
function update_stats ( ) {
41
- if ( start_time ) {
42
- var current_time = ( Math . floor ( new Date ( ) . getTime ( ) / 1000 ) ) ;
43
- ratio = Math . floor (
44
- hits_correct / ( hits_correct + hits_wrong ) * 100
45
- ) ;
46
- hpm = Math . floor (
47
- ( hits_correct + hits_wrong ) / ( current_time - start_time ) * 60
48
- ) ;
49
- if ( ! isFinite ( hpm ) ) { hpm = 0 ; }
48
+ if ( start_time ) {
49
+ var current_time = ( Math . floor ( new Date ( ) . getTime ( ) / 1000 ) ) ;
50
+ /* better than "ration": correct hits %, see also render_stats(), the author knows it! */
51
+ ratio = Math . floor ( hits_correct / ( hits_correct + hits_wrong ) * 100 ) ;
52
+ /* total hits per minute */
53
+ hpm = Math . floor ( ( hits_correct + hits_wrong ) / ( current_time - start_time ) * 60 ) ;
54
+ /*
55
+ built-in function that "returns false if the argument is positive or negative Infinity or NaN or undefined; otherwise, true."
56
+ */
57
+ if ( ! isFinite ( hpm ) ) {
58
+ hpm = 0 ;
50
59
}
60
+ }
51
61
}
52
62
53
63
function set_level ( l ) {
0 commit comments