Chapter 2 Exercises — The F1 Data Pipeline
Difficulty: ⭐ concept check · ⭐⭐ calculation or short script · ⭐⭐⭐ multi-step analysis · ⭐⭐⭐⭐ open-ended project
All data work runs offline from the book's processed files. Run scripts from the chapter directory
(part-01-physics/chapter-02-the-f1-data-pipeline/), start every new script with the standard header from
§2.1, and never call the OpenF1 or Jolpica APIs from exercise code. Where an answer is given as a number, it
comes from the book's data snapshot (OpenF1 2023–2026 through the Las Vegas GP, Jolpica 1950–2026).
Part A — Concepts ⭐
A1. Name the three layers of the book's data pipeline, say where each lives on disk, and say which script builds each of the first two.
A2. Explain the difference between a meeting_key and a session_key. Give the 2026 Las Vegas values
from §2.2.
A3. A friend says, "Jolpica is just an old version of OpenF1." Give three concrete things Jolpica has that OpenF1 does not, and three that OpenF1 has that Jolpica does not.
A4. List the five rules of the clean-lap definition. For each, give one real reason a lap might fail it.
A5. Why does the downloader save an empty list [] when OpenF1 returns HTTP 404, instead of saving
nothing?
A6. In your own words, explain why the stint-boundary fix fires mostly at Monaco, Montreal and Melbourne, and why an off-by-one lap in a stint table changes a pit-loss estimate.
A7. What is the difference between pit loss, pit-lane time and stationary time? Which of the three does the book's data contain for every stop?
A8. Why does this book not depend on FastF1, even though FastF1 is a well-designed library? Give one situation in which you would use FastF1 alongside the book's sources.
A9. "Deleted laps should always be removed from a pace analysis." Agree or disagree, with a reason that depends on the session type.
A10. Name five telemetry channels that teams record and the public car_data stream does not contain.
Part B — Calculations & Physics ⭐⭐
B1. Sample spacing. The fastest sample in car 1's 2026 Las Vegas qualifying file reads 343 km/h. The median interval between samples is 0.240 s. How far does the car travel between two samples at that speed? How does that compare with the length of a 2026 F1 car (take 5.5 m as a round figure for the exercise)?
Solution
343 / 3.6 = 95.28 m/s; × 0.240 s = 22.9 m between samples, about four car lengths at 5.5 m. Any braking point or throttle application read from this stream is uncertain by a similar distance.
B2. Trapezoid integration. Four consecutive samples are taken at t = 0.00, 0.24, 0.44, 0.72 s with speeds 180, 196, 210 and 228 km/h. Integrate the distance covered between the first and last sample.
Solution
Convert to m/s: 50.00, 54.44, 58.33, 63.33. Interval 1: (50.00 + 54.44)/2 × 0.24 = 12.53 m. Interval 2: (54.44 + 58.33)/2 × 0.20 = 11.28 m. Interval 3: (58.33 + 63.33)/2 × 0.28 = 17.03 m. Total ≈ 40.8 m. Note the unequal intervals: the trapezoid rule handles them naturally, which is why the toolkit uses it on the irregular OpenF1 stream.
B3. Integration drift. Russell's fastest lap of 2026 Australian GP qualifying integrates to 5,233.72 m.
The official lap length in data/reference/circuits_2023_2026.csv is 5.278 km. Compute the shortfall in
metres and percent. If you compared this lap with a lap that integrated 0.5 % short, how far apart would the
two "finish lines" be on an un-normalised distance axis?
Solution
5,278 − 5,233.72 = 44.3 m short, or −0.84 %. A lap 0.5 % short integrates to 5,251.6 m, so the two laps'
ends would sit about 17.9 m apart. That is why delta_time rescales both laps to the same length before
subtracting.
B4. Two versions of the 107 % rule. In a race, a driver's median green lap in her second stint is 98.400 s. The fastest lap of the race is 94.100 s. Her lap 31 takes 104.900 s. Is it clean under the book's rule? Would it survive a "107 % of the session's best lap" rule?
Solution
Book rule: 1.07 × 98.400 = 105.288 s, and 104.900 ≤ 105.288, so it passes rule 5 (if rules 1–4 also hold). Session-best rule: 1.07 × 94.100 = 100.687 s; 104.900 > 100.687, so it would be removed. In the 2023–2026 races this disagreement affects 8,258 laps.
B5. The cost of not cleaning. Pérez's 15 timed laps in the 2023 Japanese GP average 292.551 s. One of them is the 2,588.523 s lap 14. What is the mean of the other 14 laps? What is the median of all 15 (it is one of the laps listed in §2.6's hook table)?
Solution
Sum of all 15 = 292.551 × 15 = 4,388.27 s. Without lap 14: (4,388.27 − 2,588.52) / 14 = 128.55 s. The median of all 15 is 121.045 s (lap 12, the in-lap). One row moves the mean by 164 s; the median barely notices it. Even 128.55 s is far above his clean laps (about 100 s), because the other excluded laps (lap 1, safety-car laps, pit laps) are slow for real reasons too.
B6. Pit call arithmetic. At Monaco, the median green-flag pit loss is 20.67 s with the fixed stint boundaries and 18.22 s with the raw ones (2023–2026, 69 stops). Your driver leads the next car by 19.5 s (an assumed gap). What does each estimate predict, and by how much does the data error move the predicted rejoin gap?
Solution
Raw: 19.5 − 18.22 = +1.28 s, so you rejoin ahead. Fixed: 19.5 − 20.67 = −1.17 s, so you rejoin behind. The predicted rejoin gap moves by 2.45 s and flips sign. At Monaco, where overtaking is hard, that is the difference between keeping and losing the position.
B7. Units check from location. On Antonelli's 2026 Monaco pole lap, the x/y path length is 32,702 units and the integrated distance is 3,273 m. What unit is OpenF1 using? If a corner's apex is at x = 4,297, y = 716, how far is that in metres from the coordinate origin?
Solution
32,702 / 3,273 = 9.99, so about 10 units per metre: decimetres. √(4,297² + 716²) = 4,356 units ≈ 435.6 m from the origin. The origin is just a reference point of the coordinate system, not a place on track.
B8. An as-of join by hand. A lap ends at 14:32:10. Weather records exist at 14:31:02, 14:32:05 and 14:33:07. The toolkit attaches weather to laps with the nearest record within 10 minutes of the lap's start, and positions with the most recent record before the lap's end. If this lap started at 14:30:35, which weather record does it get? If position records exist at 14:32:08 and 14:32:12, which position does it get?
Solution
Weather: the record nearest 14:30:35 is 14:31:02 (27 s away; 14:32:05 is 90 s away). Position: the most recent record at or before 14:32:10 is 14:32:08. The 14:32:12 record is later than the lap end, so a backward as-of join never uses it, even though it is closer in time. "Backward" means no information from the future leaks into the lap.
Part C — Data & Code ⭐⭐–⭐⭐⭐
C1. Set up and reproduce (⭐⭐). Install the requirements, run python -m pytest toolkit/tests -q from
the book root, then run python code/03_cleaning_funnel.py from this chapter's directory. Confirm that your
images/ch02-fig-04-clean-lap-funnel.png matches the book's, and that the last funnel row reads
within 107% of stint median 84881. If your numbers differ, find out why (hint: check the built_utc time in
data/processed/openf1/_meta.json; the archive may have been rebuilt).
Expected: six funnel rows ending in 84,881 clean race laps (83.3 %) for the book's snapshot.
C2. Analyze this session: 2024 Japanese Grand Prix, race (⭐⭐). Load it with
RaceData.load(2024, "Japanese", "R"). (a) Print summary(). (b) Find the three longest laps and their track
status. (c) Count how many laps the 2024 race has with track_status == "RED", and explain why the
standing-restart lap that follows is slow but not flagged.
Expected shape: the summary shows one red flag and 0 SC periods; the three longest laps are lap 2 for three
cars at about 1,712–1,715 s, all RED. The toolkit's caveat list explains the lap-1 timestamp problem in this
race; quote it.
C3. Compare these drivers: 2026 Monaco GP qualifying, Antonelli vs Verstappen (⭐⭐⭐). (a) Run
longest_frozen_run_s on both fastest laps first. (b) Compute telemetry.delta_time(ant, ver) and plot it
with plots.speed_trace. (c) The final delta should equal the lap-time gap; check it against the results
table. (d) The delta swings much further mid-lap than at the line. Investigate whether that swing is real:
do the speed minima of the two laps line up on the distance axis? Try step_m=2 and step_m=10.
Expected: no frozen runs on either lap; final delta +0.043 s (72.094 − 72.051); the mid-lap maximum is about
+0.71 s. Your answer to (d) is a judgment, supported by a plot of both laps' corner distances from
corners_from_speed.
C4. Build the coverage check for a season (⭐⭐). Using RaceData.from_session_key in a loop over
f1data.sessions(2024, "R"), build a table of openf1_missing_laps per race. Which race has the most, and
why?
Expected: 15 of 24 races show at least one missing timed lap (mostly lap-1 times); 2024 Monaco has the most, 16, because of the lap-1 red flag (see the §2.7 Try-it box).
C5. Deleted laps in qualifying (⭐⭐⭐). Load 2026 Mexico City GP qualifying with RaceData. (a) Print
deleted_laps(). (b) Compare len(clean_laps()) with len(clean_laps(exclude_deleted=True)). (c) For each
driver, compute the best lap time from clean_laps() and from clean_laps(exclude_deleted=True). Does any
driver's best lap change? Would the order change?
Expected: 12 parsed deletions, including CAR 44 (HAM) TIME 1:23.081 DELETED - TRACK LIMITS AT TURN 13
LAP 10; clean laps 37 → 37 (every deleted lap was already outside the clean set). Report any driver whose
best changes; then explain why the results table, not a
min() over laps, is the classification.
C6. Frozen telemetry by circuit (⭐⭐⭐). Extend section 2b of code/05_telemetry_pipeline.py to report,
for every 2026 qualifying session, the share of drivers whose fastest lap has a frozen run over 2 s, and draw a
bar chart sorted by that share.
Expected: 43 of 459 laps overall (9.4 %); Suzuka worst with 17 laps, then Shanghai with 11. Title your chart with the finding.
C7. Analyze this session: 2024 Canadian Grand Prix, race (⭐⭐⭐). Adapt the Figure 2.5 code in
code/03_cleaning_funnel.py to this wet race. Add a sixth class, "wet tyres" (compound INTERMEDIATE or WET),
checked before the clean test, and colour those laps separately. Then answer: does the 107 % rule behave
sensibly when the track is drying and every lap is faster than the one before?
Expected: the race's clean share is 0.649, one of the five lowest in 2023–2026, and it has 39 wet-tyre stints. Your chart should show a downward-sloping band of intermediate-tyre laps. Discuss whether a stint median is a fair reference when the track is changing this fast; this is the problem Chapter 15 takes on.
C8. Audit the pit-stop table (⭐⭐). Using the raw Jolpica CSV (data/raw/jolpica/csv/), merge
formula_one_pitstop.csv → formula_one_sessionentry.csv → formula_one_session.csv →
formula_one_round.csv → formula_one_season.csv to recover each stop's session type, as
code/case_study_01.py does. Count stops by season and type for 2023 onward, then check that none of the
sprint-tagged stops appears in the processed race pit table (history.pitstops(year, round)); they belong in
history.table("sprint_pitstops").
Expected: sprint-tagged (SR) stops number 11 (2023), 40 (2024), 46 (2025) and 77 (2026), 174 in all,
spread over 15 race weekends, and none of them in the processed race pit table (match on year, round and
local_timestamp). Watch out for a column-name clash: the pit-stop CSV and the round CSV both have
a column called number.
Part D — Strategy & Judgment ⭐⭐⭐
D1. Call the pit stop: Montreal with a stale notebook. A colleague's notebook gives Montreal's pit loss as 17.8 s. You recognise that number. Your driver leads the next car by 19.0 s (assumed) with 20 laps left, on tyres that are 25 laps old; the car behind is on tyres 8 laps old. Decide: pit now, or stay out? Write down the decision before checking the fixed number in §2.5, then reveal.
Reveal
17.8 s is the raw-boundary median at Montreal (17.84 s). The fixed median is 20.27 s (58 stops). With the fixed value you rejoin about 1.3 s behind (19.0 − 20.27), not 1.2 s ahead. Whether you still pit depends on the tyre-age difference and how quickly you could pass on fresher tyres (Chapters 12–13 build that model), but the decision must start from the right pit loss. The first move is to ask where 17.8 came from.
D2. Design the setup: your race-weekend data environment. You'll analyse a live race weekend for your study group. Design the data setup on one page: what you download and when (practice, qualifying, race); where you store raw and processed data; which checks run automatically after each session (name at least four from this chapter); and what you will do if OpenF1 and Jolpica disagree for the session. Justify every choice with a failure mode you saw in this chapter.
Guidance
A strong answer keeps the three layers separate (raw files written atomically and never edited; a rebuild script; analysis code that only reads processed tables), and runs at least these checks after every session: the coverage check against Jolpica (holes like 2025 Miami); the stint-boundary check at circuits where the timing line is in the pit lane; deleted laps parsed from race control (for qualifying); the frozen-run test on any telemetry you plan to plot; and a zero-value test on weather inputs. It also plans for timing: Jolpica publishes after the race, so on race night you work from OpenF1 alone and re-run the cross-checks the next day. Finally, it names who decides which source wins when they disagree, and writes the decision down.
D3. Which source wins? For each disagreement, say which source you would trust and why, or what extra
evidence you would need. (a) Lap 1 times differ by 0.4 s. (b) OpenF1 has no laps 2–24 for a race; Jolpica has
them. (c) OpenF1's stint table shows one stop for a driver; Jolpica shows two pit stops. (d) The OpenF1
qualifying results table and the fastest timed lap disagree on pole.
Guidance
(a) Neither is wrong: they start the lap-1 clock differently. Pick one convention and state it; never mix sources inside one race-time sum. (b) Jolpica for lap times and positions, after checking that its totals match the classification. OpenF1 still supplies flags (race control) and compounds. (c) Neither, yet: the lap times referee it. A real stop costs about 20 s across the in-lap and out-lap; check the signature, and check the raw Jolpica session tag in case one of the "stops" is from the sprint (Case Study 1). (d) The results table, because qualifying is classified by the last part a driver reached (and by stewards' decisions), not by the fastest lap; the wet 2026 Brazilian GP is the example in the snapshot.
D4. Is a deleted lap "clean"? Your colleague is fitting tyre degradation in races and wants to remove all 1,106 deleted-but-clean race laps "to be safe". Argue for or against, and propose a test with the data that would tell you whether keeping them biases the degradation slope.
Guidance
Against blanket removal: a deleted race lap was still driven on those tyres at that pace, so dropping it
removes real information and, if deletions cluster late in stints (when drivers push), could bias the slope.
A direct test: fit the per-stint slope with metrics.degradation twice, once on clean_laps() and once on
clean_laps(exclude_deleted=True), for every race stint containing a deletion, and look at the paired
differences with a bootstrap interval. If the interval comfortably includes zero, the choice doesn't matter
for this model, and you keep the laps.
D5. What goes in the report? Your study group wants a speed-trace comparison of the top two from 2026 Japanese GP qualifying for a blog post. You know Antonelli's fastest lap has a 24.7 s frozen stretch. List three options (for example, use the lap anyway with a caveat; compare a different pair of laps; show only the section before the freeze) and choose one. Say what you would write in the caption, and what you would refuse to claim from the data.
Guidance
A defensible choice is to compare the first 60 seconds of the two laps, where both traces are live, and to say clearly that the final sector of Antonelli's lap is not usable. Comparing his second-fastest lap is also defensible if it passes the frozen-run check, but then the caption must say it isn't the pole lap. What you must not do is publish a delta trace across the frozen section: it would show a time loss in the final sector that never happened, on a lap that took pole.
Part M — Mixed / Interleaved ⭐⭐–⭐⭐⭐
M1. (Chapter 1 + Chapter 2) The lap-time integral, honestly. Chapter 1 introduced the lap-time integral
$T = \oint ds / v(s)$. If you compute it with the toolkit's distance_m, you get the lap time back exactly.
Why? Now compute it with an independent distance: the x/y path from location data (decimetres ÷ 10) on
Antonelli's 2026 Monaco pole lap, using the average speed of each pair of samples. Compare with the official
1:12.051.
Expected
With integrated distance, $ds = v\,dt$, so $\int ds/v = \int dt$: a tautology. With the x/y path (3,270.2 m), the sum is 71.849 s, 0.20 s short of the official time. Discuss where the difference could come from: speed in whole km/h, the 0.5 s tolerance of the location merge, and the samples at each end of the lap.
M2. (Chapter 1 + Chapter 2) g-forces from a frozen lap. Chapter 1 estimated longitudinal g from the derivative of speed. Compute it for Antonelli's 2026 Suzuka qualifying lap and for Piastri's. What does the frozen stretch do to the acceleration trace, and how could an automated g-force pipeline be fooled into reporting a "perfectly steady" final sector?
M3. (Chapter 1 + Chapter 2) Minimum speeds and corner radius. Chapter 1 gave the maximum cornering speed as a function of radius, with and without downforce. Using the Monaco track map (Figure 2.11), find the slowest sampled corner (44 km/h). Estimate its radius from the x/y path (fit a circle to the samples within ±30 m of the minimum). With Chapter 1's no-downforce formula and a stated 🧪 friction coefficient, is the measured speed plausible? State the sampling-resolution caveat.
M4. (Chapter 1 + Chapter 2) Speed trap vs top speed. The sampled top speed exceeds the speed trap by a median 13 km/h on the 2026 fastest qualifying laps. Using Chapter 1's force balance (thrust vs drag), explain qualitatively why a car is still accelerating at a trap placed partway down a straight. Find the 2026 circuit where the difference is largest (+44 km/h) and look at where its trap sits relative to the maximum-speed sample.
M5. (Chapter 1 + Chapter 2) A traction circle without g-sensors. Chapter 1's traction circle needs lateral and longitudinal acceleration, and the public data have neither. Build the best substitute you can for Antonelli's 2026 Monaco pole lap: longitudinal from the change in speed between samples, lateral from v²/r with r from the curvature of the x/y path. Plot one against the other. Which parts of the plot do you trust, and which are artefacts of 3.7 Hz sampling and the 0.5 s location merge? Write the caption you would publish, including what the plot cannot show.
Part E — Research & Extension ⭐⭐⭐⭐
E1. A data-quality dashboard. Extend code/case_study_02.py into a full scorecard that also covers
qualifying sessions (deleted laps, fastest-lap-vs-pole mismatches, frozen telemetry, location samples at
(0, 0)) and writes a one-page HTML report with plotly. Decide which checks are blocking (analysis should not
proceed) and which are warnings, and defend the split.
E2. FastF1 as a second opinion (requires an F1 TV subscription). If you have one, load one 2026 race and one 2026 qualifying session with FastF1 3.9 and compare, lap by lap, with the book's OpenF1 data: lap times, compounds, stint boundaries at Monaco/Montreal/Melbourne, and the lap-1 time. Report agreement rates the way §2.7 does. If you don't have a subscription, write the comparison plan and the code, and explain which result would surprise you.
E3. Reconstruct a race without OpenF1 laps. Using only Jolpica lap times and positions plus OpenF1 race
control, rebuild a full lap table for the 2025 Miami GP with the book's columns track_status, is_pit_in_lap,
is_pit_out_lap and is_clean. You will need to (1) estimate each car's line-crossing times from the race start
and cumulative lap times, (2) overlap them with the track-status windows, (3) take pit laps from the confirmed
race stops, and (4) apply the clean-lap rule. Validate your reconstruction on laps 26–57, where OpenF1's own
is_clean exists, and report the agreement rate before you trust laps 2–24.