# Results Files, Assistants and Honest Charts

Class 8, Chapter 4: Athlete Data in Python. 24 slides, about 34 minutes.

## 1. Title

Slide up while people sit down. Every app in this course writes a text file of results beside the video. Today we read a whole folder of them into one table, catch the clip that was analysed at the wrong frame rate, and practise the four steps that keep an AI assistant's code honest. Then we tell an athlete whether to trust her watch.

## 2. 1500 heart rates: a histogram before a box plot  (3 min)

Here are the strap's fifteen hundred heart rates two ways. The box plot draws five numbers: a box over the middle half, one eleven to one sixty, a line at the median, one thirty-one, and whiskers to the extremes. The histogram cuts the range into bins and counts. It shows what the box cannot: three clusters, and the top of the box, one forty to one sixty, is a range the heart passed through rather than stayed in. Draw the histogram first. And notice the caption rule: label the observation, which anyone can check against the chart, apart from the explanation, which needs other evidence.

## 3. Three ways a correct number misleads  (2 min)

Three ways a correct number makes a misleading chart. First, the truncated axis. [Ask the room.] Two sprint times, four fifty-one and four forty-two, as bars on an axis that starts at four forty. How much longer does the first bar look? [Click.] Five and a half times, for a two percent difference. A bar's length is its message, so a bar axis starts at zero. Second, two lines on two vertical scales can be made to track by choosing the scales. Give each measure its own panel. Third, whole-number heart rates stack on top of each other: nine hundred and seventy-four points on four hundred and fifty-seven places. Jitter them.

## 4. Your turn: redraw the coach's chart  (3 min)

[Three minutes, on paper, then show a neighbour.] Here is a chart every coach has sent at some point. Use Tuesday's cleaned table: A04 converted from inches, A03 once, A07 missing week one. Redraw it so the coach gets one point in five seconds, and write the caption you would send with it. A good version is a dot for each athlete in each week, or one line per athlete, the axis from zero in centimetres, and a title that states the finding. And the caption says how sure we are: one jump each, so a change of about a centimetre could be noise.

## 5. Four files beside every video  (2 min)

Every movement app has a process-a-folder page. It runs in a desktop browser, analyses every video in a folder you choose, and the videos never leave the computer. For each video it writes four files beside it: a highlight video, the report, the text results in Markdown, and a receipt in JSON. The receipt holds no measurements. It records how the analysis was run: the input, the frame rate you asked for, the rate written in the file, the rate actually used, the height that set the scale, and any warnings. It is written last. Files starting with results underscore are never treated as input and never overwritten.

## 6. Every arrow changes a unit  (1.5 min)

Every number in a results file has passed through several hands, and its unit changed on the way. On the left, a video: the camera stores frames and the rate it claims; the app finds joints in pixels, turns pixels into centimetres with the height you typed and frames into seconds with the frame rate, and writes text; your notebook turns the text back into a number. On the right, a chest strap: microvolts and one-1024ths of a second become millivolts and milliseconds. Each arrow is a place where one wrong setting changes everything downstream, silently. When a number looks wrong, walk the arrows.

## 7. The text results: one layout for every app  (2 min)

The Markdown file is meant to be read by a person, a spreadsheet and an AI assistant, so it has a fixed layout shared by every app: a title, an Analysis table of settings, a Summary, Focus areas, a Metrics table, notes, and, from the folder page, a Batch processing section with warnings. Two things to notice in the Metrics table. The value carries its unit as text, sometimes in two systems, and N A when the clip could not measure it. And the ratings: Elite, Pro, Good, where Good is the lowest. Chapter 13 comes back to that choice of word. And read that warning at the bottom: a two-second flight.

## 8. Listing 4.21: a folder into one table  (2.5 min)

Here is a whole folder read into one tidy table. For each Markdown file, load the receipt with the same name. Walk the lines; when you reach the Metrics heading, split each table row at the bars, skip the header, and take the leading number of the value cell, so thirty-two point nine centimetres slash thirteen inches becomes thirty-two point nine. Seven clips times seventeen metrics: a hundred and nineteen rows, a number you can predict before you run it. The mean jump height comes out thirty-two point five. Is that a number you would hand to the athlete? Next slide.

