How to determine number of alarms per custom group property?

I am working on a project were we have multiple machines across different zones of the production line. In all there are around 2000 alarms. I have defined custom property for each alarm setting the corresponding machine. At the moment Ive defined additional tags like Alarm_machineXY, Alarm_zoneXY. Those tags are used to update graphics on the screen to show which part of the line is affected. I defined event scripts on each alarm to calculate number of alarms for the machine depending on the group. script is called on acknowledge, active, clear. Now, my assumption is that event will be called only on the alarm that is changing the status. If my assumption is wrong I am potentially triggering 6000 scripts every time any of the alarms change.

Am I right to say only changing alarm script will be called ?

I am dynamically creating alarms from the DB configuration. I dont yet have working solution for adding and removing event scripts, but I believe it shouldn’t be a problem. My script is very generic and same script is called on all 3 events and from all 2000 alarms. Which means I only need to maintain single copy of the script which is re-created each time I call ReconfigureAlarm function. I do this manually when DB configuration is changed.
In the script I check the alarm group property and use that as a parameter for a tag name. I create array with counts of alarms for each severity and copy it to the tags custom property.

Output of my script is something like this:
Alarm_machine1: array severities { x, y, z, q }
Alarm_machine2: array severities { x, y, z, q }
Alarm_zoneX: array severities { sum(machines), … }

then depending on the highest severity for zone/line I can change the color of the graphics.

Is there any better way of doing this ?