Workspace/Coding labs
Loading progress

Query state with two time cutoffs

Intermediate45 min

Implement state_as_of(records, valid_at, known_at). Each record has integer valid, integer recorded, and string value. Include records with valid <= valid_at and recorded <= known_at. Return a copy of the eligible record with the greatest (valid, recorded) pair, or None. Exact duplicate records are harmless; conflicting values at the same pair are rejected across all input records. Reject noninteger time fields and nonstring values. Integer time is a synthetic teaching clock.

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

Inputrecords=[{"valid":8,"recorded":10,"value":"up"},{"valid":11,"recorded":14,"value":"down"}], valid_at=12, known_at=12

Output{"valid":8,"recorded":10,"value":"up"}

The later recorded observation was not yet known.
EXAMPLE 2

Inputsame records, valid_at=12, known_at=15

Output{"valid":11,"recorded":14,"value":"down"}

The retrospective view can include the late observation.
solution.pyPython 3.12