-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpwrParser.js
60 lines (48 loc) · 1.15 KB
/
pwrParser.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
let _FitFileParser, _fs , _parent, parsedPower, data
class FitParser {
constructor(file) {
this._source = file;
_parent = this;
_FitFileParser = require("fit-file-parser").default;
_fs = require("fs");
data,
parsedPower
}
getRawData() {
let data = _fs.readFileSync(this._source);
return data;
}
parseRawData(data) {
var fitParser = new _FitFileParser({
force: true
});
return new Promise(function(resolve, reject) {
fitParser.parse(data, function(error, data) {
let result;
if (data) {
result = data;
} else {
result = "KO";
}
_parent.data = result
resolve(result)
});
});
}
getPower(data) {
return new Promise(function(resolve, reject) {
let powerData = [];
let records = data.records;
try {
records.forEach(record => {
powerData.push({ x: (new Date(record.timestamp)).getTime(), y: record.power });
});
} catch (err) {}
_parent.parsedPower = parsedPower
resolve(powerData);
});
}
}
module.exports = {
FitParser : FitParser
}