Small CLI to process a .fit activity file and print a compact JSON summary.
This binary was extracted from an AWS Lambda function. It decodes a FIT file, extracts activity records, runs the existing analysis logic, and prints a JSON object with only the fields you care about.
The CLI prints the following JSON fields:
HeartAnalysis(map / zone buckets)ElevationGain(float)StoppedTime(seconds)ElapsedTime(seconds)NormalizedPower(float)PowerAnalysis(map / zone buckets) The CLI may also include these additional fields when available:SimplifiedCoordinates(array of [lon, lat, elevation] points)SimplifiedDistances(array of distances aligned with simplified coordinates)SimplifiedElevations(array of elevations aligned with simplified coordinates)
- Go 1.20+ (module-aware). Ensure
gois on your PATH. - Run commands from the
srcdirectory (this repository's CLI package lives here).
To build a local binary:
cd /path/to/.../processFitFile/src
go build -o processFitFileYou can run without building:
# run against the included fixture
go run . --fit fixtures/Morning_Ride-8.fit
# or with a built binary
./processFitFile --fit fixtures/Morning_Ride-8.fitRun all tests across the module (root and subpackages):
go test ./...Verbose output:
go test -v ./...Run a single test (by name pattern):
go test -run TestName ./...Run tests in a specific package (from repo root):
go test -v . # root package
go test -v ./fitHelper # example subpackageWith race detector:
go test -race ./...Coverage summary and HTML report:
go test -coverprofile=coverage.out ./...
go tool cover -func=coverage.out
go tool cover -html=coverage.outNotes:
- Ensure Go is installed and your working directory is the repository root.
- Some tests may read from
fixtures/ortestdata/; paths are relative to the package under test.
The program prints a single JSON object to stdout. Example (trimmed):
{
"HeartAnalysis": { "1": 255, "10": 255, ... },
"ElevationGain": 0,
"StoppedTime": 15899,
"ElapsedTime": 35276,
"NormalizedPower": 183.89182,
"PowerAnalysis": { "1": 738, "10": 607, ... }
}If the CLI includes the optional simplified timeseries, the output can also contain:
"SimplifiedCoordinates": [[-122.4, 45.5, 123.4], [-122.401, 45.501, 124.3], ...],
"SimplifiedDistances": [0, 12.3, 24.6, ...],
"SimplifiedElevations": [123.4, 124.3, 125.0, ...]main.gois the CLI entry. It reads the.fitfile, callsProcessActivityRecords, and prints the requested JSON fields.process.gocontains the activity processing logic (power, cadence, simplification, etc.).fitHelperdecodes the FIT file and returns afit.ActivityFile.- The program reuses existing
dynamotypes for the shape of analysis results.
- Units: Elevation/Distance conversions follow the original code. If you want different units, we can change conversions in
process.go. - Output file: I can add a
--out <file>flag to write the JSON to disk. - Tests: Add small unit tests for
ProcessActivityRecordsto guard behavior on small fixture files.
You can validate the CLI output against the included JSON Schema. A schema is available at src/output.schema.json and matches the fields printed by the CLI (including the optional simplified arrays).
Example validation with ajv (recommended):
# install ajv-cli if you don't have it
npm install -g ajv-cli
# validate output.json against schema
ajv validate -s output.schema.json -d output.json --strict=falseThe schema is also embedded below for quick reference.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"properties": {
"HeartAnalysis": { "type": "object", "additionalProperties": { "type": "integer" } },
"PowerAnalysis": { "type": "object", "additionalProperties": { "type": "integer" } },
"ElevationGain": { "type": "number" },
"StoppedTime": { "type": "integer" },
"ElapsedTime": { "type": "integer" },
"NormalizedPower": { "type": "number" },
"SimplifiedCoordinates": {
"type": "array",
"items": { "type": "array", "minItems": 3, "maxItems": 3, "items": { "type": "number" } }
},
"SimplifiedDistances": { "type": "array", "items": { "type": "number" } },
"SimplifiedElevations": { "type": "array", "items": { "type": "number" } }
},
"required": ["HeartAnalysis","PowerAnalysis","ElevationGain","StoppedTime","ElapsedTime","NormalizedPower"]
}If you want any changes to the JSON shape or extra CLI flags, tell me which fields or flags and I will add them.