So I got the code working for the second button. Although I think it could be optimized, here it is for anyone who might want it. I am iterating through a tag list and querying per tag because each tag might have multiple results and I’m not sure how to handle the result if I load a list of tags into the query.
#grab the "Power Table" dataset
tableData = event.source.parent.parent.getComponent('Power Table').data
selectedRow = event.source.parent.parent.getComponent('Power Table').selectedRow
#grab the time stamp from 1st column of the selected row from the dataset.
negBuffer = event.source.parent.getComponent('Spinner').intValue
posBuffer = event.source.parent.getComponent('Spinner 1').intValue
date = system.date.parse(tableData.getValueAt(selectedRow, 0))
#start and end date time buffer to create a time window to search.
sd = system.date.addSeconds(date, negBuffer)
ed = system.date.addSeconds(date, posBuffer)
#selects the folder to search through.
folder = event.source.parent.getComponent('Label').text
#browse through the chosen folder and queries every tag at the specified timestamp (+/- {x} second), creates oneRow, a row with 5 columns, for every flagged tag and appends each row to the list "rows".
tagPaths = []
def browse(path, filter):
results = system.tag.browse(path, filter)
for result in results.getResults():
if result['hasChildren'] == False:
tagPaths.append(result['fullPath'])
if result['hasChildren'] == True:
browse(result['fullPath'], filter)
browse(folder, {'dataType':'boolean'})
tags = tagPaths
rows = []
for tag in tags:
check = system.tag.queryTagHistory(paths=[tag], calculations=['Count'], startDate=sd, endDate=ed)
#if a change in state is detected, append a new row with the tag path, the tag name, timestamp, value changed to, and documentation.
if check.rowCount >= 1:
for x in range(check.rowCount):
doc = system.tag.readBlocking([(tag.toString() + ".Documentation")])
name = system.tag.readBlocking([(tag.toString() + ".Name")])
oneRow = [tag.toString(), name[0].value, check.getValueAt(x,0), check.getValueAt(x,1), doc[0].value]
rows.append(oneRow)
#Create the headers and datset. Populate 'Power Table 1' with the dataset.
headers = ['Path', 'Name', 'Time Stamp', 'Value Changed To', 'Documentation']
data = system.dataset.toDataSet(headers, rows)
table = event.source.parent.parent.getComponent('Power Table 1')
table.data = data
event.source.parent.parent.getComponent('Power Table 1').data = data