Your question is Clean and Normalize Data Streams. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Amgen's laboratory systems can emit sample events with inconsistent field names, capitalization, whitespace, timestamp formats, and numeric units. Implement normalize_stream to clean a batch of incoming event records and return only valid, canonical events.
Input is a list of dictionaries. Each record may use these aliases:
event_id or idsample_id or sample or specimen_idstatus or statedose_mg or dosetimestamp or timeReturn a list of dictionaries with exactly these keys: event_id, sample_id, status, dose_mg, and timestamp.
Normalize values as follows:
complete and completed to completed, in-progress and processing to in_progress, and failed and error to failed."12.5 mg", "1,000", or numeric values into nonnegative floats. Missing doses become None.Z.event_id, keep the last valid record while preserving the order of each event's first appearance.def normalize_stream(records):