Skip to content

Commit

Permalink
cli: fitconv add CSV to FIT File converter (#168)
Browse files Browse the repository at this point in the history
* cli: fitconv add support for converting CSV file back into FIT file

* add copyright license
  • Loading branch information
muktihari authored Apr 9, 2024
1 parent 21db25f commit f5bbd57
Show file tree
Hide file tree
Showing 8 changed files with 2,621 additions and 50 deletions.
31 changes: 31 additions & 0 deletions cmd/fitconv/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.PHONY: build build-esc run pprof pprof-cpu pprof-mem trace took

build:
go build main.go

build-esc: # escape analysis
go build -gcflags="-m=2" main.go

run:
make build
./main $(wordlist 2, $(words $(MAKECMDGOALS)),$(MAKECMDGOALS))

pprof:
make build
./main -opt $(opt) $(wordlist 2, $(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
go tool pprof -http=:8080 $(opt).pprof

pprof-cpu:
make pprof opt=cpu $(wordlist 2, $(words $(MAKECMDGOALS)),$(MAKECMDGOALS))

pprof-mem:
make pprof opt=mem $(wordlist 2, $(words $(MAKECMDGOALS)),$(MAKECMDGOALS))

trace:
make build
./main -opt trace $(wordlist 2, $(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
go tool trace trace.out

took:
make build
./main -opt took $(wordlist 2, $(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
34 changes: 18 additions & 16 deletions cmd/fitconv/README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
# Fitconv

Fitconv converts the FIT file into a CSV file, allowing us to read the FIT file in a human-readable format.
Fitconv converts the FIT file into a CSV file, allowing us to read the FIT file in a human-readable format. And vice-versa, it converts CSV file back to FIT file allowing us editing FIT file in its CSV form using only code editor.

This is designed to work seamlessly with CSVs produced by the Official FIT SDK's `FitCSVTool.jar`.

Note:

- Currently only FIT to CSV conversion is supported, other format might be added later when necessary (or requested).
- Currently only `FIT to CSV` conversion and vice-versa (`CSV to FIT`) are supported, other format might be added later when necessary (or requested).
- When converting `CSV to FIT`, unknown message and unknown fields are both skipped since we can't get the correct value's type since we don't have any context about it.

## Usage Examples

```sh
go run main.go activity.fit activity2.fit
go run main.go activity.fit activity2.csv

# Output:
# Converted! activity.csv
# Converted! activity2.csv
# 📄 "activity.fit" -> "activity.csv"
# 🚀 "activity2.csv" -> "activity2.fit". [In total, 2 unknown messages are skipped]

ls
# activity.fit activity.csv activity2.fit activity2.csv
```

### Options

| Options | Description |
| ---------- | ----------------------------------------------------- |
| -v | Show version |
| -csv | Convert FIT to CSV (default if not specified) |
| -disk | Use disk instead of load everything in memory |
| -unknown | Print 'unknown(68)' instead of 'unknown' |
| -valid | Print only valid value and omit invalid value |
| -raw | Use raw value instead of scaled value |
| -deg | Print GPS Positions in degress instead of semicircles |
| -trim | Trim trailing commas in every line (save storage) |
| -no-expand | [Decode Option] Do not expand components |
| Options | Valid For | Description |
| ---------- | --------------- | ------------------------------------------------------ |
| -v | All | Show version |
| -disk | FIT to CSV only | Use disk instead of load everything in memory |
| -unknown | FIT to CSV only | Print 'unknown(68)' instead of 'unknown' |
| -valid | FIT to CSV only | Print only valid value and omit invalid value |
| -raw | FIT to CSV only | Use raw value instead of scaled value |
| -deg | FIT to CSV only | Print GPS Positions in degress instead of semicircles. |
| -trim | FIT to CSV only | Trim trailing commas in every line (save storage) |
| -no-expand | FIT to CSV only | [Decode Option] Do not expand components |

```sh
go run main.go -deg activity.fit activity2.fit
Expand Down
Loading

0 comments on commit f5bbd57

Please sign in to comment.