Group by on a Dataset

Hi hello.

I have a issue regarding to the dataset obtained from a Tag History.

Im using this script:

endTime =event.source.parent.getComponent(‘Date Range’).endDate
startTime = event.source.parent.getComponent(‘Date Range’).startDate

data = system.tag.queryTagHistory(paths=["[default]L7/PNT/AlarmsMonitor/TransactionGroups/Spur05/Trigger_Spur05"], startDate=startTime, endDate=endTime , returnSize=0, aggregationMode = “Count”, columnNames = [“TimeStamp”, “Count”])

formattedData = system.dataset.formatDates(data, “HH:00”)
event.source.parent.getComponent(‘Power Table 1’).data = formattedData

The Information display like this:

Dataset Obtained form the TagHistory:
TimeStamp|Count|
|06:00|0|
|07:00|1|
|07:00|0|
|07:00|1|
|07:00|0|
|07:00|1|
|07:00|0|
|08:00|1|
|08:00|0|
|08:00|1|
|08:00|0|
|10:00|1|
|10:00|0|
|10:00|1|
|10:00|0|
|10:00|1|
|10:00|0|
|12:00|1|
|12:00|0|
|12:00|1|
|12:00|0|
|12:00|1|
|12:00|0|

Exists a script to group the dataset information by TimeStamp, and count all the number “1” on the column Count, just like the same Functtion “group by” that we use on SQL query.
“Example:”
TimeStamp|Count|
|07:00|5|
|08:00|2|
|09:00|10|

Thanks for your help and sharing knowledge

You might get what you want by using intervalHours=1 as an argument in queryTagHistory. If you do that I’m not sure you need returnSize.

1 Like

Thanks My friend . it woks.

This is the script:

endTime =event.source.parent.getComponent(‘Date Range’).endDate
startTime = event.source.parent.getComponent(‘Date Range’).startDate

data = system.tag.queryTagHistory(paths=["[default]L7/PNT/AlarmsMonitor/TransactionGroups/Spur05/Trigger_Spur05"], startDate=startTime, endDate=endTime, aggregationMode = “Count”, columnNames = [“TimeStamp”, “Count”], intervalHours = 1)

formattedData = system.dataset.formatDates(data, “HH:00”)
event.source.parent.getComponent(‘Power Table 1’).data = formattedData

And the data will look like this:

Thanks for your time.

Regrads

I’m glad it works. It’s nice when there’s easy fixes!

1 Like