← Back to the chapter · Previous detail · Next detail →
Technical detail · Data Quality Monitoring
Normalize versioned temperature payloads
The fleet may send version 1 or version 2 temperature payloads during the same rollout. This parser maps their different field names into a shared record shape, retains the source version and unit, and rejects unknown versions.
def normalize_temperature(payload):
version = payload.get("version")
if version == 1:
return {
"schema_version": 1,
"metric": "temperature",
"value_num": payload["temp"],
"unit": "C"
}
if version == 2:
return {
"schema_version": 2,
"metric": "temperature",
"value_num": payload["temperature"],
"unit": payload.get("unit", "C")
}
raise ValueError("unknown schema version")