Add per-area alarm breakdown (Areas tab + AreaCard), disable sim tick

New area_breakdown() calc groups top-5 alarm sources by plant area for
a new Areas tab / AreaCard component. Disabled AlarmSimTick so it stops
generating data during dev.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-22 07:38:02 -05:00
parent 4b07272556
commit 5f8c06ca80
9 changed files with 439 additions and 2 deletions

View File

@@ -536,6 +536,40 @@ def heatmap(instances, opts=None):
"max_count": mx, "total": total}
def area_breakdown(instances, opts=None, per_area=5):
"""Top-N most active alarm sources per plant area.
Returns [{area, total, top: [{rank, source, label, priority_name, count,
pct}]}] sorted by area total desc; pct is share of the AREA's activations."""
groups = {}
for inst in instances or []:
if inst.get("active_ms") is None:
continue
a = inst.get("area") or "unknown"
if a not in groups:
groups[a] = {"total": 0, "counts": {}, "refs": {}}
g = groups[a]
g["total"] += 1
src = inst["source"]
g["counts"][src] = g["counts"].get(src, 0) + 1
if src not in g["refs"]:
g["refs"][src] = inst
out = []
for a in groups:
g = groups[a]
ordered = sorted(g["counts"].items(),
key=lambda kv: (-kv[1], g["refs"][kv[0]]["label"]))[:per_area]
top = []
for i in range(len(ordered)):
src, c = ordered[i]
ref = g["refs"][src]
top.append({"rank": i + 1, "source": src, "label": ref["label"],
"priority_name": ref["priority_name"], "count": c,
"pct": 100.0 * c / g["total"] if g["total"] else 0.0})
out.append({"area": a, "total": g["total"], "top": top})
out.sort(key=lambda x: (-x["total"], x["area"]))
return out
def priority_distribution(instances, opts=None):
o = opts_merged(opts)
raw_counts = {}
@@ -727,6 +761,7 @@ def _assemble(instances, active_now, shelved_count, start_ms, end_ms, now_ms,
par = pareto(current, o)
prio = priority_distribution(current, o)
heat = heatmap(current, o)
areas_top = area_breakdown(current, o)
# prior mirrors (cheap subset for deltas)
p_start = start_ms - (end_ms - start_ms)
@@ -800,6 +835,7 @@ def _assemble(instances, active_now, shelved_count, start_ms, end_ms, now_ms,
"heatmap": heat,
"mtta_mttr": mm,
"pareto": par,
"areas_top": areas_top,
"top_sources": top_sources(par, 5),
"chattering": chat,
"fleeting": fleet,