## 9. Check the receipts against your session log  (3 min)

The thirty-two point five mixed two weeks and included a clip analysed at the wrong rate. The receipts catch it, but only against a record you kept: the rate each clip was filmed at. Week three was filmed at a hundred and twenty; one receipt says thirty. Drop that clip, and week three is two point eight centimetres above week one. Notice what the wrong clip did and did not spoil. Its height, thirty-two point nine, is plausible, because height is scaled from pixels and stature, not time. Its flight time came out two point oh seven seconds, impossible, so the app withheld every time and speed. Keep a log: date, clip, frame rate, view, height.

## 10. Which numbers survive the wrong frame rate?  (2 min)

[Thirty seconds, hands up.] C. Reading a hundred and twenty frames a second at thirty makes every time four times too long and every speed four times too low. Distances scaled from pixels and your stature do not depend on time, so they survive. Here the flight came out impossible, so the app withheld the times. But be careful: a half-second jump filmed at sixty and read at thirty becomes a believable one-second flight, under the app's limit, and every time in the file is doubled without a warning. The safe rule: a clip whose rate does not match your log is excluded entirely.

## 11. Specify, generate, verify, defend  (2 min)

Every listing in this chapter could have been written by an assistant in seconds. They are short so you can read them, because the assistant is not responsible for the numbers you hand an athlete; you are. Four steps. Specify, with one test you computed by hand. Generate, pasting column names and a few invented rows, never the athlete's file. Verify: run the test, read every line, check one result a second way. Defend: say what the code does with an empty file or a missing value. Here is a specification for Tuesday's moving average. The test is the part you write yourself.

## 12. A test catches a plausible error  (2.5 min)

A common first answer from an assistant uses NumPy's convolve with mode same. It looks right, it is one line, and the middle values pass. [Ask: where does seventy-three point four come from?] [Click.] Mode same pads the data with zeros, so the first average is zero, zero, one twenty, one twenty-two, one twenty-five, over five. On a heart-rate trace, that is a plunge to seventy-three at the start and end of every file, exactly the kind of thing a chart shows as a fast recovery and a reader believes. The test caught it because it checked the edges. Write your hand test before you read the code.

## 13. An offset that is too good, and the prompt log  (1.5 min)

One more from the chapter. The assistant reports perfect agreement: a correlation of zero point nine eight at every shift. That is not agreement; it is a bug. A working cross-correlation has one sharp peak, as on Tuesday. A flat one means the code compared something that does not depend on the shift, usually the raw levels without the means removed. And on the right, what a prompt log line looks like: what you asked, what you got, what you changed and why. One line each. It is how a reviewer, or you in a month, can tell which choices were yours.

## 14. ``Can I trust my watch for intervals?''  (2.5 min)

The athlete who wore both devices asks one question: can I trust my watch for intervals? The poor answer is every number from Tuesday, correct and in order, and it never says yes or no. The better answer answers the question asked, first word. It puts the numbers in the units she uses, beats a minute. It states the size of the uncertainty. It gives one action: check once more on a bike ride. And it stays within scope: it judges a device, not her heart. [Ask: which sentence carries the uncertainty?]

## 15. Build step B-4: a CSV file on a canvas  (3 min)

This week your app reads a CSV file and draws one column as a line. The file is read in the browser and never uploaded, which matters when it is someone's heart rate. The module has two functions: one splits the text into a header and rows; this one scales the values to the canvas and draws them. Look at the first line inside the loop: a missing value lifts the pen, so the chart shows a gap instead of a straight line through invented data. And it prints the range, so the scale is honest. Test with a known answer: fifteen hundred rows and a peak of one seventy-four, the same as pandas.

## 16. Before Class 9  (1.5 min)

Homework nine is due at the start of next class. Open the instructor's watch archive and audit it first: missing heart rates, pauses, units and duplicates, with a change log. Then build a four-panel overview of the season where each chart makes one point, with a title that states it. Finish build step B-4 and test it on the strap file. Redraw the coach's chart from today. Read Chapter 5, sections 5.1 to 5.6: heart rate and the ECG. If you have a chest strap, bring it; if not, we will share.
