-
Notifications
You must be signed in to change notification settings - Fork 28
/
dataexport.js
41 lines (39 loc) · 1.63 KB
/
dataexport.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
// basic csv serialisation function
// accepts a list of lists representing the columns of data, and a list of text labels
var dumpSamples = function (columns, labels) {
if (columns.length != labels.length) {
throw("label length mismatches number of columns");
}
var lengths = columns.map(function(x) {return x.length;})
var csvContent = '';
for (var i = 0; i < labels.length; i++) {
csvContent += labels[i] + ((i != (labels.length-1)) ? "," : "");
}
csvContent += "\n";
var minimumLength = Math.min.apply(null, lengths);
for (var i = 0; i < minimumLength; i++) {
for (var j = 0; j < columns.length; j++) {
var x = columns[j][i].toFixed(4);
x = (x == 0) ? (0.00001).toFixed(4) : x;
csvContent += (x >= 0 ? "+" : "") + x + ((j != (columns.length-1)) ? "," : "");
}
csvContent += (i != (minimumLength-1) ? "\n" : "");
}
return csvContent
}
var saveData = function (target) {
var labels = [];
var columns = [];
if (session.devices.length) {
for (var i = 0; i < session.devices.length; i++) {
for (var j = 0; j < session.devices[i].channels.length; j++) {
for (var k = 0; k < session.devices[i].channels[i].signals.length; k++) {
var label = '' + i + session.devices[i].channels[j].label +"_"+ session.devices[i].channels[j].signals[k].label;
labels.push(label);
columns.push(session.devices[i].channels[j].signals[k].buffer.getData());
};
};
};
fileio.writeByURI(target, dumpSamples(columns, labels));
};
};