Skip to content

Commit d342f40

Browse files
committed
Made sense of start_stats() and update_stats()
1 parent 6b72145 commit d342f40

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

keyzen.js

+26-16
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,9 @@ data.consecutive = 5;
55
data.word_length = 7;
66
data.current_layout = "qwerty";
77

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;
158

169

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? */
1711
var layouts = {};
1812
layouts["qwerty"] = " jfkdlsahgyturieowpqbnvmcxz6758493021`-=[]\\;',./ABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$%^&*()_+{}|:\"<>?";
1913
layouts["azerty"] = " jfkdlsmqhgyturieozpabnvcxw6758493021`-=[]\\;',./ABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$%^&*()_+{}|:\"<>?";
@@ -33,21 +27,37 @@ $(document).ready(function() {
3327
});
3428

3529
/* TODO */
30+
var start_time = 0;
31+
/* - viene chiamata in keyHandler, on keypress
32+
- div.stats
33+
*/
3634
function start_stats() {
35+
/*
36+
quando start_time è 0, assegna il tempo in sec
37+
quando start_time è > 0, assegna
38+
*/
3739
start_time = start_time || Math.floor(new Date().getTime() / 1000);
3840
}
3941

42+
/* TODO */
43+
var hpm = 0; /* hits per minute */
44+
var ratio = 0;
45+
var hits_correct = 0;
46+
var hits_wrong = 0;
4047
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;
5059
}
60+
}
5161
}
5262

5363
function set_level(l) {

style.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
-khtml-user-select: none;
1616
-moz-user-select: none;
1717
-ms-user-select: none;
18-
user-select: none;
18+
user-select: none;
1919
}
2020

2121
#container {

0 commit comments

Comments
 (0)