Course / Tutorials / Week 6 / Q-16
Quick tutorial Q-16 · Week 6 · about 15 min · Foundation
Open an activity file and list its fields
Decode a running watch's binary FIT file into plain tables, list every message and field with its units, and find the pauses before any analysis.
- 1Gather (used)
- 2Statistics (used)
- 3Visualize (used)
- 4Cleanse
- 5Features
- 6Balance
- 7Scale
- 8Split
- 9Deploy
- Ask
- Collect (this week)
- Check (this week)
- Interpret
- Coach
- Reassess
Download notebook ·Python file ·Read as Markdown ·Data folder ·Chapter 6 (sections 6.3)
2 of 3 cells run in this page. The rest need a model that does not run in the browser: run them in the notebook on your computer or in Colab (File → Upload notebook); their output from the course build is shown, and the files they write are published so the later cells still run here.
The decision
A runner sends a watch file and asks for a pace. Before any pace, find out what the file holds, in which units, and whether the watch was paused.
The raw data
raw/2026-05-14_0726_running_nogps.fit: the instructor's FIT file of a 5.9 km run on 14 May 2026, as the watch wrote it except that every position value is blanked (FIT's "no value" code), 76,615 bytes. The instructor's own watch, published under his name.prepare.pyblanks the 3,604 position values, recomputes the file's checksum, and checks that no coordinate is left.
Try it
A running watch saves each run as a FIT file: compact, binary, and unreadable in a text editor. This one is the instructor's run of 14 May 2026, the example run of Chapter 6, as his watch wrote it, except that every position value has been blanked (set to FIT's "no value" code) so the file shows no route. You will open it, list what it holds, and save it as plain tables.
Read the binary file
The first cell needs the fitdecode package, which does not run in a web page, so it runs on your computer or in Colab (pip install fitdecode). It writes three CSV files under clean/; the cells after it run here, in the page, from those files.
Decode the FIT file into tables
Runs in the notebook (needs a model that does not run in the browser). Output from the course build:
# Needs fitdecode (pip install fitdecode); runs on your computer or in Colab.
import os
import warnings
import fitdecode
import pandas as pd
warnings.simplefilter("ignore") # the watch writes one odd field definition
rows, fields, session = [], {}, {}
with fitdecode.FitReader("raw/2026-05-14_0726_running_nogps.fit") as fit:
for m in fit:
if not isinstance(m, fitdecode.FitDataMessage):
continue # skip headers and definitions
for f in m.fields:
key = (m.name, f.name)
n, unit, ex = fields.get(key, (0, f.units, None))
fields[key] = (n + (f.value is not None), unit, ex if ex is not None else f.value)
if m.name == "record":
rows.append({f.name: f.value for f in m.fields})
elif m.name == "session":
session = {f.name: f.value for f in m.fields}
os.makedirs("clean", exist_ok=True)
table = pd.DataFrame([(a, b, n, u, ex) for (a, b), (n, u, ex) in fields.items()],
columns=["message", "field", "values", "units", "example"])
table.to_csv("clean/fields.csv", index=False)
pd.DataFrame(rows).dropna(axis=1, how="all").to_csv("clean/records.csv", index=False)
pd.Series(session).to_csv("clean/session.csv", header=["value"])
print(table.groupby("message")["field"].count().to_string())message activity 7 developer_data_id 3 device_info 3 event 5 field_description 5 file_id 5 lap 27 record 18 session 27
Nine kinds of message. Most of the file is record messages, one per sample; lap and session messages are the watch's own summaries; event messages mark the timer starting and stopping. The position fields come out empty, so dropna leaves them out of the records table.
List the fields of a record
Show the expected result without running
field values units example
activity_type 1803 NaN running
timestamp 1803 NaN 2026-05-14 13:26:48+00:00
distance 1803 m 0.0
position_lat 0 semicircles NaN
position_long 0 semicircles NaN
heart_rate 1802 bpm 81
enhanced_speed 1796 m/s 1.547
speed 1796 m/s 1.547
stance_time 1796 ms 0.0
vertical_oscillation 1796 mm 0.0
vertical_ratio 1796 percent 0.0
step_length 1796 mm 810.0
Effort Pace 1796 m/s 1.5470000505447388
cadence 1794 rpm 75
power 1794 watts 115
accumulated_power 1794 watts 115
enhanced_altitude 1783 m 1445.0
altitude 1783 m 1445.0Read the units column before anything else. Distance is in metres and speed in metres per second, but cadence is in "rpm", one leg's steps a minute, so a runner's cadence is twice it. position_lat and position_long have no values here; in a file straight from a watch they are in semicircles (2³¹ of them make 180°), not degrees.
Three facts before any analysis
Type a prediction to enable Run.
Show the expected result without running
1803 records; gaps over 1 s: [3787.0, 23.0] first to last record 5610 s; watch timer 1801.7 s; distance 5880.5 m cadence field 88 per leg -> 176 steps/min

The watch was paused twice, once for more than an hour and once for 23 seconds, so the first and last records are over 90 minutes apart while the watch ran for 30. Any pace computed from the clock instead of the timer would be three times too slow. Chapter 6 (Section 6.3) reads the same file and finds the same facts.
For the athlete: "Your watch file holds 1803 one-second records of speed, heart rate, cadence and running dynamics; we saved them as plain tables and checked the pauses before measuring anything."
Action card
- Finding
- The file holds 1803 one-second records in nine kinds of message; the watch was paused twice.
- Evidence
- Gaps of 3787 s and 23 s between records; timer 1801.7 s against 5610 s from first to last record.
- How sure
- High; these are the watch's own fields and timestamps.
- Action
- Compute pace from timer time and the watch's distance, and double the cadence field.
- Test again
- Run the same three checks on every new file before analysing it.
With your own data
Export the FIT file of one of your own runs from your watch's app, put it in raw/, change the file name in the first cell and run it on your computer. Do not share a file that still has positions in it: the clean/records.csv the cell writes keeps them if your watch recorded them, so drop the position_lat and position_long columns before you share it.
Check yourself
The record's cadence field reads 88 rpm. What is the runner's cadence in steps a minute?
Why can't the browser cells open the FIT file directly?
References
- Data-Driven Athletics, Chapter 6, Activity Files (Section 6.3): what a record holds, reading a FIT file, splits and pauses.
- fitdecode, a FIT file reader for Python: github.com/polyvertex/fitdecode.
Built 2026-11-30 with Python packages numpy 2.5.5, pandas 3.1.1, matplotlib 3.11.2. In the browser the same code runs on Pyodide, so the last digit can differ.