def main(originalDeviceTagpaths, deviceTagpaths, tagsToRead, tagToWrite): """ originalDeviceTagpaths: List; a list of qualified tagpaths without their provider remapped. deviceTagpaths: List; a list of qualified device tagpaths, i.e ['[default]RM2505/PHXA2_RM2505_FCU_4']. tagsToRead: List; a list of atomic tag names, i.e ['/Meta/EqName', '/Space Temperature', '/System Mode'] tagToWrite: String; the tagPath of where to write the device data, i.e '[PHXA2_IG_COMN]System/VAV' where the tag is a DynamicDeviceSet """ # Format the atomic tag name from a full tagpath. i.e: # "[PHXA2_IG_COMN]RM224/[..]/RTU_01/Space Temperature" -> "spaceTemperature" def getTagName(tagPath): name = tagPath.split('/')[-1] words = name.split() return words[0].lower() + ''.join(word.capitalize() for word in words[1:]) # Append atomic tag names to each device, returning a fully qualified tagpath. tagPaths = [] for device in deviceTagpaths: for tag in tagsToRead: tagPaths.append(str(device) + str(tag)) tagsPerDevice = len(tagsToRead) tagData = system.tag.readBlocking(tagPaths) logger = system.util.getLogger('Tagpaths Script') # batch read alarm status activeAlarmsTagpaths = list(map(lambda x: str(x) + '/AlarmSummary/ActiveAlarms', tagPaths)) # Generate tagPaths to ActiveAlarms. activeAlarmData = system.tag.readBlocking(activeAlarmsTagpaths) # Read tag data. activeAlarmData = [x.value for x in activeAlarmData] # Get .value from each QualifiedObject. activeAlarmData = list(map(lambda x: len(x.keys()) != 0, activeAlarmData)) # Check if length > 0, if true, device isAlarmed. res = [] for batchIndex in range(len(tagPaths) / tagsPerDevice): # read all tags per device startIndex = batchIndex * tagsPerDevice endIndex = startIndex + tagsPerDevice val = {'value': {}, 'style': {}} # If device is alarmed, highlight red. val['style'] = {'backgroundColor': '#FF4747', 'color': 'white'} if activeAlarmData[batchIndex] else {} # Map original tagpath without tag provider reassigned. # This is necessary for the L4 popup. originalTagpath = originalDeviceTagpaths[batchIndex] val['value']['tagPath'] = originalTagpath # Map tag name to respective tag value. for i in range(startIndex, endIndex): tagName = getTagName(tagPaths[i]) tagValue = tagData[i].value val['value'][tagName] = tagValue res.append(val) system.tag.writeBlocking(tagToWrite, system.util.jsonEncode(res))