I would like to be able to obtain a dataset of available timestamps from the historian to display on a data range component using the Data Density property.
Basically exactly how the Easy Chart does here in red:
I don’t see a way to get this data from a Tag History binding so I think it will need to be scripted. What is the most efficient way to get this data from the historian?
SELECT
eventtime
FROM
alarm_events
WHERE
eventtime BETWEEN '{Root Container.Date Range.outerRangeStartDate}' AND '{Root Container.Date Range.outerRangeEndDate}'
ORDER BY
eventtime ASC
queryTagDensity only returned the count of the tag for the range given - so I would have to call it a lot of times to fill in the Data Density.
After taking a fresh look at this, I ended up solving this by binding a custom property dataset to a Tag History query return the Percent Good aggregation and a 10,000 fixed sample size (any less and the data density will look choppy). Surprisingly the performance was pretty good for this.
I then wrote a propertyChange script that whenever the above custom property changes creates a new dataset multiplying the Percent Good by 100 and then assigns this to the Date Range components densityData property. I also store the time stamp of the last good value in a custom property for other uses. Script is like this:
if event.propertyName == 'Density':
density = event.source.Density
rows = []
for i in range(density.getRowCount()):
percentGood = density.getValueAt(i, 'weight')
timeStamp = density.getValueAt(i, 't_stamp')
if percentGood > 0:
event.source.LastValidDate = timeStamp
row = [timeStamp, percentGood * 100.0]
rows.append(row)
event.source.densityData = system.dataset.toDataSet(['t_stamp', 'weight'], rows)