I'm working in Perspective and I am trying to filter some alarms at the Alarm Status Table. So, I'm using the extension function of the table "filter Alarm". At my script I am using the alarm.Event.get() function, and the property which I want to use to filter the Alarms is 'displaypath', but when I'm using that property no one alarm is show up at the table.
So, my question is, is possible use this property with that function? If that is true, how can I use it??
Okay, first, posting only screen shots of code can be frustrating, you should post the formatted code. If you want to provide a screen shot to give more context that's great but you should always post any code in question as preformatted text.
See:
Second, you don't need to use the get() function, you can just reference the property directly.
Third, the comment above your conditional does not match what the logic is doing. It says that you want to display alarms without a matching display path, but the logic is doing the opposite of that.
Finally, your conditional can be cleaned up and optimized so you're minimizing the amount of time it takes to filter the table.
def filterAlarm(self, alarmEvent):
# Retrieve the Grupo property from the alarm event
grupo = alarmEvent.displayPath
# Correctly retrieve the checkbox selections from the view's custom properties
nodo1Selected = self.custom.Nodo1
nodo3Selected = self.custom.Nodo3
nodo5Selected = self.custom.Nodo5
possibleGrupo = ['Nodo 1','Nodo 3','Nodo 5']
# If no checkboxes are selected, show alarms with no Grupo value
if not (any([nodo1Selected,nodo3Selected,nodo5Selected])) and grupo not in possibleGrupo:
return True
# Show alarms that match the selected nodes
elif any([grupo == 'Nodo 1' and nodo1Selected,grupo == 'Nodo 3' and nodo3Selected,grupo == 'Nodo 5' and nodo5Selected]):
return True
return False
The use of the any() built-in allows for short-circuiting the evaluation, so as soon as a checkbox is seen as being true it will return instead of evaluating all options.
Once a return is evaluated, no code beyond that point will be processed, I have factored out all of your else return False statements to the end of the conditional. In python an else if condition is signaled by the elif keyword, so I have used here as well. These changes I believe make the code much more readable.
This code is at my Extension Function:Filter Alarm and I am trying to filter the alarms which have at their displayPath a parameter which is "Nodo 1". I said parameter because those tags are into a UDT, but when I try to use the displayPath as a 'propertyName' it does not work, but if I use the label or an associated data it work, it filter the alarms and show them up at the table.