93 lines
3.1 KiB
Plaintext
93 lines
3.1 KiB
Plaintext
def create_home_page(self):
|
|
self.session.custom.covert = True
|
|
fc = self.session.custom.fc
|
|
tag_provider = "[%s_SCADA_TAG_PROVIDER]" % (fc)
|
|
data_to_read = system.tag.readBlocking([tag_provider+"Configuration/PLC"])
|
|
data = system.util.jsonDecode(data_to_read[0].value)
|
|
try: devices_list = sorted(data.keys())
|
|
except: devices_list = []
|
|
|
|
if len(devices_list)>0:
|
|
instances = []
|
|
dashboard_devices = {}
|
|
for i in devices_list:
|
|
area = data[i]['Area']
|
|
if len(data[i]['Area'])>0:
|
|
|
|
dashboard_devices.update({i:area})
|
|
else:
|
|
dashboard_devices.update({i:'unknown'})
|
|
instances.append({
|
|
"instanceStyle": {
|
|
"classes": "",
|
|
"margin": "5px"
|
|
},
|
|
"instancePosition": {},
|
|
"tagProps": [
|
|
i,
|
|
"value",
|
|
"value",
|
|
"value",
|
|
"value",
|
|
"value",
|
|
"value",
|
|
"value",
|
|
"value",
|
|
"value"
|
|
],"Counts":{"Diag":0, "High":0, "Low":0, "Medium":0},
|
|
"area":data[i]['Area'],
|
|
"subarea":data[i]['SubArea']
|
|
})
|
|
self.custom.Devices = sorted(dashboard_devices.items(), key=lambda x:x[1], reverse = False)
|
|
self.getChild("FlexRepeater").props.instances = sorted(instances, reverse = False)
|
|
|
|
def get_counters(alarm_counters, controller):
|
|
counters = alarm_counters.get(controller,{"High":0, "Medium":0, "Low":0, "Diagnostic":0})
|
|
return counters
|
|
|
|
|
|
def get_device_values(tag_provider, devices_list):
|
|
tag_paths_to_read = []
|
|
read_values = []
|
|
for device in devices_list:
|
|
tag_path = "%s%s/ALARMST" % (tag_provider, str(device[0]))
|
|
tag_paths_to_read.append(tag_path)
|
|
values = system.tag.readBlocking(tag_paths_to_read)
|
|
for i,j in enumerate(values):
|
|
value = values[i].value
|
|
if value == None:
|
|
read_values.append(0)
|
|
else:
|
|
read_values.append(value)
|
|
return read_values
|
|
|
|
|
|
def update_home_status(self):
|
|
orderBy = self.session.custom.alarm_filter.orderby
|
|
fc = self.session.custom.fc
|
|
tag_provider = "[%s_SCADA_TAG_PROVIDER]" % (fc)
|
|
alarm_counters = system.tag.readBlocking([tag_provider + "System/device_count"])[0].value
|
|
counters_decoded = system.util.jsonDecode(alarm_counters)
|
|
if not counters_decoded:
|
|
counters_decoded = {}
|
|
devices_list = self.custom.Devices
|
|
values = get_device_values(tag_provider, devices_list)
|
|
|
|
devices_only = []
|
|
for device in devices_list:
|
|
devices_only.append(str(device[0]))
|
|
|
|
if orderBy == True:
|
|
zipped_list = zip(values, devices_only)
|
|
else:
|
|
zipped_list = sorted(zip(values, devices_only), reverse = True)
|
|
|
|
devices_sorted = [y for x, y in (zipped_list)]
|
|
for i,j in enumerate(devices_sorted):
|
|
counters = get_counters(counters_decoded, j)
|
|
self.getChild("FlexRepeater").props.instances[i].tagProps[0] = j
|
|
self.getChild("FlexRepeater").props.instances[i].Counts.Diag = counters.get("Diagnostic")
|
|
self.getChild("FlexRepeater").props.instances[i].Counts.Low = counters.get("Low")
|
|
self.getChild("FlexRepeater").props.instances[i].Counts.Medium = counters.get("Medium")
|
|
self.getChild("FlexRepeater").props.instances[i].Counts.High = counters.get("High")
|