FreeCampus Python

Milestone Challenge: Recover the Observatory Log

Build a reproducible package that parses, validates, and summarizes a partly damaged CSV log.
Open in Colab
  • Goal: Build a reproducible package that parses, validates, and summarizes a partly damaged CSV log.
  • Estimated time: 2–4 hours of active work.
  • Before starting: Complete the milestone units and their unit challenges.
  • Keep: Your source, observed outputs, checks, and a debugging note.

This community challenge is ungraded. Use the checks to review your own work; there is no submission service or automatic grade. Completion is self-reported in this browser on this device.

1. Recover the observatory log

Create load_readings(path) and a python -m entry point. The CSV header is station,reading. Strip surrounding spaces; accept nonempty stations and finite float readings. Skip invalid rows and return row-numbered explanations alongside accepted records. Missing files, empty files, and wrong headers are fatal errors with clear messages. Summarize accepted readings by station with count and mean. Use the standard library.

Predict an ordinary result before coding. Start with the smallest part you can run and inspect. Use Colab for notebooks and the local workspace introduced in the units for packaging or command-line tasks.

2. Set up the experiment

sample_csv = """station,reading
A,10
B,20
A,14
B,bad
,8
A,nan
"""
# Save readings.csv, then implement parsing, validation, and reporting.

The starter is deliberately incomplete. Implement the contract; do not change the expected results to match an incorrect implementation.

3. Check the observable results

  1. A has count 2 and mean 12.0; B has count 1 and mean 20.0.
  2. Rows 5, 6, and 7 are rejected with distinct reasons; the header is row 1.
  3. A missing file or wrong header produces a clear fatal error.
  4. A valid header without data produces an empty summary and no rejected records.
  5. Importing the package does not read a file or print. Document a command that runs in a clean environment.

Record actual outputs beside predictions. Reduce a failure to a small example, change one cause at a time, and repeat the failed check after repairing it.

4. Change one condition

Add a station containing a comma using a quoted CSV field, and a reading of infinity. Preserve the station name but reject infinity. Explain why splitting lines on commas fails.

5. Review a hint after attempting the task

Hint: connect the relevant tools

Use csv.DictReader, enumerate starting at 2, float conversion, and math.isfinite. Separate parsing, validation, grouping, and presentation; catch expected errors at the input boundary.

6. Explain and self-review

Include the fixture, output, accepted/rejected counts, assertions, and run instructions. Explain a row-level error versus a file-level error, and save a minimal reproduction of one repaired bug.

Review path: compare your result with the contract

Check the ordinary result first, then the boundary cases and changed condition. Explain which rule justifies each result. An implementation that differs from the hint can still satisfy the contract; explain why yours does.

7. Save your work and record completion

Save the notebook or project somewhere you control. Include one decision, one failed check, its repair, and a result you can reproduce. Record completion after reviewing the checks; you can undo it later.

Not yet recorded.

Return to the milestone overview.

Back to top