system.tag.queryTagHistory with multiple aggregate modes

Hello,

I’m trying to collect minimum, maximum, average and deviation values from tag history (basically to gather this aggregated data from each individual production run and to store it into a SQL table for that production run) and ultimately to move these values into an SQL table using a transaction group.

I know that with a report, I can generate this data relatively easily all at once using the “Tag CalculationQuery”. I’m not sure though how to use those values generated for the report can be used elsewhere as data. I’ve found the “system.tag.queryTagHistory” function, but I’m not sure if I can use multiple aggregate modes in the same query. Also, once I generate the dataset with the query, how to I collect the individual values from the dataset?

Currently, I have a table with the following script on mouseClicked:

endTime = event.source.parent.getComponent(‘Date Range’).endDate
startTime = event.source.parent.getComponent(‘Date Range’).startDate
dataSet = system.tag.queryTagHistory(paths=[’[default]Machine1/Annealer/OvenTemp1’], startDate=startTime, endDate=endTime, returnSize=1, aggregationMode=“SimpleAverage”, returnFormat=‘Wide’)
event.source.Returned = dataSet

The dataset is assigned to “Returned”, which I have set as a custom property on the table. The data is then linked to the custom property. I actually don’t even need this data in a viewable table, I just trying to figure out how to gather this data from the queries.

Any help is greatly appreciated.

Thanks,
Russ

I think you should use system.tag.queryTagCalculations().

Your code changed to give the values your looking for would be:

endTime = event.source.parent.getComponent('Date Range').endDate
startTime = event.source.parent.getComponent('Date Range').startDate
dataSet = system.tag.queryTagCalculations(paths=['[default]Machine1/Annealer/OvenTemp1'],calculations=['Minimum','Maximum','SimpleAverage','StdDev'],startDate=startTime,endDate=endTime)
event.source.Returned = dataSet
4 Likes

Also, once I generate the dataset with the query, how to I collect the individual values from the dataset?

You can access any value in a dataset with getValueAt, i.e.:

dataSet.getValueAt(rowIndex,columnIndexOrName)
1 Like

Thank you, I didn’t realize that function was available outside of the reports!
image

Excellent, thank you!

@jonathan.taylor can we also store that value in a tag using system.tag.writeblocking ?

What would stop you from doing whatever you want with that value once you have it ?

When i am running this script in ignition's console its running and printing perfectly but when i was trying to send specific data set value in a memory tag by using "system.tag.writeBlocking" it is not writing on that tag.

Then show us what doesn't work, not what does.

There's no reason you can't use writeBlocking to write that value to a tag, as long as you have write permissions.