fit-file-parser 1.9.4 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/binary.js +4 -0
- package/dist/fit-parser.js +15 -1
- package/dist/fit.js +31 -0
- package/dist/helper.js +12 -14
- package/package.json +2 -1
package/README.md
CHANGED
package/dist/binary.js
CHANGED
|
@@ -232,6 +232,10 @@ function applyOptions(data, field, options) {
|
|
|
232
232
|
case 'avg_temperature':
|
|
233
233
|
case 'max_temperature':
|
|
234
234
|
return convertTo(data, 'temperatureUnits', options.temperatureUnit);
|
|
235
|
+
case 'pressure':
|
|
236
|
+
case 'start_pressure':
|
|
237
|
+
case 'end_pressure':
|
|
238
|
+
return convertTo(data, 'pressureUnits', options.pressureUnit);
|
|
235
239
|
default:
|
|
236
240
|
return data;
|
|
237
241
|
}
|
package/dist/fit-parser.js
CHANGED
|
@@ -24,6 +24,7 @@ var FitParser = function () {
|
|
|
24
24
|
lengthUnit: options.lengthUnit || 'm',
|
|
25
25
|
temperatureUnit: options.temperatureUnit || 'celsius',
|
|
26
26
|
elapsedRecordField: options.elapsedRecordField || false,
|
|
27
|
+
pressureUnit: options.pressureUnit || 'bar',
|
|
27
28
|
mode: options.mode || 'list'
|
|
28
29
|
};
|
|
29
30
|
}
|
|
@@ -107,6 +108,8 @@ var FitParser = function () {
|
|
|
107
108
|
var file_ids = [];
|
|
108
109
|
var monitor_info = [];
|
|
109
110
|
var lengths = [];
|
|
111
|
+
var tank_updates = [];
|
|
112
|
+
var tank_summaries = [];
|
|
110
113
|
|
|
111
114
|
var loopIndex = headerLength;
|
|
112
115
|
var messageTypes = [];
|
|
@@ -198,6 +201,12 @@ var FitParser = function () {
|
|
|
198
201
|
case 'software':
|
|
199
202
|
fitObj.software = message;
|
|
200
203
|
break;
|
|
204
|
+
case 'tank_update':
|
|
205
|
+
tank_updates.push(message);
|
|
206
|
+
break;
|
|
207
|
+
case 'tank_summary':
|
|
208
|
+
tank_summaries.push(message);
|
|
209
|
+
break;
|
|
201
210
|
default:
|
|
202
211
|
if (messageType !== '') {
|
|
203
212
|
fitObj[messageType] = message;
|
|
@@ -208,7 +217,10 @@ var FitParser = function () {
|
|
|
208
217
|
|
|
209
218
|
if (isCascadeNeeded) {
|
|
210
219
|
fitObj.activity = fitObj.activity || {};
|
|
211
|
-
|
|
220
|
+
laps = (0, _helper.mapDataIntoLap)(laps, 'records', records);
|
|
221
|
+
laps = (0, _helper.mapDataIntoLap)(laps, 'lengths', lengths);
|
|
222
|
+
sessions = (0, _helper.mapDataIntoSession)(sessions, laps);
|
|
223
|
+
fitObj.activity.sessions = sessions;
|
|
212
224
|
fitObj.activity.events = events;
|
|
213
225
|
fitObj.activity.hrv = hrv;
|
|
214
226
|
fitObj.activity.device_infos = devices;
|
|
@@ -235,6 +247,8 @@ var FitParser = function () {
|
|
|
235
247
|
fitObj.file_ids = file_ids;
|
|
236
248
|
fitObj.monitor_info = monitor_info;
|
|
237
249
|
fitObj.definitions = definitions;
|
|
250
|
+
fitObj.tank_updates = tank_updates;
|
|
251
|
+
fitObj.tank_summaries = tank_summaries;
|
|
238
252
|
}
|
|
239
253
|
|
|
240
254
|
callback(null, fitObj);
|
package/dist/fit.js
CHANGED
|
@@ -10,6 +10,8 @@ var metersInOneKilometer = 1000;
|
|
|
10
10
|
var secondsInOneHour = 3600;
|
|
11
11
|
// according to https://en.wikipedia.org/wiki/Mile
|
|
12
12
|
var metersInOneMile = 1609.344;
|
|
13
|
+
var centiBarsInOneBar = 100;
|
|
14
|
+
var psiInOneBar = 14.5037738;
|
|
13
15
|
|
|
14
16
|
var FIT = exports.FIT = {
|
|
15
17
|
scConst: 180 / Math.pow(2, 31),
|
|
@@ -64,6 +66,20 @@ var FIT = exports.FIT = {
|
|
|
64
66
|
multiplier: 9 / 5,
|
|
65
67
|
offset: 32
|
|
66
68
|
}
|
|
69
|
+
},
|
|
70
|
+
pressureUnits: {
|
|
71
|
+
cbar: {
|
|
72
|
+
multiplier: 1,
|
|
73
|
+
offset: 0
|
|
74
|
+
},
|
|
75
|
+
bar: {
|
|
76
|
+
multiplier: 1 / centiBarsInOneBar,
|
|
77
|
+
offset: 0
|
|
78
|
+
},
|
|
79
|
+
psi: {
|
|
80
|
+
multiplier: 1 / centiBarsInOneBar * psiInOneBar,
|
|
81
|
+
offset: 0
|
|
82
|
+
}
|
|
67
83
|
}
|
|
68
84
|
},
|
|
69
85
|
messages: {
|
|
@@ -848,6 +864,19 @@ var FIT = exports.FIT = {
|
|
|
848
864
|
9: { field: 'o2_toxicity', type: 'uint16', scale: null, offset: 0, units: 'OTUs' },
|
|
849
865
|
10: { field: 'dive_number', type: 'uint32', scale: null, offset: 0, units: '' },
|
|
850
866
|
11: { field: 'bottom_time', type: 'uint32', scale: null, offset: 0, units: 's' }
|
|
867
|
+
},
|
|
868
|
+
319: {
|
|
869
|
+
name: 'tank_update',
|
|
870
|
+
253: { field: 'timestamp', type: 'date_time', scale: null, offset: 0, units: 's' },
|
|
871
|
+
0: { field: 'sensor', type: 'uint32', scale: null, offset: 0, units: '' },
|
|
872
|
+
1: { field: 'pressure', type: 'uint16', scale: null, offset: 0, units: 'cbar' }
|
|
873
|
+
},
|
|
874
|
+
323: {
|
|
875
|
+
name: 'tank_summary',
|
|
876
|
+
0: { field: 'sensor', type: 'uint32', scale: null, offset: 0, units: '' },
|
|
877
|
+
1: { field: 'start_pressure', type: 'uint16', scale: null, offset: 0, units: 'cbar' },
|
|
878
|
+
2: { field: 'end_pressure', type: 'uint16', scale: null, offset: 0, units: 'cbar' },
|
|
879
|
+
3: { field: 'volume_used', type: 'uint16', scale: null, offset: 0, units: 'cbar' }
|
|
851
880
|
}
|
|
852
881
|
},
|
|
853
882
|
types: {
|
|
@@ -961,6 +990,8 @@ var FIT = exports.FIT = {
|
|
|
961
990
|
268: 'dive_summary',
|
|
962
991
|
285: 'jump',
|
|
963
992
|
317: 'climb_pro',
|
|
993
|
+
319: 'tank_pressure',
|
|
994
|
+
323: 'tank_summary',
|
|
964
995
|
65280: 'mfg_range_min',
|
|
965
996
|
65534: 'mfg_range_max'
|
|
966
997
|
},
|
package/dist/helper.js
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
|
|
7
|
+
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
|
8
|
+
|
|
6
9
|
var mapDataIntoLap = exports.mapDataIntoLap = function mapDataIntoLap(inputLaps, lapKey, data) {
|
|
7
|
-
var laps =
|
|
10
|
+
var laps = [].concat(_toConsumableArray(inputLaps));
|
|
8
11
|
var index = 0;
|
|
9
12
|
for (var i = 0; i < laps.length; i++) {
|
|
10
13
|
var lap = laps[i];
|
|
11
14
|
var nextLap = laps[i + 1];
|
|
12
15
|
var tempData = [];
|
|
13
|
-
var lapStartTime = new Date(lap.
|
|
16
|
+
var lapStartTime = new Date(lap.start_time).getTime();
|
|
14
17
|
var nextLapStartTime = nextLap ? new Date(nextLap.start_time).getTime() : null;
|
|
15
18
|
for (var j = index; j < data.length; j++) {
|
|
16
19
|
var row = data[j];
|
|
17
20
|
if (nextLap) {
|
|
18
21
|
var timestamp = new Date(row.timestamp).getTime();
|
|
19
|
-
if (lapStartTime <= timestamp && nextLapStartTime
|
|
22
|
+
if (lapStartTime <= timestamp && nextLapStartTime > timestamp) {
|
|
20
23
|
tempData.push(row);
|
|
21
|
-
} else if (nextLapStartTime
|
|
22
|
-
laps[i][lapKey] = tempData;
|
|
24
|
+
} else if (nextLapStartTime <= timestamp) {
|
|
23
25
|
index = j;
|
|
24
26
|
break;
|
|
25
27
|
}
|
|
@@ -36,11 +38,8 @@ var mapDataIntoLap = exports.mapDataIntoLap = function mapDataIntoLap(inputLaps,
|
|
|
36
38
|
return laps;
|
|
37
39
|
};
|
|
38
40
|
|
|
39
|
-
var mapDataIntoSession = exports.mapDataIntoSession = function mapDataIntoSession(inputSessions,
|
|
40
|
-
var sessions =
|
|
41
|
-
var laps = JSON.parse(JSON.stringify(inputLaps));
|
|
42
|
-
laps = mapDataIntoLap(laps, 'lengths', lengths);
|
|
43
|
-
laps = mapDataIntoLap(laps, 'records', records);
|
|
41
|
+
var mapDataIntoSession = exports.mapDataIntoSession = function mapDataIntoSession(inputSessions, laps) {
|
|
42
|
+
var sessions = [].concat(_toConsumableArray(inputSessions));
|
|
44
43
|
var lapIndex = 0;
|
|
45
44
|
for (var i = 0; i < sessions.length; i++) {
|
|
46
45
|
var session = sessions[i];
|
|
@@ -52,10 +51,9 @@ var mapDataIntoSession = exports.mapDataIntoSession = function mapDataIntoSessio
|
|
|
52
51
|
var lap = laps[j];
|
|
53
52
|
if (nextSession) {
|
|
54
53
|
var lapStartTime = new Date(lap.start_time).getTime();
|
|
55
|
-
if (sessionStartTime <= lapStartTime && nextSessionStartTime
|
|
54
|
+
if (sessionStartTime <= lapStartTime && nextSessionStartTime > lapStartTime) {
|
|
56
55
|
tempLaps.push(lap);
|
|
57
|
-
} else if (nextSessionStartTime
|
|
58
|
-
sessions[i].laps = tempLaps;
|
|
56
|
+
} else if (nextSessionStartTime <= lapStartTime) {
|
|
59
57
|
lapIndex = j;
|
|
60
58
|
break;
|
|
61
59
|
}
|
package/package.json
CHANGED
|
@@ -65,13 +65,14 @@
|
|
|
65
65
|
},
|
|
66
66
|
"scripts": {
|
|
67
67
|
"example-output": "node_modules/gulp/bin/gulp.js; node examples/example.js examples/example.fit > examples/output.json",
|
|
68
|
+
"example-output-tank": "node_modules/gulp/bin/gulp.js; node examples/example.js examples/example-diving.fit > examples/output-diving.json",
|
|
68
69
|
"example-output-summary-first": "node_modules/gulp/bin/gulp.js; node examples/example.js examples/triathlon_summary_first.fit > examples/output_summary_first.json",
|
|
69
70
|
"example-output-summary-last": "node_modules/gulp/bin/gulp.js; node examples/example.js examples/triathlon_summary_last.fit > examples/output_summary_last.json",
|
|
70
71
|
"example": "node_modules/gulp/bin/gulp.js; node examples/example.js examples/triathlon_summary_first.fit",
|
|
71
72
|
"test": "node_modules/gulp/bin/gulp.js;",
|
|
72
73
|
"build": "node_modules/gulp/bin/gulp.js babel"
|
|
73
74
|
},
|
|
74
|
-
"version": "1.
|
|
75
|
+
"version": "1.10.0",
|
|
75
76
|
"dependencies": {
|
|
76
77
|
"buffer": "^5.1.0"
|
|
77
78
|
}
|