-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (35 loc) · 1.03 KB
/
index.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
// A node.js script to try to convert svg points of Pulsar CP 1919 into usable data
var pulses = require("./cp-edited");
var fs = require('fs');
pulses.reverse();
var totalTime = 0.0;
var currentMagnitude = 0.0;
var pulseNumber = 3;
var pulseArray = [];
for (let i = 0; i < pulses.length; i++) {
totalTime = 0.0; // Reset for each pulse
// console.log(i);
// console.log(getPulseLevels(i));
pulseArray.push(getPulseLevels(i));
}
console.log(pulseArray);
fs.writeFile("./test", JSON.stringify(pulseArray, null, 2), 'utf-8', function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
function getPulseLevels(pulse) {
var levels = pulses[pulse].map((elem, i) => {
var magnitude = elem[1];
totalTime = totalTime + elem[0];
// Account for line offset
if (i === 0) {
currentMagnitude = 0; // magnitude - (90 + pulse * 10);
} else {
currentMagnitude = currentMagnitude + magnitude;
}
return [totalTime, -currentMagnitude];
});
return levels;
}