Workspace/Coding labs
Loading progress

Summarize validated run records

Foundation50 min

Implement summarize_runs(records). Each record must have exactly ok (bool) and milliseconds (nonnegative exact int). Return count, successes, success_rate, and mean_ms over all records. Empty input has zero counts and None for both averages. Reject malformed records with ValueError and do not mutate inputs. This small report exercises a real distinction between no observations and a measured zero success rate.

Your task

  1. Complete the starter function using the contract above.
  2. Use the examples and visible tests to check normal inputs, boundaries, and rejected inputs.
  3. Run tests to record your result, then compare with the explained reference solution.

Examples

EXAMPLE 1

Input[{"ok": true, "milliseconds": 10}, {"ok": false, "milliseconds": 30}]

Output{"count": 2, "successes": 1, "success_rate": 0.5, "mean_ms": 20.0}

Both successful and failed runs contribute to latency.
EXAMPLE 2

Input[]

Output{"count": 0, "successes": 0, "success_rate": null, "mean_ms": null}

An average without observations is undefined.
solution.pyPython 3.12