I’m experimenting with the new system.historian namespace and I’m curious how I could possibly use the function system.historian.queryAggregatedPoints() system function in order to query the tag historian and get the average value of a tag per hour over a specified time range, where each row of data returned contains a data point for the average value within each hour? I don’t see any interval parameters or sample by and can half get there using the returnSize.
Is there a key concept I am missing in relation to the system function system.historian.queryAggregatedPoints() ? or an example that shows a per hour average with a specific time range?
I seems like what you are trying to do can easly be achieved with the system.tag.queryTagHistory().
Since it is generally used for historical tag data and includes parameters that allow for interval based aggregration. Some of the parameter it has are internalHours
and aggregationMode
.
Here's an example. You'll need to calculate the hour intervals needed:
import math
end_date = system.date.now()
start_date = system.date.addDays(end_date, -1)
difference_in_seconds = system.date.secondsBetween(start_date, end_date)
total_hours = difference_in_seconds / 3600.0
hour_windows = math.ceil(total_hours)
paths = ['histprov:Historian:/prov:default:/tag:Ramp/Ramp0']
aggregates = ['Average']
result = system.historian.queryAggregatedPoints(paths=paths, startTime=start_date, endTime=end_date, aggregates=aggregates, returnSize=hour_windows)
for r in result: print r[0], r[1]