fix(scada): preserve observation fields in chart evidence
This commit is contained in:
@@ -394,6 +394,9 @@ async def execute_query(
|
||||
if hasattr(args, "field") and args.field not in units:
|
||||
gaps.append(f"Unit metadata is unavailable for field {args.field}")
|
||||
else:
|
||||
# Keep the selected field in durable evidence; `value` alone cannot
|
||||
# distinguish raw observations from cleaned observations.
|
||||
data = [{**row, args.field: row["value"]} if "value" in row else row for row in data]
|
||||
metadata = [
|
||||
r
|
||||
for device in ids
|
||||
|
||||
@@ -77,7 +77,8 @@ class ScadaObservations:
|
||||
if "time" in row and "device_id" in row:
|
||||
at = datetime.fromisoformat(row["time"])
|
||||
if start <= at <= end:
|
||||
self.values[(str(row["device_id"]), at)] = row
|
||||
observed = self.values.setdefault((str(row["device_id"]), at), {})
|
||||
observed.update({field: row[field] for field in ("monitored_value", "cleaned_value") if field in row})
|
||||
|
||||
def absent_reason(self, device: str, at: datetime) -> str | None:
|
||||
for ids, outside, start, end in self.windows:
|
||||
@@ -206,6 +207,8 @@ def verify_chart(task: dict, chart: dict, evidence: list[dict], refs: list[str])
|
||||
"历史散点只保留每日末三个对应时刻")
|
||||
continue
|
||||
record = observations.values.get((device, at))
|
||||
require(record is None or field in record, "SCADA_CHART_EVIDENCE_REQUIRED",
|
||||
f"设备 {device} 的证据未标明 {field},请重新读取明确的监测字段", refs=[device])
|
||||
actual = record.get(field) if record is not None else None
|
||||
if actual is None:
|
||||
absent = observations.absent_reason(device, at)
|
||||
|
||||
Reference in New Issue
Block a user