How to populate the Data Density of a Date Range component with historian data

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?

Put this in Data Density:

SELECT 
	eventtime
FROM 
	alarm_events 
WHERE 
	eventtime BETWEEN '{Root Container.Date Range.outerRangeStartDate}' AND '{Root Container.Date Range.outerRangeEndDate}' 
ORDER BY 
	eventtime ASC

Unfortunately this is for historian data, not alarm events.

https://docs.inductiveautomation.com/display/DOC81/system.tag.queryTagDensity?

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)

I’m also trying to use the data density dataset to highlight where data exists for a date range object. My dates are not continuous so I manually create the density

    ds = self.getComponent('Power Table').data
	t_stamp = []
	for row in range(ds.getRowCount()):
		start = ds.getValueAt(row, 'StartDate')
		end = ds.getValueAt(row, 'EndDate')
		
		delta = system.date.hoursBetween(start, end)
		
		for i in range(delta):
			dt = system.date.addHours(start, i)
			t_stamp.append(dt)
	
	weight = [100] * len(t_stamp)
	
	data = [[t, w] for t, w in zip(t_stamp, weight)]
	headers = ['t_stamp', 'weight']
	ds = system.dataset.toDataSet(headers, data)
	self.getComponent('Date Range').densityData = ds

The problem I’m having is the highlight color is very weak even though I’ve set the high density color to 255,0,0 with no opacity.

image

How can I adjust this to get a bold red color like in the original post’s screen shot?