-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
62 lines (57 loc) · 1.77 KB
/
main.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
'use strict';
/*
* Define, load, condition and render datasets
*/
function vecmag(v) {
return Math.sqrt(
(v[0] * v[0]) +
(v[1] * v[1]) +
(v[2] * v[2])
);
}
let sensormodel = new CSVModel('flight_20160314.csv', rec => {
let accel = [+rec.accelx, +rec.accely, +rec.accely],
gravity = [+rec.gravityx, +rec.gravityy, +rec.gravityz],
linaccel = [+rec.linaccelx, +rec.linaccely, +rec.linaccelz],
gyr = [+rec.gyrx, +rec.gyry, +rec.gyrz],
mag = [+rec.magx, +rec.magy, +rec.magz];
return {
date: new Date(rec.datestamp),
accel: accel,
gravity: gravity,
gyr: gyr,
mag: mag,
pitch: +rec.orientpitch,
roll: +rec.orientroll,
azimuth: +rec.orientazimuth,
pressure: +rec.pressure,
sound: +rec.sound,
gravmag: vecmag(gravity),
accelmag: vecmag(accel),
linaccelmag: vecmag(linaccel),
magmag: vecmag(mag),
gyrmag: vecmag(gyr)
};
})
, adsmodel = new CSVModel('flighttrack.csv', rec => {
let dateparts = /^([A-Za-z]+)\s+(\d\d):(\d\d):(\d\d)\s+([AP]M)$/.exec(rec.timestamp)
, pmoffs = dateparts[5] == 'PM' ? 12 : 0
, course = /^(\d+)\D*$/.exec(rec.course);
return {
date: new Date(2016, 2, 14, +dateparts[2] + pmoffs, +dateparts[3], +dateparts[4]),
lat: +rec.lat,
lon: +rec.lon,
course: +rec.course[1],
direction: rec.direction,
kts: +rec.kts,
mph: +rec.mph,
altft: +rec.altft,
climbft: +rec.climbft,
datasource: rec.datasource
};
});
Promise.all([sensormodel.loadP(), adsmodel.loadP()]).then(res => {
new FlightChart(res[0].records, res[1].records, document.getElementById('frame'));
// document.getElementById('savebtn').innerHTML = makeSVGLink('chart');
})
.catch(err => { throw err; });