-
Notifications
You must be signed in to change notification settings - Fork 9
/
recorder-diagnostic.html
404 lines (361 loc) · 11.4 KB
/
recorder-diagnostic.html
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
<!doctype html>
<meta charset="utf-8">
<h1>Gesture Diagnostics <small id="gesture-url"></small></h1>
<canvas id="line" width=200 height=1300 style="position:absolute;"></canvas>
<div class="left finger">
<canvas id="planar" width=200 height=140></canvas>
<h4>Planar Pointables</h4>
</div>
<div class="left hand">
<canvas id="handable" width=200 height=140></canvas>
<h4>Planar Hands</h4>
</div>
<div class="left finger">
<canvas id="profile" width=200 height=140></canvas>
<h4>Profile Pointables</h4>
</div>
<div class="left finger">
<canvas id="pointable-lengths" width=200 height=140></canvas>
<h4>Pointable Lengths</h4>
</div>
<div style="clear:both;"></div>
<div class="finger">
<canvas id="pointables" width=200 height=60></canvas>
<h4>Number of Pointables</h4>
</div>
<div class="finger">
<canvas id="pointables-by-id" width=200 height=60></canvas>
<h4>Number of Pointables By Id <small>Uniques: <strong id="pointable-uniques"></strong></small></h4>
</div>
<div class="fill">
<canvas id="velocities" width=200 height=60></canvas>
<h4>Average Pointable Velocity</h4>
</div>
<div class="fill">
<canvas id="velocity-x" width=200 height=60></canvas><br/>
<h4>x Pointable Velocity Components, Averaged</h4>
<canvas id="velocity-y" width=200 height=60></canvas><br/>
<h4>y Pointable Velocity Components, Averaged</h4>
<canvas id="velocity-z" width=200 height=60></canvas><br/>
<h4>z Pointable Velocity Components, Averaged</h4>
</div>
<div class="hand">
<canvas id="hands" width=200 height=60></canvas>
<h4>Number of Hands</h4>
</div>
<div class="fill">
<canvas id="deltas" width=200 height=50></canvas>
<h4>Time Between Frames
<small>
Min: <strong id="delta-min"></strong> ms -
Max: <strong id="delta-max"></strong> ms -
Ave: <strong id="delta-ave"></strong> ms -
Total: <strong id="delta-total"></strong> ms -
Frames: <strong id="frames-total"></strong>
</small></h4>
</div>
<script src="js/lib/d3.v3.js"></script>
<script src="js/lib/underscore.js"></script>
<script>
var gestureUrl = "data/gestures/frolic-2.json";
var fillColor = "#37A0CF";
var fingerColor = "#FDAE61";
var handColor = "#FFFFBF";
var faintColor = "rgba(150,150,150,0.5)";
var darkColor = "rgba(18,18,18,0.5)";
d3.json(gestureUrl, function(error, data) {
if (error) {
alert(error.statusText);
return
}
d3.select("#gesture-url").text(gestureUrl);
window.data = data;
fleas(data);
between(data);
pointables(data);
pointablesById(data);
velocities(data);
velocityComponents(data);
hands(data);
});
/* Animated 2d visualization */
function fleas(data) {
var last = data.length-1;
var i = 0;
var duration = (data[last].timestamp - data[0].timestamp)/1000;
var step = duration/data.length;
var canvasPlanar = document.getElementById("planar");
var ctxPlanar = canvasPlanar.getContext("2d");
var canvasProfile = document.getElementById("profile");
var ctxProfile = canvasProfile.getContext("2d");
var canvasHands = document.getElementById("handable");
var ctxHands = canvasHands.getContext("2d");
var canvasLengths = document.getElementById("pointable-lengths");
var ctxLengths= canvasLengths.getContext("2d");
var x = d3.scale.linear().range([0,canvasPlanar.width]).domain([-200,200]);
var y = d3.scale.linear().range([canvasPlanar.height,0]).domain([0,400]);
var xProfile = d3.scale.linear().range([0,canvasProfile.width]).domain([-200,200]);
var yProfile = d3.scale.linear().range([canvasProfile.height,0]).domain([0,400]);
function renderPointablesPlanar(obj) {
ctxPlanar.fillStyle = "rgba(0,0,0,0.4)";
ctxPlanar.fillRect(0,0,canvasPlanar.width,canvasPlanar.height);
ctxPlanar.fillStyle = fingerColor;
if ("pointables" in obj) {
obj.pointables.forEach(function(p) {
var pos = p.tipPosition;
ctxPlanar.fillRect(x(pos[0]), y(pos[1]), 4, 4);
});
}
};
function renderPointablesProfile(obj) {
ctxProfile.fillStyle = "rgba(0,0,0,0.4)";
ctxProfile.fillRect(0,0,canvasProfile.width,canvasProfile.height);
ctxProfile.fillStyle = fingerColor;
if ("pointables" in obj) {
obj.pointables.forEach(function(p) {
var pos = p.tipPosition;
ctxProfile.fillRect(x(pos[2]), y(pos[1]), 4, 4);
});
}
};
function renderHandables(obj) {
ctxHands.fillStyle = "rgba(0,0,0,0.4)";
ctxHands.fillRect(0,0,canvasHands.width,canvasHands.height);
ctxHands.fillStyle = handColor;
if ("hands" in obj) {
obj.hands.forEach(function(p) {
var pos = p.palmPosition;
ctxHands.fillRect(x(pos[0]), y(pos[1]), 12, 12);
});
}
};
function renderLengths(obj) {
ctxLengths.fillStyle = "rgba(0,0,0,0.4)";
ctxLengths.fillRect(0,0,canvasLengths.width,canvasLengths.height);
ctxLengths.fillStyle = fingerColor;
if ("pointables" in obj) {
obj.pointables.forEach(function(p,i) {
ctxLengths.fillRect(4+p.id*6,canvasLengths.height,5,-canvasLengths.height*p.length/120);
});
}
};
// line moving across the screen
var canvas2 = document.getElementById("line");
canvas2.width = data.length;
var ctx2 = canvas2.getContext("2d");
ctx2.fillStyle = "rgba(215,65,68,0.6)";
function run() {
renderPointablesPlanar(data[i]);
renderPointablesProfile(data[i]);
renderHandables(data[i]);
renderLengths(data[i]);
ctx2.clearRect(0,0,canvas2.width,canvas2.height);
ctx2.fillRect(i-1,190,2,1200);
i++;
if (i == last) i = 0;
setTimeout(run, step);
};
run();
};
/* see time between frames */
function between(data) {
var deltas = data.slice(1).map(function(d,i) {
return d.timestamp - data[i].timestamp;
});
var canvas = document.getElementById("deltas");
canvas.width = deltas.length;
var ctx = canvas.getContext("2d");
ctx.fillStyle = fillColor;
var extents = d3.extent(deltas);
var duration = (data[data.length-1].timestamp - data[0].timestamp)/1000;
var y = d3.scale.linear().range([canvas.height,0]).domain([0,extents[1]]);
d3.select("#delta-min").text(extents[0]/1000);
d3.select("#delta-max").text(extents[1]/1000);
d3.select("#delta-ave").text((duration/data.length).toPrecision(5));
d3.select("#delta-total").text(duration);
d3.select("#frames-total").text(data.length);
deltas.forEach(function(d,i) {
ctx.fillRect(i,y(d),1,canvas.height-y(d));
});
};
/* number of pointables */
function pointables(data) {
var pointables_per_msg = data.map(function(d,i) {
if ("pointables" in d) return d.pointables.length;
return 0;
});
var canvas = document.getElementById("pointables");
canvas.width = pointables_per_msg.length;
var ctx = canvas.getContext("2d");
ctx.fillStyle = fingerColor;
pointables_per_msg.forEach(function(d,i) {
d3.range(d).forEach(function(j) {
ctx.fillRect(i,canvas.height-(j+1)*5,1,3);
});
});
}
/* pointables by id */
function pointablesById(data) {
var pointables_by_id = data.map(function(d,i) {
if ("pointables" in d) return d.pointables.map(function(p) { return p.id; });
return [];
});
var canvas = document.getElementById("pointables-by-id");
canvas.width = pointables_by_id.length;
var ctx = canvas.getContext("2d");
ctx.fillStyle = fingerColor;
var flattened = _(pointables_by_id).flatten();
var max = d3.max(flattened);
var uniqs = _(flattened).chain().uniq().sortBy(_.identity).value().join(",");
d3.select("#pointable-uniques").text(uniqs);
pointables_by_id.forEach(function(frame,i) {
frame.forEach(function(d) {
ctx.fillRect(i,d*2,1,1);
});
});
};;
/* number of hands */
function hands(data) {
var hands_per_msg = data.map(function(d,i) {
if ("hands" in d) return d.hands.length;
return 0;
});
var canvas = document.getElementById("hands");
canvas.width = hands_per_msg.length;
var ctx = canvas.getContext("2d");
ctx.fillStyle = handColor;
hands_per_msg.forEach(function(d,i) {
d3.range(d).forEach(function(j) {
ctx.fillRect(i,canvas.height-(j+1)*5,1,3);
});
});
};
/* average pointable velocities */
function velocities(data) {
var velocities = data.map(function(d,i) {
if ("pointables" in d) {
var summed = 0;
var ave_velocities = d.pointables.forEach(function(p) {
var vel = p.tipVelocity;
summed += Math.sqrt(vel[0]*vel[0]+vel[1]*vel[1]+vel[2]*vel[2]);
});
return summed/d.pointables.length || 0;
}
return 0;
});
var canvas = document.getElementById("velocities");
canvas.width = velocities.length;
var ctx = canvas.getContext("2d");
ctx.fillStyle = fillColor;
var extents = d3.extent(velocities);
var y = d3.scale.linear().range([canvas.height,0]).domain(extents);
velocities.forEach(function(d,i) {
ctx.fillRect(i,y(d),1,canvas.height-y(d));
});
};
/* pointable velocity component average */
function velocityComponents(data) {
var velocities = data.map(function(d,i) {
if ("pointables" in d) {
var x = 0,
y = 0,
z = 0,
num = d.pointables.length;
var ave_velocities = d.pointables.forEach(function(p) {
var vel = p.tipVelocity;
x += vel[0];
y += vel[1];
z += vel[2];
});
return [x/num || 0,y/num || 0,z/num || 0];
}
return [0,0,0];
});
var canvasX = document.getElementById("velocity-x");
var canvasY = document.getElementById("velocity-y");
var canvasZ = document.getElementById("velocity-z");
canvasX.width = data.length;
canvasY.width = data.length;
canvasZ.width = data.length;
var ctxX = canvasX.getContext("2d");
var ctxY = canvasY.getContext("2d");
var ctxZ = canvasZ.getContext("2d");
var extentsX = d3.extent(velocities, function(d) { return d[0]; });
var extentsY = d3.extent(velocities, function(d) { return d[1]; });
var extentsZ = d3.extent(velocities, function(d) { return d[2]; });
var yX = d3.scale.linear().range([canvasX.height,0]).domain(extentsX);
var yY = d3.scale.linear().range([canvasY.height,0]).domain(extentsY);
var yZ = d3.scale.linear().range([canvasZ.height,0]).domain(extentsZ);
// line at 0
ctxX.fillStyle = darkColor;
ctxY.fillStyle = darkColor;
ctxZ.fillStyle = darkColor;
ctxX.fillRect(0,yX(0),canvasX.width,canvasX.height/2);
ctxY.fillRect(0,yY(0),canvasY.width,canvasX.height/2);
ctxZ.fillRect(0,yZ(0),canvasZ.width,canvasX.height/2);
ctxX.strokeStyle = fillColor;
ctxY.strokeStyle = fillColor;
ctxZ.strokeStyle = fillColor;
ctxX.beginPath();
ctxY.beginPath();
ctxZ.beginPath();
ctxX.moveTo(1,yX(velocities[0][0]),1,canvasX.height-yX(velocities[0][0]));
ctxY.moveTo(1,yY(velocities[0][1]),1,canvasY.height-yY(velocities[0][1]));
ctxZ.moveTo(1,yZ(velocities[0][2]),1,canvasZ.height-yZ(velocities[0][2]));
velocities.forEach(function(d,i) {
ctxX.lineTo(i,yX(d[0]),1,canvasX.height-yX(d[0]));
ctxY.lineTo(i,yY(d[1]),1,canvasY.height-yY(d[1]));
ctxZ.lineTo(i,yZ(d[2]),1,canvasZ.height-yZ(d[2]));
});
ctxX.stroke();
ctxY.stroke();
ctxZ.stroke();
};
</script>
<style>
body {
font-size: 12px;
font-family: Helvetica, Arial, sans-serif;
background: #1e1e1e;
color: #9b9994;
margin: 0;
}
h1 {
font-size: 14px;
margin: 8px 0 8px 16px;
color: #f2f2f2;
}
h4 {
font-size: 10px;
margin: -2px 0 10px 16px;
padding: 0;
line-height: 10px;
font-weight: normal;
}
canvas {
margin: 0;
}
.left {
float: left;
margin-left: 20px;
}
#line {
pointer-events: none;
}
h1 small {
margin-left: 12px;
}
h4 small {
margin-left: 12px;
font-size: 1em;
}
.fill {
color: #37A0CF;
}
.finger {
color: #FDAE61;
}
.hand {
color: #FFFFBF;
}
</style>