Best way to show current days uptime in a Perspective view

I have a tag that correlates to an external companies’ mostly proprietary machine that we aren’t allowed to mess with the PLC of at all.

The tag displays a product count (ranging from 0 to about 90) in the last minute, sort of a case per minute count.

Whenever that tag goes above 5 for the first time each day, I want to start tracking it until it drops to ) for longer than an hour, and while tracking it I want to show how long it has been above 5 expressed as a percentage at the current point in the day.

Ie. if the tag goes above 5 at 5:35 am and it is currently 9:55 am I am trying to show what percent of those elapsed 260 minutes the value was at least 5.

I am currently mainly trying to do this all within the perspective view but wondering if I am better serviced running a gateway event that writes a runtime percent value each minute for me to reference in the view.

Any help or insight appreciated, sorry for probably dumb question or poor explanation.

Record the raw value into your DB once per minute with a scheduled gateway event. After that, it is just SQL with some subqueries for any given time period.