How is ActiveDuration Calculated

I can’t seam to figure out how the built in ActiveDuration property for an alarm journal is calculated. I would have thought it would be the time between activeTime and clearTime. But it doesn’t even come close to that see attached shot. I must be missing something here.

[code]from com.inductiveautomation.ignition.common.alarming.config import CommonAlarmProperties

results = system.alarm.queryJournal(journalName=“journal”,
startDate=‘2015-10-01 06:00:00’,
endDate=‘2015-10-02 18:00:00’,
includeData=True,
includeSystem=False)
for event in results:
x = [ event.get(CommonAlarmProperties.EventId),event.getName(), event.get(CommonAlarmProperties.ActiveTime),
event.get(CommonAlarmProperties.ClearTime)
,event.get(CommonAlarmProperties.AckDuration),event.getState()]
print x[/code]


Maybe I just don’t have enough caffeine in my system yet, but I don’t see where your script is using ActiveDuration…

Oops copied wrong one there.

[code]from com.inductiveautomation.ignition.common.alarming.config import CommonAlarmProperties

results = system.alarm.queryJournal(journalName=“journal”,
startDate=‘2015-10-01 06:00:00’,
endDate=‘2015-10-02 18:00:00’,
includeData=True,
includeSystem=False)
for event in results:
x = [ event.get(CommonAlarmProperties.EventId),event.getName(), event.get(CommonAlarmProperties.ActiveTime),
event.get(CommonAlarmProperties.ClearTime)
,event.get(CommonAlarmProperties.ActiveDuration),event.getState()]
print x[/code]

Here’s the pseudocode for how ActiveDuration is calculated.

if activeTime == null return "" if clearTime == null return time between activeTime and now else return time between activeTime and clearTime endif

This seems to match your output.

Now i must not have had enough coffee.
The active time was at 07:01:34
The cleared time was at 07:01:39

ActiveDuration then should have been 5 seconds not 2 day 7 hours 28 minutes 52 seconds.

Your screen shot shows two different lines of output for your loop. The first line shows an AlarmEvent with an ActiveTime but no ClearTime, and therefore the ActiveDuration is from ActiveTime to now. The second line shows an AlarmEvent with no ActiveTime but having a ClearTime, so the ActiveDuration returned there is an empty string.

Perhaps the real question here isn’t about the ActiveDuration calculation, but why are you getting two different AlarmEvents for the same id, one with the active time and the other with the clear time?

This is my whole question. If you look at the new reporting and you use the activeDuration field you get these long “wrong” active durations.
So i decided to see if it was something weird going on it the reporting for some reason but as you can see i get the same results here.
If you look at how the alarms a logged to the database you will see the same thing you have to do the math in a sql query to get the duration because it logs active and cleared events separately. Which is how i would assume they are stored internally also. Thus it should be getting the active time for a specific eventid and the cleared time for the same eventid and getting the difference.

Unless i am totally missing something here.

I’ll make a note for the documentation people to clarify this, because I certainly wouldn’t be able to get this from the docs.

Yes, the events are stored separately because they happen at different times. (When an event happens, we just add it to the journal, rather than retrieve-edit-save.) system.alarm.queryJournal() returns the raw entries. system.alarm.queryStatus() returns the “squashed” entries. So if I change the script to [code]from com.inductiveautomation.ignition.common.alarming.config import CommonAlarmProperties

results = system.alarm.queryStatus()
for event in results:
x = [ event.get(CommonAlarmProperties.EventId),
event.getName(),
event.get(CommonAlarmProperties.ActiveTime),
event.get(CommonAlarmProperties.ClearTime),
event.get(CommonAlarmProperties.ActiveDuration),
event.getState()]
print x[/code]

I get this as output: [d9225e6c-5d88-426e-acf7-aab5ff444bb9, u'Alarm', Mon Oct 05 09:07:46 PDT 2015, Mon Oct 05 09:07:50 PDT 2015, u'4 seconds', Cleared, Unacknowledged] [9c75dcac-39de-44a1-ada8-44053cc93aa9, u'Alarm', Mon Oct 05 09:07:55 PDT 2015, Mon Oct 05 09:08:00 PDT 2015, u'5 seconds', Cleared, Unacknowledged] [6030fc33-396c-4a99-a00c-397dae0a9f1e, u'Alarm', Mon Oct 05 09:07:35 PDT 2015, Mon Oct 05 09:07:46 PDT 2015, u'11 seconds', Cleared, Unacknowledged]

Obviously you would want to add some parameters to filter down the results.

Perfect now that makes sense.

Now can you also question the developers on the reporting queries.
This will be confusing to other too i am sure.
It looks to me that they need to also add the ability to select an alarmStatus query also not just the alarmJournal query in reporting data. Because i would bet lots of people will want the alarmStatus instead of the alarmJournal.

ideas.inductiveautomation.com is the perfect place for great suggestions like this.

Glad we could get the alarm duration cleared up! :slight_smile:

One question: how can I add such output to a Table inside an image?