I have a tag monitoring an analog process value. It has been logged in the historian for many months. I’m displaying the value on a PowerChart.
I would like to add a label below the chart showing the amount of time the value was above a certain threshold.
Can anyone suggest a way of doing that with a history query? It would be like setting the aggregation mode to DurationOn but with a threshold of my choosing.
Many thanks.
craigb
July 24, 2022, 3:28pm
2
A very very crude way if its saved periodically is COUNT rows where value >= * poll rate.
lrose
July 25, 2022, 3:07pm
3
There is a little used/known, hidden in plain sight, capability of the historian scripting functions to accept custom aggregates. Custom Tag History Aggregates - Ignition User Manual 8.1 - Ignition Documentation
There are some restraints to their use for them to be the most performant:
The return size provided must be greater than 0
They should be used with a project script
The script must be located in the Gateway Scripting Project
The script library must have a name that starts with “shared” all lower case.
All of this is in the documentation.
Then you can provide a function similar to this to get what you are looking for.
def durationAbove(qval, interpolated, finished, blockContext, queryContext):
duration = blockContext.getOrDefault('duration',0)
lastTime = blockContext.getOrDefault('lastTime',None)
if qval.quality.isGood() and qval.value >= 200:
if not lastTime:
blockContext['lastTime'] = qval.timestamp
else:
blockContext['duration'] += system.date.millisBetween(lastTime,qval.timestamp)
blockContext['lastTime'] = qval.timestamp
if finished:
return blockContext.getOrDefault('duration',0)
Note: This is just an example and is completely untested. You’ll probably need to play around with it to get the results you want.