apopt.comCBE 493R Data-Driven Athletics

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.

  1. 1Gather (used)
  2. 2Statistics (used)
  3. 3Visualize
  4. 4Cleanse
  5. 5Features
  6. 6Balance
  7. 7Scale
  8. 8Split
  9. 9Deploy
  1. Ask
  2. Collect (this week)
  3. Check (this week)
  4. Interpret
  5. Coach
  6. Reassess

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

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.

PythonA pace function and three known cases

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.

PythonMoving pace and elapsed pace for 19 runs

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?

PythonCheck the file's pace column

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

PythonMoving against elapsed pace, run by run

Show the expected result without running
slowest elapsed pace 16.3 min/km on 2026-05-16
Pace in minutes per kilometer for each of the 19 runs in date order, two markers per run. The moving pace sits between about 4.6 and 6.0 minutes per kilometer; the elapsed pace is the same on non-stop runs and far slower, up to about 16 minutes per kilometer, on runs with long stops.

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

  1. Why is one mile in 8:00 a good third test case for a pace function?

  2. A pace column reads 5.5 min/km. What is that in minutes and seconds?

  3. A 10 km run took 50 minutes of moving time and 62 minutes elapsed. What is the elapsed pace, in seconds per kilometer?

    s/km

0 of 3 answered · 0 right the first time

References

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.