Filter Alarm Status Table

Hello!!

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??

Here is a pic of my script

I believe it is camel case so 'displayPath'

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.

1 Like

Hello Sr,

Got it, thank you for you answer an I appreciate the advices about the code, promise next time I will add the code to the comments.

I did your code, but it did not work, think it was because of "any" when I put it in ignition, ignition does not recognize it.

I used the "get" at the alarmEvent because as you can see at the pic the extension function use the get and into it the property name

When I use the alarmEvent.displayPath it brings me all the alarms and not the filter ones

Did it and did not work

You'll need to provide more detail than just that. Copy the full error messages and paste here as pre-formatted text.

1 Like

Whatever the error you got was, it would be very odd that any() wouldn’t be ‘recognized’. I use it all the time in ignition.

It’s quite possible that there is an error in my code, as I did not test it, it is also quite likely that there is some type of copy/paste error.

As Phil suggested, provide the error messages and we can give guidance as to how to clear them up.

Ok This is my code at this moment. Something simple as:

def filterAlarm(self, alarmEvent):
	displayPath = alarmEvent.get('displayPath')
	
	Nodo1Selected = self.custom.Nodo1
	
	if displayPath == 'Nodo 1' and Nodo1Selected:
		return True
	else:
		return False

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.


There are two pictures where in one I'm using "label" and in the other one I'm using "displayPath" as a propertyName

Your displayPath is coming back as a stringPath,
You need to compare it as a string
displayPath = str(alarmEvent.get('displayPath'))

2 Likes

This will work:

def filterAlarm(self, alarmEvent):
    displayPath = alarmEvent.displayPath.toString()
    Nodo1Selected = self.custom.Nodo1

    if displayPath == 'Nodo 1' and Nodo1Selected:
        return True
    return False

I tested this and it works as expected.

For what it's worth you could just use alarmEvent.label too. That worked in your example because the AlarmEvent.getLabel() returns a string.