Zoox telemetry can contain a time-ordered stream of measurements such as planning latency or actuator delay. Implement a one-pass function that summarizes the stream without materializing all samples.
Each sample is a (timestamp, value) pair. The value at sample i is considered active from timestamp[i] until timestamp[i + 1]; the final sample contributes no duration because its ending time is unknown.
Return a dictionary containing the sample count, arithmetic mean, population standard deviation, minimum, maximum, total observed duration, duration spent strictly above a supplied threshold, the fraction of observed duration above that threshold, and the longest consecutive above-threshold duration. For an empty stream, return None for value-based metrics and 0 for duration-based metrics.
Implement stream_metrics(samples, threshold), where samples is an iterable of strictly increasing numeric timestamps and numeric values, and threshold is numeric. Return a dictionary with keys count, mean, stddev, min, max, observed_duration, above_threshold_duration, above_threshold_fraction, and longest_above_threshold_duration.
Use population standard deviation. A value equal to threshold is not above the threshold.
samples contains zero or more samples.threshold are finite numeric values.def stream_metrics(samples, threshold):