-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfinger_analysis.js
121 lines (103 loc) · 3.66 KB
/
finger_analysis.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// l and r stand for left and right; L and S for Lowercase and Shifted
var hands = {
lL: ["qaz", "123wsx", "4ed", "56rtfgcv", " "],
lS: ["QAZ", "!@#WSX", "$ED", "%^RTFGCV", ""],
rL: [";'/", "pol0.", "9ik", "78yuhjnmb", ""],
rS: [":\"", "POL)>", "(IK", "&*YUHJNMB", ""]
}
var letters = {}
for (var c = 32; c < 128; c++) {
for (var hand in hands) {
for (var finger = 0; finger < 5; finger++) {
if (hands[hand][finger].indexOf(String.fromCharCode(c)) >= 0) {
letters[c] = hand+finger
}
}
}
}
var handfingers = []
for (var hand in hands) {
for (var finger = 0; finger < 5; finger++) {
handfingers.push(hand+finger);
}
}
// Returns a pair of
// + Are the strokes from the same hand
// + Are the strokes from the same finger
function classify_transition(hf1, hf2) {
// Ignoring shifting/unshifting for now
return [hf1.charAt(0) == hf2.charAt(0),
hf1.charAt(2) == hf2.charAt(2)]
}
function finger_analyze(data) {
var timediffs = {}
for (var i in handfingers) {
hf = handfingers[i];
timediffs[hf] = {}
for (var j in handfingers) {
hf2 = handfingers[j];
timediffs[hf][hf2] = [0, 0];
}
}
for (var i in data) {
var distroke = idx_to_digraph(i);
var finger_from = letters[distroke.charCodeAt(0)];
var finger_to = letters[distroke.charCodeAt(1)];
if (!finger_from || !finger_to) continue;
var arr = timediffs[finger_from][finger_to]
arr[0] += data[i][0];
arr[1] += data[i][1];
}
var analysis = {
ss: [0, 0], sd: [0, 0], ds: [0, 0], dd: [0, 0]
}
for (var hf in timediffs) {
for (var hf2 in timediffs) {
var type = classify_transition(hf, hf2);
var bucket = (type[0] ? "s" : "d") + (type[1] ? "s" : "d");
var vals = analysis[bucket];
vals[0] += timediffs[hf][hf2][0];
vals[1] += timediffs[hf][hf2][1];
}
}
return analysis;
}
function finger_analysis(data) {
var sec = document.getElementById("finger_analysis");
var res = finger_analyze(data);
var d = (res.dd[0] + res.ds[0]) / (res.dd[1] + res.ds[1]);
var sd = res.sd[0] / res.sd[1];
var ss = res.ss[0] / res.ss[1];
var avg = (res.dd[0] + res.ds[0] + res.ss[0] + res.sd[0]) / (res.dd[1] + res.ds[1] + res.ss[1] + res.sd[1]);
sec.getElementsByClassName("d")[0].innerHTML = Math.round(1000*d) + " ms";
sec.getElementsByClassName("sd")[0].innerHTML = Math.round(1000*sd) + " ms";
sec.getElementsByClassName("ss")[0].innerHTML = Math.round(1000*ss) + " ms";
sec.getElementsByClassName("avg")[0].innerHTML = Math.round(1000*avg) + " ms";
var same_position = [0, 0];
for (c = 0; c < 96; c++) {
// 97 * c = 96 * c + c
if (data[97*c]) {
same_position[0] += data[97*c][0];
same_position[1] += data[97*c][1];
}
}
var sp = same_position[0] / same_position[1];
sec.getElementsByClassName("sp")[0].innerHTML = Math.round(1000*sp) + " ms";
var fastest_transition = 10000;
var fastest_idx;
var slowest_transition = 0;
var slowest_idx;
for (var i in data) {
var avg = data[i][0] / data[i][1];
if (avg < fastest_transition) {
fastest_transition = avg;
fastest_idx = i;
}
if (avg > slowest_transition) {
slowest_transition = avg;
slowest_idx = i;
}
}
sec.getElementsByClassName("slowest")[0].innerHTML = idx_to_digraph(slowest_idx);
sec.getElementsByClassName("fastest")[0].innerHTML = idx_to_digraph(fastest_idx);
}