Files
Stream_PHX_A7/Gateways/FE/projects/.resources/4bc42ffa1453714bc569e1ba4b8a122bcc926a0e0be305f0b119a476f9ee3692

22 lines
1.2 KiB
Plaintext

from com.inductiveautomation.ignition.common.alarming.config.CommonAlarmProperties import EventTime
priorityBGColors = {"Diagnostic":"#FFFFFF", "Low":"#7266B7", "Medium":"#F4B834", "High":"#DE7C33", "Critical":"#E22028"}
priorityTextColors = {"Diagnostic":"#222222", "Low":"#FAFAFB", "Medium":"#FAFAFB", "High":"#FAFAFB", "Critical":"#FAFAFB"}
def getTop3Alarms():
# import time
# start= time.time()
res= []
activeAlarms = system.alarm.queryStatus([], ["ActiveUnacked"], ["*"], [], [])
sortedAlarms = system.dataset.toPyDataSet(system.dataset.sort(activeAlarms.getDataset(),3,False))
formatAlarms = [{'eventid':str(alm.EventId), "label":alm.get('label'), "dispPath":alm.getDisplayPathOrSource(), "eventtime":alm.getActiveData().get(EventTime), "priority":str(alm.getPriority())} for alm in activeAlarms]
top3EventIDs = [alm["EventId"] for alm in sortedAlarms[:3]]
for eid in top3EventIDs:
for alm in formatAlarms:
if alm["eventid"] == eid:
res.append({"value":{"dispPath":alm["dispPath"],"label":alm["label"]}, "style":{"backgroundColor":priorityBGColors[alm["priority"]],
"color":priorityTextColors[alm["priority"]]}})
break
# system.perspective.print("alarm update duration %s"%(time.time()- start))
return res