Trace a report total back to its rows
Run the report for September, then follow the North total back to the exact orders behind it.
2 parts · 11 and 2 min · part 1 on a computer
Free course. Your Maestro, an AI, .
In the September file, you saw that every row stands for one order. When you run the monthly Glossary word, those individual orders disappear behind regional totals in reports/history.csv and a single monthly summary in reports/latest.json. When someone asks why a region's total looks the way it does, you need to trace that figure back through the code to the exact rows of the Glossary word file that produced it.
Tracing a number's lineage means following each transformation between the raw input and the finished output. Rerunning the script only proves that the code still gives the same answer today; it does not show which rows went into the calculation. Accepting a total because it looks reasonable carries its own risk, since missing orders or a wrong filter can still land on a believable sum.
Open report.py in the workspace below and read run(month). Every figure that reaches reports/history.csv passes through four steps in order:
csv.DictReaderopensdata/sales_{month}.csvand reads every line intorowsas a dictionary.check(rows, columns, month)fromcontract.pyinspects the column list and every row'sorder_id,order_date,region, andamount. If it finds any problems,runrecords a rejected status inreports/runs.csvand stops before changing the report files.- A loop steps through
rows, convertsr["amount"]withfloat(), and adds it tototals[r["region"]]. Here the Glossary word shifts from one row per order to one sum per region. upsertformats each regional sum to two decimal places, replaces any existing rows for that month inreports/history.csv, and writes the file throughwrite_atomic.
The diagram below maps those four steps from the input file to the saved history table.
File rows in data/sales_2026-09.csv
One row per order
Contract check in contract.py
check(rows, columns, month)
Totals by region in report.py
Sum float(r["amount"]) per region
Regional rows in reports/history.csv
One row per month and region
Following the arrows forward shows how report.py builds the output; walking them backward gives you a checklist for tracing any number on the page. Start at the line in reports/history.csv, check how upsert and the totals loop grouped the amounts by region, and pull the matching orders from data/sales_2026-09.csv. If any line in report.py is hard to follow, ask your Maestro to walk through it with you.
Try it
In the workbench below, report.py and contract.py are read-only so you can inspect the exact code that runs. Run trace.py first to execute report.run("2026-09") and print reports/history.csv. Then edit trace.py to read data/sales_2026-09.csv, keep the rows where r["region"] == "North", print each order's order_id and amount, and print their sum. At the bottom of trace.py, write a comment naming the steps in report.py between those source rows and the history line.
A good place to stop. Up next: part 2 of 2 · 2 min
What your trace should show
When trace.py runs report.run("2026-09"), it prints a report total of 3000.0 and writes four regional lines for 2026-09 into reports/history.csv: East with 650.00, North with 1200.00, South with 800.00, and West with 350.00.
Filtering data/sales_2026-09.csv for r["region"] == "North" returns three orders: S-0901 with amount 500, S-0904 with amount 400, and S-0908 with amount 300. Summing those three amounts with float(r["amount"]) gives 1200.0, which report.py formats to two decimal places as 1200.00.
Your comment at the bottom of trace.py should name all four steps in order: csv.DictReader reads the rows from data/sales_2026-09.csv, contract.check checks and accepts them, the totals loop groups by region and sums float(r["amount"]), and upsert writes the month's regional rows into reports/history.csv. If your sum does not match 1200.0 or a step in the chain is unclear, share your output with your Maestro.