fit-file-parser 2.2.3 → 2.2.5

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.
@@ -0,0 +1,35 @@
1
+ # FIT Parser Development Rules
2
+
3
+ You are working on the `fit-parser` library. Follow these rules strictly to ensure correctness and stability.
4
+
5
+ ## Core Principles
6
+
7
+ 1. **Trust the Official SDK**:
8
+ * Always verify Message IDs and Field IDs against the Official Garmin FIT SDK (`@garmin/fitsdk`).
9
+ * **NEVER** guess or reuse existing IDs if they seem wrong (e.g., Message 140 vs 285).
10
+ * If `@garmin/fitsdk` is available in `node_modules`, use it as the source of truth.
11
+
12
+ 2. **Investigation First**:
13
+ * If a field is missing, use `npm run inspect <file>` or `npm run probe <file> <value>` BEFORE modifying code.
14
+ * Confirm the field exists in the file and identify its raw value.
15
+
16
+ 3. **Testing is Mandatory**:
17
+ * Every new message or field definition MUST have a corresponding test case in `test/`.
18
+ * Test against real FIT files whenever possible (use `examples/` directory).
19
+ * Use `npm run test` to verify changes.
20
+
21
+ 4. **Code Generation**:
22
+ * `src/fit_types.ts` is AUTO-GENERATED.
23
+ * If you modify `src/fit.ts`, you **MUST** run `npm run codegen` to update types.
24
+ * Do not edit `src/fit_types.ts` manually.
25
+
26
+ ## Workflow checklist
27
+
28
+ When adding a new message or fixing a field:
29
+
30
+ - [ ] Locate official Message ID in Garmin SDK
31
+ - [ ] Locate Field IDs and Types in Garmin SDK
32
+ - [ ] Update `src/fit.ts` with new definition
33
+ - [ ] Run `npm run codegen`
34
+ - [ ] Add/Update test in `test/`
35
+ - [ ] Run `npm run build && npm run test`
@@ -0,0 +1,29 @@
1
+ ---
2
+ name: add-fit-message
3
+ description: Add a new FIT message or update an existing one
4
+ ---
5
+
6
+ # Add/Update FIT Message
7
+
8
+ ## Prerequisites
9
+
10
+ - Identify Message ID (e.g., 285 for Jump)
11
+ - Identify Field IDs and Types from Garmin SDK
12
+
13
+ ## Steps
14
+
15
+ 1. **Modify `src/fit.ts`** - Add message definition
16
+ 2. **Run `npm run codegen`** - Updates `src/fit_types.ts`
17
+ 3. **Add Test** - Create test in `test/`
18
+ 4. **Verify** - Run `npm run build && npm run test`
19
+
20
+ ## Example Entry
21
+
22
+ ```typescript
23
+ 285: {
24
+ name: 'jump',
25
+ 253: { field: 'timestamp', type: 'date_time', scale: null, offset: 0, units: 's' },
26
+ 0: { field: 'distance', type: 'float32', scale: null, offset: 0, units: 'm' },
27
+ 5: { field: 'position_lat', type: 'sint32', scale: null, offset: 0, units: 'semicircles' },
28
+ }
29
+ ```
@@ -0,0 +1,28 @@
1
+ ---
2
+ description: common fit-parser development workflows
3
+ ---
4
+
5
+ # Inspect FIT File
6
+
7
+ // turbo
8
+ 1. node scripts/inspect_fit.js <path_to_fit_file> [message_key]
9
+
10
+ # Probe FIT File for Value
11
+
12
+ // turbo
13
+ 1. node scripts/deep_probe.js <path_to_fit_file> <value> [tolerance]
14
+
15
+ # Run Tests
16
+
17
+ // turbo
18
+ 1. npm run build && npm run test
19
+
20
+ # Add New Message
21
+
22
+ 1. Locate Message ID in `@garmin/fitsdk/src/profile.js`
23
+ 2. Update `src/fit.ts` with message definition
24
+ // turbo
25
+ 3. npm run codegen
26
+ 4. Add test in `test/`
27
+ // turbo
28
+ 5. npm run build && npm run test
@@ -0,0 +1,50 @@
1
+ # Investigating FIT Files
2
+
3
+ This guide explains how to investigate FIT files when you suspect fields are missing or incorrectly parsed, and how to add support for new messages.
4
+
5
+ ## Tools Included
6
+
7
+ We provide scripts in the `scripts/` directory to help you probe FIT files.
8
+
9
+ ### 1. Inspecting Parsed Data (`scripts/inspect_fit.js`)
10
+
11
+ Use this script to see what the parser currently outputs for a file.
12
+
13
+ ```bash
14
+ # View summary of all messages in file
15
+ node scripts/inspect_fit.js examples/jumps-mtb.fit
16
+
17
+ # View specific message details
18
+ node scripts/inspect_fit.js examples/jumps-mtb.fit jumps
19
+ node scripts/inspect_fit.js examples/jumps-mtb.fit session
20
+ ```
21
+
22
+ ### 2. Probing for Unknown Data (`scripts/deep_probe.js`)
23
+
24
+ Use this script when you know a value exists (e.g., from Garmin Connect or another tool) but can't find it in the parser output. It recursively searches the raw parsed structure for that value.
25
+
26
+ ```bash
27
+ # Edit the script to set the value you're looking for, then run:
28
+ node scripts/deep_probe.js
29
+ ```
30
+
31
+ ## Workflow for Missing Fields
32
+
33
+ If you suspect a field is missing (e.g., "Jump Hang Time"):
34
+
35
+ 1. **Verify it exists**: Check the file with an external tool or online viewer. Note the exact value (e.g., `0.36` seconds).
36
+ 2. **Probe**: Use `deep_probe.js` or inspect the `examples/` output to see if the value appears in an unknown field (e.g., `field_123`).
37
+ 3. **Identify Message ID**:
38
+ * Check `src/fit.ts` for the message definition.
39
+ * If the message ID seems wrong, or fields are missing, compare with the **Official Garmin FIT SDK**.
40
+ * *Tip: You can find the official SDK in `@garmin/fitsdk` if installed, or search online.*
41
+ 4. **Fix**:
42
+ * Update `src/fit.ts` with the correct Message ID and Field IDs.
43
+ * Run `npm run codegen` to update types.
44
+ * Add a test case in `test/` relative to your new message.
45
+
46
+ ## Common Issues
47
+
48
+ * **Wrong Message ID**: Sometimes `fit-parser` has legacy or guessed IDs (e.g., `jump` was 140, but official is 285).
49
+ * **Missing Fields**: New devices add new fields. They often appear as `unknown_field_X`.
50
+ * **Scale/Offset**: If values look huge (e.g., 20838184 instead of 20.838), check if they need a scale factor (e.g., `semicircles` to `degrees`).
package/check_ids.js ADDED
@@ -0,0 +1,24 @@
1
+ import fs from 'fs';
2
+ import FitParser from './dist/fit-parser.js';
3
+
4
+ const content = fs.readFileSync('../sports-lib/samples/fit/jumps-mtb.fit');
5
+ const fitParser = new (FitParser.default || FitParser)({ force: true, mode: 'both' });
6
+
7
+ fitParser.parse(content, (error, data) => {
8
+ if (error) { console.error(error); return; }
9
+
10
+ // The parser stores messages in data[messageName]
11
+ // Any unknown messages are in data[messageId] (if numeric)
12
+ console.log('Keys in data:', Object.keys(data));
13
+
14
+ // Let's check for anything that looks like a message ID
15
+ for (const key of Object.keys(data)) {
16
+ if (!isNaN(parseInt(key))) {
17
+ console.log(`Unknown Message ID found: ${key} (${data[key].length} items)`);
18
+ }
19
+ }
20
+
21
+ if (data.jumps) {
22
+ console.log('Jumps fields:', Object.keys(data.jumps[0]));
23
+ }
24
+ });
@@ -0,0 +1,46 @@
1
+ import fs from 'fs'
2
+ import { createRequire } from 'module'
3
+
4
+ const require = createRequire(import.meta.url)
5
+ const FitParser = require('./dist/fit-parser.js').default
6
+
7
+ const content = fs.readFileSync('./examples/jumps-mtb.fit')
8
+ const fitParser = new FitParser({
9
+ force: true,
10
+ speedUnit: 'm/s',
11
+ lengthUnit: 'm',
12
+ temperatureUnit: 'celsius',
13
+ elapsedRecordField: true,
14
+ mode: 'both',
15
+ })
16
+
17
+ fitParser.parse(content, (error, data) => {
18
+ if (error) {
19
+ console.error(error)
20
+ return
21
+ }
22
+
23
+ console.log('=== JUMPS ARRAY ===')
24
+ if (data.jumps && data.jumps.length > 0) {
25
+ data.jumps.forEach((jump, i) => {
26
+ console.log(`\nJump ${i + 1}:`)
27
+ Object.keys(jump).forEach((key) => {
28
+ console.log(` ${key}: ${JSON.stringify(jump[key])}`)
29
+ })
30
+ })
31
+ }
32
+ else {
33
+ console.log('No jumps found')
34
+ }
35
+
36
+ // Also check definitions array for message 140 (jump)
37
+ console.log('\n=== DEFINITIONS FOR MESSAGE 140 (JUMP) ===')
38
+ if (data.definitions) {
39
+ const jumpDefs = data.definitions.filter(d => d && d.messageType === 140)
40
+ console.log(`Found ${jumpDefs.length} jump definitions`)
41
+ jumpDefs.forEach((def, i) => {
42
+ console.log(`\nDefinition ${i + 1}:`)
43
+ console.log(JSON.stringify(def, null, 2))
44
+ })
45
+ }
46
+ })
package/dist/binary.js CHANGED
@@ -84,6 +84,10 @@ function readData(blob, fDef, startIndex, options) {
84
84
  }
