Course / Tutorials / Week 1 / Q-3
Quick tutorial Q-3 · Week 1 · about 15 min · Foundation
Pace from distance and time, checked three ways
Write a pace function, check it against three known cases with assert, then apply it to the instructor's 19 runs with moving and elapsed time and work out what the file's own pace column means.
- Ask
- Collect (this week)
- Check (this week)
- Interpret
- Coach
- Reassess
Download notebook ·Python file ·Read as Markdown ·Data folder ·Chapter 1 (sections 4.1)
Every cell runs in this page; the first run downloads Python (about 30 s). Nothing you load leaves your browser. Helpful first: Q-1 Run your first cell and change one number.
The decision
A runner wants to compare this week's runs with last month's by pace. Before any comparison, decide which time the pace uses and prove that the function computing it handles units.
The raw data
raw/activities.csv: one row per run, 19 runs from 10 April to 18 May 2026, with distance, moving and elapsed time, a pace column, heart rate and cadence. The instructor's own watch runs, from the course case fileathletes/jh/watch/(converted from the watch's FIT files; GPS positions removed), published under his name.
Try it
A function you can trust
Pace is time per kilometer: pace = t / (d / 1000), with t in seconds and d in meters. It is one line of code and still easy to get wrong: kilometers typed as meters, minutes as seconds, or a pace in decimal minutes read as minutes and seconds. The habit from Section 4.1.1 is to check a function against three known cases before it touches real data: one ordinary case, one round-number case, and one that tests a unit. An assert line stops the notebook if a case fails, which is what you want.
Work the three cases by hand first: 10 km in 50:00, 5 km in 22:30, and one mile (1609.344 m, exact) in 8:00.
Type a prediction to enable Run.
Show the expected result without running
10000.000 m in 50:00.0: 3.333 m/s, pace 5:00.0 /km 5000.000 m in 22:30.0: 3.704 m/s, pace 4:30.0 /km 1609.344 m in 8:00.0: 3.353 m/s, pace 4:58.3 /km all four checks pass
The mile is the case that catches a function written for kilometers: 8:00 a mile is 4:58.3 a kilometer, not 8:00. A distance of zero stops with a clear message instead of an infinite pace.
Apply it to the instructor's watch
The course's case file holds 19 of the instructor's runs from spring 2026, one row each, with the distance, the moving time (the watch stops counting while he stands still) and the elapsed time (start to finish, stops included). Compute the pace both ways.
Type a prediction to enable Run.
Show the expected result without running
date distance_km moving_time_min elapsed_time_min moving elapsed 2026-04-10 11.567 59.95 85.16 5:11.0 7:21.7 2026-04-11 14.326 69.15 80.22 4:49.6 5:36.0 2026-05-04 8.606 40.63 40.63 4:43.3 4:43.3 2026-05-04 8.674 47.74 70.52 5:30.2 8:07.8 2026-05-05 8.343 41.85 111.15 5:01.0 13:19.4 elapsed pace is slower by a median of 2:03.9 per km
The third way: the file's own pace column
The file already has a column pace_min_per_km. Which time does it use, and in which unit?
Show the expected result without running
file says 5.18 min/km; moving pace 5:11.0, elapsed pace 7:21.7 largest difference from the moving pace, all 19 runs: 0.3 s/km read as 5 min 18 s by mistake, the first run would be 7 s/km too slow
The column is the moving pace, in decimal minutes: 5.18 means 5.18 minutes, which is 5:10.8, not 5:18. Every one of the 19 runs agrees with the function's moving pace to within 0.3 s per kilometer, the rounding of the column. Reading the decimal as minutes and seconds would make the first run 7 s per kilometer slower than it was.
One chart
Show the expected result without running
slowest elapsed pace 16.3 min/km on 2026-05-16

On runs with no stops the two markers sit on top of each other. On others, stops at lights, water and conversations make the elapsed pace minutes slower. Neither is wrong; a report must say which it used.
For the athlete: "On your 10 April run you averaged 5:11 a kilometer while moving; counting the stops it was 7:22, so when we compare runs we will always use the moving pace."
With your own data
Export one of your own runs from your watch or phone app (distance, moving and elapsed time), add a row to the table, and check that your app's average pace matches one of your two paces. Which one it matches tells you how your app treats pauses.
Check yourself
Why is one mile in 8:00 a good third test case for a pace function?
A pace column reads 5.5 min/km. What is that in minutes and seconds?
A 10 km run took 50 minutes of moving time and 62 minutes elapsed. What is the elapsed pace, in seconds per kilometer?
References
- Data-Driven Athletics, Chapter 4, A Working Setup (Section 4.1) and its exercise extending the pace listing; Chapter 1, the case-file exercise on pace.
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.