
Boss
Boss: The Streaming Observatory

Boss Fight!
Every passing test breaks a shield.
High on Skyreach Isle, the Observatory's star-log never stops growing. It is far too big to load into memory at once, and its lantern-lens flickers whenever someone tries. Pip needs a lazy pipeline that reads it one line at a time.
Each log line looks like HH:MM STATUS STAR MAGNITUDE:
21:05 OK vega 0.03
21:40 ERR lens fogged
Assignment
Build the pipeline in four stages:
read_lines(stream): a generator that takes any iterable of raw lines (a list, a file, an endless stream...) and yields each line with whitespace stripped, skipping blank lines and lines starting with"#".parse(lines): a generator that yields a dict{"hour": 21, "star": "vega", "mag": 0.03}for each valid observation. Skip any line that doesn't have exactly 4 parts, isn't status"OK", or whose magnitude isn't a number.hourly_counts(records): return a list of(hour, count)tuples, grouping consecutive records with the same hour (usegroupby).observatory_report(stream): connect the three stages and return the hourly counts.
Every stage must be lazy: it should work even on an endless stream.
Build the pipeline in four stages:
read_lines(stream): a generator that takes any iterable of raw lines (a list, a file, an endless stream...) and yields each line with whitespace stripped, skipping blank lines and lines starting with"#".parse(lines): a generator that yields a dict{"hour": 21, "star": "vega", "mag": 0.03}for each valid observation. Skip any line that doesn't have exactly 4 parts, isn't status"OK", or whose magnitude isn't a number.hourly_counts(records): return a list of(hour, count)tuples, grouping consecutive records with the same hour (usegroupby).observatory_report(stream): connect the three stages and return the hourly counts.
Every stage must be lazy: it should work even on an endless stream.
main.py Python sleeping
Press Run to try your code, then Check to test it.