85
85
  return temp;
86
86
  }
87
+ if (fDef.type === 'sint8') {
88
+ const val = blob[startIndex];
89
+ return val > 127 ? val - 256 : val;
90
+ }
87
91
  return blob[startIndex];
88
92
  }
89
93
  function formatByType(data, type, scale, offset) {
@@ -90,6 +90,10 @@ function readData(blob, fDef, startIndex, options) {
90
90
  }
91
91
  return temp;
92
92
  }
93
+ if (fDef.type === 'sint8') {
94
+ const val = blob[startIndex];
95
+ return val > 127 ? val - 256 : val;
96
+ }
93
97
  return blob[startIndex];
94
98
  }
95
99
  function formatByType(data, type, scale, offset) {
package/dist/cjs/fit.js CHANGED
@@ -3005,13 +3005,18 @@ exports.FIT = {
3005
3005
  units: 'percent',
3006
3006
  },
3007
3007
  },
3008
- 140: {
3008
+ 285: {
3009
3009
  name: 'jump',
3010
3010
  253: { field: 'timestamp', type: 'date_time', scale: null, offset: 0, units: 's' },
3011
- 9: { field: 'distance', type: 'uint16', scale: 100, offset: 0, units: 'm' },
3012
- 10: { field: 'height', type: 'uint16', scale: 1000, offset: 0, units: 'm' },
3013
- 37: { field: 'score', type: 'sint32', scale: null, offset: 0, units: '' },
3014
- 7: { field: 'enhanced_mets', type: 'uint32', scale: 65536, offset: 0, units: 'METs' },
3011
+ 0: { field: 'distance', type: 'float32', scale: null, offset: 0, units: 'm' },
3012
+ 1: { field: 'height', type: 'float32', scale: null, offset: 0, units: 'm' },
3013
+ 2: { field: 'rotations', type: 'uint8', scale: null, offset: 0, units: '' },
3014
+ 3: { field: 'hang_time', type: 'float32', scale: null, offset: 0, units: 's' },
3015
+ 4: { field: 'score', type: 'float32', scale: null, offset: 0, units: '' },
3016
+ 5: { field: 'position_lat', type: 'sint32', scale: null, offset: 0, units: 'semicircles' },
3017
+ 6: { field: 'position_long', type: 'sint32', scale: null, offset: 0, units: 'semicircles' },
3018
+ 7: { field: 'speed', type: 'uint16', scale: 1000, offset: 0, units: 'm/s' },
3019
+ 8: { field: 'enhanced_speed', type: 'uint32', scale: 1000, offset: 0, units: 'm/s' },
3015
3020
  },
3016
3021
  21: {
3017
3022
  name: 'event',
@@ -871,13 +871,6 @@ export interface ParsedOHrSettings {
871
871
  enabled?: number;
872
872
  timestamp: string;
873
873
  }
874
- export interface ParsedJump {
875
- enhanced_mets?: number;
876
- distance?: number;
877
- height?: number;
878
- score?: number;
879
- timestamp: string;
880
- }
881
874
  export interface ParsedFieldDescription {
882
875
  developer_data_index?: number;
883
876
  field_definition_number?: number;
@@ -975,6 +968,18 @@ export interface ParsedDiveSummary {
975
968
  bottom_time?: number;
976
969
  timestamp: string;
977
970
  }
971
+ export interface ParsedJump {
972
+ distance?: number;
973
+ height?: number;
974
+ rotations?: number;
975
+ hang_time?: number;
976
+ score?: number;
977
+ position_lat?: number;
978
+ position_long?: number;
979
+ speed?: number;
980
+ enhanced_speed?: number;
981
+ timestamp: string;
982
+ }
978
983
  export interface ParsedTankUpdate {
979
984
  sensor?: number;
980
985
  pressure?: number;
package/dist/fit.js CHANGED
@@ -3002,13 +3002,18 @@ export const FIT = {
3002
3002
  units: 'percent',
3003
3003
  },
3004
3004
  },
3005
- 140: {
3005
+ 285: {
3006
3006
  name: 'jump',
3007
3007
  253: { field: 'timestamp', type: 'date_time', scale: null, offset: 0, units: 's' },
3008
- 9: { field: 'distance', type: 'uint16', scale: 100, offset: 0, units: 'm' },
3009
- 10: { field: 'height', type: 'uint16', scale: 1000, offset: 0, units: 'm' },
3010
- 37: { field: 'score', type: 'sint32', scale: null, offset: 0, units: '' },
3011
- 7: { field: 'enhanced_mets', type: 'uint32', scale: 65536, offset: 0, units: 'METs' },
3008
+ 0: { field: 'distance', type: 'float32', scale: null, offset: 0, units: 'm' },
3009
+ 1: { field: 'height', type: 'float32', scale: null, offset: 0, units: 'm' },
3010
+ 2: { field: 'rotations', type: 'uint8', scale: null, offset: 0, units: '' },
3011
+ 3: { field: 'hang_time', type: 'float32', scale: null, offset: 0, units: 's' },
3012
+ 4: { field: 'score', type: 'float32', scale: null, offset: 0, units: '' },
3013
+ 5: { field: 'position_lat', type: 'sint32', scale: null, offset: 0, units: 'semicircles' },
3014
+ 6: { field: 'position_long', type: 'sint32', scale: null, offset: 0, units: 'semicircles' },
3015
+ 7: { field: 'speed', type: 'uint16', scale: 1000, offset: 0, units: 'm/s' },
3016
+ 8: { field: 'enhanced_speed', type: 'uint32', scale: 1000, offset: 0, units: 'm/s' },
3012
3017
  },
3013
3018
  21: {
3014
3019
  name: 'event',
@@ -871,13 +871,6 @@ export interface ParsedOHrSettings {
871
871
  enabled?: number;
872
872
  timestamp: string;
873
873
  }
874
- export interface ParsedJump {
875
- enhanced_mets?: number;
876
- distance?: number;
877
- height?: number;
878
- score?: number;
879
- timestamp: string;
880
- }
881
874
  export interface ParsedFieldDescription {
882
875
  developer_data_index?: number;
883
876
  field_definition_number?: number;
@@ -975,6 +968,18 @@ export interface ParsedDiveSummary {
975
968
  bottom_time?: number;
976
969
  timestamp: string;
977
970
  }
971
+ export interface ParsedJump {
972
+ distance?: number;
973
+ height?: number;
974
+ rotations?: number;
975
+ hang_time?: number;
976
+ score?: number;
977
+ position_lat?: number;
978
+ position_long?: number;
979
+ speed?: number;
980
+ enhanced_speed?: number;
981
+ timestamp: string;
982
+ }
978
983
  export interface ParsedTankUpdate {
979
984
  sensor?: number;
980
985
  pressure?: number;
package/find_field.js ADDED
@@ -0,0 +1,23 @@
1
+ const fs = require('fs');
2
+ const FitParser = require('./dist/fit-parser.js').default;
3
+
4
+ const content = fs.readFileSync('../sports-lib/samples/fit/jumps-mtb.fit');
5
+ const fitParser = new FitParser({ force: true, mode: 'both' });
6
+
7
+ fitParser.parse(content, (error, data) => {
8
+ if (error) { console.error(error); return; }
9
+
10
+ function search(obj, path = '') {
11
+ if (!obj || typeof obj !== 'object') return;
12
+ for (const [key, value] of Object.entries(obj)) {
13
+ const currentPath = path ? `${path}.${key}` : key;
14
+ if (key === 'enhanced_mets') {
15
+ console.log(`FOUND enhanced_mets at ${currentPath}: ${value}`);
16
+ }
17
+ search(value, currentPath);
18
+ }
19
+ }
20
+
21
+ search(data);
22
+ console.log('Search finished.');
23
+ });
@@ -0,0 +1,28 @@
1
+ import fs from 'fs';
2
+ import FitParser from './dist/fit-parser.js';
3
+
4
+ const content = fs.readFileSync('../sports-lib/samples/fit/jumps-mtb.fit');
5
+ // Try both ways to instantiate
6
+ const fitParser = new (FitParser.default || FitParser)({ force: true, mode: 'both' });
7
+
8
+ fitParser.parse(content, (error, data) => {
9
+ if (error) { console.error(error); return; }
10
+
11
+ function search(obj, path = '') {
12
+ if (!obj || typeof obj !== 'object') return;
13
+ if (Array.isArray(obj)) {
14
+ obj.forEach((item, index) => search(item, `${path}[${index}]`));
15
+ return;
16
+ }
17
+ for (const [key, value] of Object.entries(obj)) {
18
+ const currentPath = path ? `${path}.${key}` : key;
19
+ if (key === 'enhanced_mets') {
20
+ console.log(`FOUND enhanced_mets at ${currentPath}: ${value}`);
21
+ }
22
+ search(value, currentPath);
23
+ }
24
+ }
25
+
26
+ search(data);
27
+ console.log('Search finished.');
28
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "fit-file-parser",
3
3
  "type": "module",
4
- "version": "2.2.3",
4
+ "version": "2.2.5",
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/scan_jumps.js ADDED
@@ -0,0 +1,29 @@
1
+ import fs from 'fs';
2
+ import FitParser from './dist/fit-parser.js';
3
+
4
+ const content = fs.readFileSync('../sports-lib/samples/fit/jumps-mtb.fit');
5
+ const fitParser = new (FitParser.default || FitParser)({ force: true, mode: 'both' });
6
+
7
+ fitParser.parse(content, (error, data) => {
8
+ if (error) { console.error(error); return; }
9
+
10
+ if (data.jumps && data.jumps.length > 0) {
11
+ console.log(`Found ${data.jumps.length} jumps.`);
12
+ data.jumps.forEach((j, i) => {
13
+ // check for values close to 16.3038
14
+ const target = 16.3038;
15
+ const epsilon = 0.1;
16
+
17
+ Object.entries(j).forEach(([key, val]) => {
18
+ if (typeof val === 'number' && Math.abs(val - target) < epsilon) {
19
+ console.log(`MATCH INDEX ${i} KEY ${key}: ${val}`);
20
+ }
21
+ });
22
+
23
+ // Also just print field 7 ('speed' in new def)
24
+ console.log(`Jump ${i}: speed=${j.speed}`);
25
+ });
26
+ } else {
27
+ console.log('No jumps found.');
28
+ }
29
+ });
@@ -0,0 +1,74 @@
1
+ import fs from 'fs'
2
+ import { createRequire } from 'module'
3
+
4
+ const require = createRequire(import.meta.url)
5
+ // Try to load from local build or node_modules
6
+ let FitParser
7
+ try {
8
+ FitParser = require('../dist/fit-parser.js').default
9
+ }
10
+ catch (e) {
11
+ FitParser = require('fit-file-parser').default
12
+ }
13
+
14
+ const args = process.argv.slice(2)
15
+ if (args.length < 2) {
16
+ console.log('Usage: node deep_probe.js <path_to_fit_file> <search_value> [tolerance]')
17
+ console.log('Example: node deep_probe.js ../examples/jumps-mtb.fit 11 0.1')
18
+ process.exit(1)
19
+ }
20
+
21
+ const filePath = args[0]
22
+ const targetValue = Number.parseFloat(args[1])
23
+ const tolerance = args[2] ? Number.parseFloat(args[2]) : 0.001
24
+
25
+ if (isNaN(targetValue)) {
26
+ console.error('Error: Search value must be a number')
27
+ process.exit(1)
28
+ }
29
+
30
+ try {
31
+ const content = fs.readFileSync(filePath)
32
+ const fitParser = new FitParser({
33
+ force: true,
34
+ speedUnit: 'm/s',
35
+ lengthUnit: 'm',
36
+ temperatureUnit: 'celsius',
37
+ elapsedRecordField: true,
38
+ mode: 'both',
39
+ })
40
+
41
+ function search(obj, path = []) {
42
+ if (!obj || typeof obj !== 'object')
43
+ return
44
+
45
+ Object.keys(obj).forEach((key) => {
46
+ const val = obj[key]
47
+ const newPath = [...path, key]
48
+
49
+ if (typeof val === 'number') {
50
+ if (Math.abs(val - targetValue) <= tolerance) {
51
+ console.log(`>>> FOUND MATCH at: ${newPath.join('.')} (Value: ${val})`)
52
+ }
53
+ }
54
+
55
+ if (typeof val === 'object') {
56
+ search(val, newPath)
57
+ }
58
+ })
59
+ }
60
+
61
+ fitParser.parse(content, (error, data) => {
62
+ if (error) {
63
+ console.error(error)
64
+ }
65
+ else {
66
+ console.log(`Searching for value ${targetValue} (±${tolerance}) in ${filePath}...`)
67
+ search(data)
68
+ console.log('Search complete.')
69
+ }
70
+ })
71
+ }
72
+ catch (e) {
73
+ console.error('Error:', e.message)
74
+ }
@@ -0,0 +1,69 @@
1
+ import fs from 'fs'
2
+ import { createRequire } from 'module'
3
+
4
+ const require = createRequire(import.meta.url)
5
+ // Try to load from local build or node_modules
6
+ let FitParser
7
+ try {
8
+ FitParser = require('../dist/fit-parser.js').default
9
+ }
10
+ catch (e) {
11
+ FitParser = require('fit-file-parser').default
12
+ }
13
+
14
+ const args = process.argv.slice(2)
15
+ if (args.length < 1) {
16
+ console.log('Usage: node inspect_fit.js <path_to_fit_file> [message_key]')
17
+ console.log('Example: node inspect_fit.js ../examples/jumps-mtb.fit jumps')
18
+ process.exit(1)
19
+ }
20
+
21
+ const filePath = args[0]
22
+ const messageKey = args[1]
23
+
24
+ try {
25
+ const content = fs.readFileSync(filePath)
26
+ const fitParser = new FitParser({
27
+ force: true,
28
+ mode: 'both',
29
+ speedUnit: 'm/s',
30
+ lengthUnit: 'm',
31
+ })
32
+
33
+ fitParser.parse(content, (error, data) => {
34
+ if (error) {
35
+ console.error('Error parsing FIT file:', error)
36
+ return
37
+ }
38
+
39
+ if (messageKey) {
40
+ if (data[messageKey]) {
41
+ console.log(`\n=== ${messageKey.toUpperCase()} (${Array.isArray(data[messageKey]) ? data[messageKey].length : 'object'}) ===`)
42
+ console.log(JSON.stringify(data[messageKey], null, 2))
43
+ }
44
+ else if (data.activity && data.activity[messageKey]) {
45
+ console.log(`\n=== ACTIVITY.${messageKey.toUpperCase()} ===`)
46
+ console.log(JSON.stringify(data.activity[messageKey], null, 2))
47
+ }
48
+ else {
49
+ console.log(`\nMessage key '${messageKey}' not found in root or activity object.`)
50
+ console.log('Available keys:', Object.keys(data).join(', '))
51
+ }
52
+ }
53
+ else {
54
+ console.log('\n=== ROOT KEYS ===')
55
+ console.log(Object.keys(data).join('\n'))
56
+
57
+ // Print summary of counts
58
+ console.log('\n=== SUMMARY ===')
59
+ Object.keys(data).forEach((key) => {
60
+ if (Array.isArray(data[key])) {
61
+ console.log(`${key}: ${data[key].length} items`)
62
+ }
63
+ })
64
+ }
65
+ })
66
+ }
67
+ catch (e) {
68
+ console.error('Error reading file:', e.message)
69
+ }
package/deep_probe.js DELETED
@@ -1,70 +0,0 @@
1
- import fs from 'fs'
2
- import { createRequire } from 'module'
3
-
4
- const require = createRequire(import.meta.url)
5
- const FitParser = require('./dist/fit-parser.js').default
6
-
7
- const content = fs.readFileSync('/Users/dimitrios/Projects/sports-lib/samples/fit/jumps-mtb.fit')
8
- const fitParser = new FitParser({
9
- force: true,
10
- speedUnit: 'km/h',
11
- lengthUnit: 'm',
12
- temperatureUnit: 'celsius',
13
- elapsedRecordField: true,
14
- mode: 'both',
15
- })
16
-
17
- function search(obj, path = []) {
18
- if (!obj || typeof obj !== 'object')
19
- return
20
-
21
- Object.keys(obj).forEach((key) => {
22
- const val = obj[key]
23
- const newPath = [...path, key]
24
-
25
- // Check match 11 (Jump Count)
26
- if (typeof val === 'number' && Math.abs(val - 11) < 0.001) {
27
- console.log(`>>> FOUND 11 at: ${newPath.join('.')} (Value: ${val})`)
28
- }
29
- // Check match 159 (Resting Cals)
30
- if (typeof val === 'number' && Math.abs(val - 159) < 0.1) {
31
- console.log(`>>> FOUND 159 at: ${newPath.join('.')} (Value: ${val})`)
32
- }
33
- // Check match for Training Load Peak
34
- if (typeof val === 'number' && Math.abs(val - 6079174) < 100) {
35
- console.log(`>>> FOUND 6M at: ${newPath.join('.')} (Value: ${val})`)
36
- }
37
-
38
- if (typeof val === 'object') {
39
- search(val, newPath)
40
- }
41
- })
42
- }
43
-
44
- fitParser.parse(content, (error, data) => {
45
- if (error) {
46
- console.error(error)
47
- }
48
- else {
49
- console.log('Starting deep search...')
50
- search(data)
51
-
52
- if (data.sessions && data.sessions.length > 0) {
53
- console.log('\n=== SESSION OBJECT (First) ===')
54
- const session = data.sessions[0]
55
- Object.keys(session).forEach((key) => {
56
- console.log(`${key}: ${session[key]}`)
57
- })
58
- }
59
- // Explicitly check for jump-related keys
60
- if (data.jumps) {
61
- console.log('=== JUMPS OBJECT === ')
62
- console.log(JSON.stringify(data.jumps, null, 2))
63
- }
64
- // Also check for jump events in events
65
- if (data.events) {
66
- const jumpEvents = data.events.filter(e => JSON.stringify(e).includes('jump'))
67
- console.log(`Found ${jumpEvents.length} jump events`)
68
- }
69
- }
70
- })