data_model: implement range_at_100 procedural field

Compute estimated full-charge range from totalRange and current SOC.
Guard against None values (_get returns None for missing keys) and
SOC = 0 to avoid TypeError / ZeroDivisionError on incomplete records.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-26 17:49:12 +02:00
co-authored by Claude Sonnet 4.6
parent 2756c6a49b
commit cdc01aaa76
+5
View File
@@ -265,6 +265,11 @@ def apply_procedural(record: dict) -> dict:
""" """
proc: dict = {} proc: dict = {}
range_at_soc = _get(record, "measurements", "rangeStatus", "totalRange", "value")
soc = _get(record, "charging", "batteryStatus", "currentSOC", "value")
if range_at_soc is not None and soc:
proc["range_at_100"] = _phys(round(100 * float(range_at_soc) / float(soc), 1), "km")
# ── add computed fields here ────────────────────────────────────────── # ── add computed fields here ──────────────────────────────────────────
# Use _get(record, "domain", "statusObject", "field", "value") to # Use _get(record, "domain", "statusObject", "field", "value") to
# safely read any nested value. Always use {"value": ..., "unit": ...} # safely read any nested value. Always use {"value": ..., "unit": ...}