I can get the alarms dataset from an Alarm Journal component using alarmJObj.alarms
, but it looks like I only get a fixed-column dataset back. They don’t contain all of the available fields or the fields that I’m showing (for example Label and Name aren’t in there which are important). The fields returns are:
EventId Source DisplayPath EventTime EventState Priority IsSystemEvent
How can I get all fields and/or the fields I’m displaying in the actual journal?
1 Like
Disclaimer: Subject to break if we ever change the internal field name (which is unlikely to happen, but still). I’ll leave putting this into a dataset or something else as an exercise for the reader
from org.apache.commons.lang3.reflect import FieldUtils
ajt = event.source.parent.getComponent('Alarm Journal')
model = FieldUtils.readField(ajt, "model", True)
for row in range(model.rowCount):
for col in range(model.columnCount):
print model.getColumnName(col), model.getColumnClass(col), model.getValueAt(row, col)
2 Likes
Awesome, thanks Paul!
This is what I ended up using
from org.apache.commons.lang3.reflect import FieldUtils
ajt = event.source.parent.getComponent('Alarm Journal')
# do some magic to get the alarm journal full dataset
model = FieldUtils.readField(ajt, "model", True)
# define the headers that we want to export
exportHeaders = ['eventId'
,'Event Time'
,'Display Path'
,'Name'
,'Event State'
,'Priority'
,'Event Value'
,'isSystemEvent'
,"Ack'ed By"
,'Ack Notes'
,'Label'
,'Current State'
,'Source Path']
data = []
for row in range(model.rowCount):
# create a dictionary of all field values
dataDict = {}
for col in range(model.columnCount):
dataDict[model.getColumnName(col)] = model.getValueAt(row, col)
# append only the headers we want to the `data` list
data.append([dataDict.get(header, 'INVALID') for header in exportHeaders])
ds = system.dataset.toDataSet(exportHeaders, data)
start = system.date.format(event.source.parent.getComponent('startDate').date, 'YYYYMMdd_HHmm')
end = system.date.format(event.source.parent.getComponent('endDate').date, 'YYYYMMdd_HHmm')
filename = 'Alarm History Export %s to %s' % (start, end)
filepath = system.dataset.exportCSV(filename, True, ds)
if filepath is not None:
system.gui.messageBox("Successfully export the current history to '%s'." % filepath, 'Export Completed')