Creating report from alarm data - getting user who acknowlegded alarm and when?

Thank you for clearing that up, that makes a lot of sense.

So given that, how can I better represent the time the event first started and when it was cleared of an alarm? Right now my script looks like

def generateAlarmDataForFullDay(day):
	"""
	Get's all alarms for a specified day and creates a report that is put into a mapped drive folder.
	Args:
		day: datetime object from a calendar component that will be used to determine what days to use in calculation
	Returns:
		DataSet - to be utilized by the reporting module
	"""
	logger = system.util.getLogger("Alarm Report Data Logger")
	beginningOfDay, endOfDay = dates.getMidnightToMidnight(day)
	allAlarmData = system.alarm.queryJournal(startDate=beginningOfDay, endDate=endOfDay, includeSystem=False)
	headers = ['Alarm Occured At', 'Alarm Cleared At', 'Alarm Name', 'User Logged In']
	rows = []
	for i, alarmRecord in enumerate(allAlarmData):
		alarmOccuredAt = alarmRecord.get(CommonAlarmProperties.EventTime)
		alarmClearedAt = alarmRecord.get(CommonAlarmProperties.ActiveTime)
		# Step 0 - get name of alarm
		alarmName = alarmRecord.getName()
		# Step 1 - Way to differentiate between start of alarm and clearing of alarm, determins alarmOccuredAt and alarmCleared at columns
		queryTimeStamp=None
		# This is when alarm was cleared
		if alarmClearedAt is None:
			alarmClearedAt = alarmOccuredAt
			alarmOccuredAt = None
			queryTimeStamp = alarmClearedAt
		# this is when alarm started
		elif alarmClearedAt is not None and alarmOccuredAt is not None:
			alarmClearedAt = None
			queryTimeStamp = alarmOccuredAt
			
		# Step 2 - Chance to determine who was logged in at time
		getUserQuery = "SELECT UserName, EventName, TimeStamp FROM event_log WHERE TimeStamp<? AND EventName IN ('Login','Logout') ORDER BY TimeStamp DESC LIMIT 1"
		userData = system.db.runPrepQuery(getUserQuery, [queryTimeStamp])
		for (username, eventName, TimeStamp) in userData:
			if eventName == 'Logout':
				userLoggedIn = "Auto-Logged In User"
			else:
				userLoggedIn = username
		rows.append([alarmOccuredAt, alarmClearedAt, alarmName, userLoggedIn])
	dataset = system.dataset.toDataSet(headers, rows)
	return dataset

Which gives me data in a report table that looks like

image

I highlighted one instance, Label Head E-Stop Pressed occured and then 1 minute 28 seconds later was cleared. Is that actually true though based on my script? I am nervous I am misinterpreting the alarm objects. Tagging @JordanCClark @nminchin as I believe I have seen you both work a lot with alarms