I should be able to figure this out but my head is a little muzzy today.
I have the machine status logged on-change in the default historian.
I want my Perspective view to display how long the machine has been stopped (when stopped and blank when running).
The tag’s history setting has its Max Time Between Samples set to 1 hour so there could be multiple stop records and we would need to retrieve the first to know how long the machine is stopped.
How can I retrieve this t_stamp value efficiently? I could create a tag binding and run a script transform to figure it out but I’d have to retrieve quite a lot of records to be sure that I got the first stop event. That doesn’t sound smart.
I can disable the visibility if the machine is running so that part is OK.
I prefer using a dedicated table for events, not tag history. Multiple sources can share the table using a source device column. Then use a conventional query the “TOP 1” or “LIMIT 1” record from the given source device using “ORDER BY t_stamp DESC”. The primary key should be t_stamp+source.
If all you want to do is display the time the equipment has currently been down for, I would create a binding to the tags TimeStamp, then use an expression binding like secondsBetween(now(), {view.custom.tagTimeStamp}).
I use this script in a project library and a transform to display the time values as a string
Now I'm just giving the time since the run status last changed state. Set the text color to CSS variable --success for elapsed run-time and --error for elapsed stop-time. Nice!