Metrics ingestion: JSON objects with metric name, source and value are streamed in; implement a method that returns the average of all metrics for a given name and source (keep running count/total per name+source).
Asked in the coding (CodePen) stage. The input is a list of metric objects, each with string fields name and source and numeric field value. Return the average as a float, or None when no matching metric exists. Reported follow-up: How would you use mutexes to achieve eventual consistency?
Function: average_metric(metrics, name, source)
def average_metric(metrics, name, source):