fit-file-parser 2.2.2 → 2.2.3
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/dist/cjs/fit.js +14 -0
- package/dist/cjs/fit_types.d.ts +2 -2
- package/dist/cjs/type_generator.js +8 -3
- package/dist/fit.js +14 -0
- package/dist/fit_types.d.ts +2 -2
- package/dist/type_generator.js +8 -3
- package/package.json +2 -2
- package/probe_session.js +0 -49
package/dist/cjs/fit.js
CHANGED
|
@@ -1734,6 +1734,13 @@ exports.FIT = {
|
|
|
1734
1734
|
offset: 0,
|
|
1735
1735
|
units: 'kGrit',
|
|
1736
1736
|
},
|
|
1737
|
+
182: {
|
|
1738
|
+
field: 'total_flow',
|
|
1739
|
+
type: 'float32',
|
|
1740
|
+
scale: 1,
|
|
1741
|
+
offset: 0,
|
|
1742
|
+
units: 'Flow',
|
|
1743
|
+
},
|
|
1737
1744
|
183: {
|
|
1738
1745
|
field: 'jump_count',
|
|
1739
1746
|
type: 'uint16',
|
|
@@ -1741,6 +1748,13 @@ exports.FIT = {
|
|
|
1741
1748
|
offset: 0,
|
|
1742
1749
|
units: '',
|
|
1743
1750
|
},
|
|
1751
|
+
186: {
|
|
1752
|
+
field: 'avg_grit',
|
|
1753
|
+
type: 'float32',
|
|
1754
|
+
scale: 1,
|
|
1755
|
+
offset: 0,
|
|
1756
|
+
units: 'kGrit',
|
|
1757
|
+
},
|
|
1744
1758
|
187: {
|
|
1745
1759
|
field: 'avg_flow',
|
|
1746
1760
|
type: 'float32',
|
package/dist/cjs/fit_types.d.ts
CHANGED
|
@@ -455,14 +455,14 @@ export interface ParsedSession {
|
|
|
455
455
|
est_sweat_loss?: number;
|
|
456
456
|
enhanced_min_respiration_rate?: number;
|
|
457
457
|
total_grit?: number;
|
|
458
|
+
total_flow?: number;
|
|
458
459
|
jump_count?: number;
|
|
460
|
+
avg_grit?: number;
|
|
459
461
|
avg_flow?: number;
|
|
460
462
|
primary_benefit?: number;
|
|
461
463
|
workout_feel?: number;
|
|
462
464
|
workout_rpe?: number;
|
|
463
465
|
resting_calories?: number;
|
|
464
|
-
avg_grit?: number;
|
|
465
|
-
avg_flow?: number;
|
|
466
466
|
timestamp: string;
|
|
467
467
|
message_index?: MessageIndex;
|
|
468
468
|
laps?: ParsedLap[];
|
|
@@ -234,13 +234,18 @@ function generateMessages(messages) {
|
|
|
234
234
|
const nodes = [];
|
|
235
235
|
Object.keys(messages).forEach((name) => {
|
|
236
236
|
const msg = fit_js_1.FIT.messages[Number(name)];
|
|
237
|
+
const usedFields = new Set();
|
|
237
238
|
const messageType = typescript_1.default.factory.createInterfaceDeclaration([
|
|
238
239
|
typescript_1.default.factory.createModifier(typescript_1.default.SyntaxKind.ExportKeyword),
|
|
239
240
|
], snakeToCamel(`parsed_${msg.name}`), undefined, undefined, [
|
|
240
|
-
...Object.keys(msg).filter(n => n !== 'name').
|
|
241
|
+
...Object.keys(msg).filter(n => n !== 'name').reduce((acc, id) => {
|
|
241
242
|
const def = msg[Number(id)];
|
|
242
|
-
|
|
243
|
-
|
|
243
|
+
if (!usedFields.has(def.field)) {
|
|
244
|
+
usedFields.add(def.field);
|
|
245
|
+
acc.push(generateProperty(def.field, generateTypeFromField(def), !['start_time', 'timestamp'].includes(def.field)));
|
|
246
|
+
}
|
|
247
|
+
return acc;
|
|
248
|
+
}, []),
|
|
244
249
|
...generateAdditionalFields(msg),
|
|
245
250
|
]);
|
|
246
251
|
nodes.push(messageType);
|
package/dist/fit.js
CHANGED
|
@@ -1731,6 +1731,13 @@ export const FIT = {
|
|
|
1731
1731
|
offset: 0,
|
|
1732
1732
|
units: 'kGrit',
|
|
1733
1733
|
},
|
|
1734
|
+
182: {
|
|
1735
|
+
field: 'total_flow',
|
|
1736
|
+
type: 'float32',
|
|
1737
|
+
scale: 1,
|
|
1738
|
+
offset: 0,
|
|
1739
|
+
units: 'Flow',
|
|
1740
|
+
},
|
|
1734
1741
|
183: {
|
|
1735
1742
|
field: 'jump_count',
|
|
1736
1743
|
type: 'uint16',
|
|
@@ -1738,6 +1745,13 @@ export const FIT = {
|
|
|
1738
1745
|
offset: 0,
|
|
1739
1746
|
units: '',
|
|
1740
1747
|
},
|
|
1748
|
+
186: {
|
|
1749
|
+
field: 'avg_grit',
|
|
1750
|
+
type: 'float32',
|
|
1751
|
+
scale: 1,
|
|
1752
|
+
offset: 0,
|
|
1753
|
+
units: 'kGrit',
|
|
1754
|
+
},
|
|
1741
1755
|
187: {
|
|
1742
1756
|
field: 'avg_flow',
|
|
1743
1757
|
type: 'float32',
|
package/dist/fit_types.d.ts
CHANGED
|
@@ -455,14 +455,14 @@ export interface ParsedSession {
|
|
|
455
455
|
est_sweat_loss?: number;
|
|
456
456
|
enhanced_min_respiration_rate?: number;
|
|
457
457
|
total_grit?: number;
|
|
458
|
+
total_flow?: number;
|
|
458
459
|
jump_count?: number;
|
|
460
|
+
avg_grit?: number;
|
|
459
461
|
avg_flow?: number;
|
|
460
462
|
primary_benefit?: number;
|
|
461
463
|
workout_feel?: number;
|
|
462
464
|
workout_rpe?: number;
|
|
463
465
|
resting_calories?: number;
|
|
464
|
-
avg_grit?: number;
|
|
465
|
-
avg_flow?: number;
|
|
466
466
|
timestamp: string;
|
|
467
467
|
message_index?: MessageIndex;
|
|
468
468
|
laps?: ParsedLap[];
|
package/dist/type_generator.js
CHANGED
|
@@ -214,13 +214,18 @@ export function generateMessages(messages) {
|
|
|
214
214
|
const nodes = [];
|
|
215
215
|
Object.keys(messages).forEach((name) => {
|
|
216
216
|
const msg = FIT.messages[Number(name)];
|
|
217
|
+
const usedFields = new Set();
|
|
217
218
|
const messageType = ts.factory.createInterfaceDeclaration([
|
|
218
219
|
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword),
|
|
219
220
|
], snakeToCamel(`parsed_${msg.name}`), undefined, undefined, [
|
|
220
|
-
...Object.keys(msg).filter(n => n !== 'name').
|
|
221
|
+
...Object.keys(msg).filter(n => n !== 'name').reduce((acc, id) => {
|
|
221
222
|
const def = msg[Number(id)];
|
|
222
|
-
|
|
223
|
-
|
|
223
|
+
if (!usedFields.has(def.field)) {
|
|
224
|
+
usedFields.add(def.field);
|
|
225
|
+
acc.push(generateProperty(def.field, generateTypeFromField(def), !['start_time', 'timestamp'].includes(def.field)));
|
|
226
|
+
}
|
|
227
|
+
return acc;
|
|
228
|
+
}, []),
|
|
224
229
|
...generateAdditionalFields(msg),
|
|
225
230
|
]);
|
|
226
231
|
nodes.push(messageType);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fit-file-parser",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.2.
|
|
4
|
+
"version": "2.2.3",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Parse your .FIT files easily, directly from JS (Garmin, Polar, Suunto)",
|
|
7
7
|
"author": {
|
|
@@ -75,4 +75,4 @@
|
|
|
75
75
|
"typescript": "^5.9.3",
|
|
76
76
|
"vitest": "^4.0.13"
|
|
77
77
|
}
|
|
78
|
-
}
|
|
78
|
+
}
|
package/probe_session.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'module'
|
|
2
|
-
|
|
3
|
-
// Note: Importing TS directly might not work with node without a loader.
|
|
4
|
-
// Better to use the built file if available, or use ts-node.
|
|
5
|
-
// But earlier I saw `dist/fit-parser.js`. Let's try to import that if key is default.
|
|
6
|
-
// Actually, let's just use `fs.readFileSync` and basic node.
|
|
7
|
-
// If `dist` is CJS, I can use `createRequire`.
|
|
8
|
-
|
|
9
|
-
import fs from 'node:fs'
|
|
10
|
-
|
|
11
|
-
const require = createRequire(import.meta.url)
|
|
12
|
-
|
|
13
|
-
const FitParserDist = require('./dist/fit-parser.js').default
|
|
14
|
-
|
|
15
|
-
const content = fs.readFileSync('/Users/dimitrios/Projects/sports-lib/samples/fit/jumps-mtb.fit')
|
|
16
|
-
const fitParser = new FitParserDist({
|
|
17
|
-
force: true,
|
|
18
|
-
speedUnit: 'km/h',
|
|
19
|
-
lengthUnit: 'm',
|
|
20
|
-
temperatureUnit: 'celsius',
|
|
21
|
-
elapsedRecordField: true,
|
|
22
|
-
mode: 'both',
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
fitParser.parse(content, (error, data) => {
|
|
26
|
-
if (error) {
|
|
27
|
-
console.error(error)
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
const session = data.sessions[0]
|
|
31
|
-
if (session) {
|
|
32
|
-
console.log('=== SESSION KEYS & VALUES ===')
|
|
33
|
-
Object.keys(session).forEach((key) => {
|
|
34
|
-
const val = session[key]
|
|
35
|
-
console.log(`${key}: ${val}`)
|
|
36
|
-
if (Math.abs(val - 11) < 0.1)
|
|
37
|
-
console.log(`>>> MATCH 11 (Jump Count?): ${key}`)
|
|
38
|
-
if (Math.abs(val - 159) < 0.1)
|
|
39
|
-
console.log(`>>> MATCH 159 (Resting Cals?): ${key}`)
|
|
40
|
-
if (Math.abs(val - 6079174) < 1)
|
|
41
|
-
console.log(`>>> MATCH 6M (Training Load?): ${key}`)
|
|
42
|
-
if (Math.abs(val - 100) < 0.1)
|
|
43
|
-
console.log(`>>> MATCH 100 (Avg VAM?): ${key}`)
|
|
44
|
-
if (Math.abs(val - 2756) < 1)
|
|
45
|
-
console.log(`>>> MATCH 2756 (Avg Resp?): ${key}`)
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
})
|