Rolling min, max, average for each tag

We have a customer that wants to have access to a rolling min/max/average for every tag for the last 15 minutes. What is the cleanest way to handle this? We are trying to steer away from needing a database setup but that is not out of the question. The customer in question would have around 90,000 tags.

The cleanest way would be to turn on history (with a DB) with a short pruning period. Then, where the user wants to see this, run a query for the last 15 minutes with result-size == 1 and with the averaging mode. Stuffing such data into a DB is way simpler than any other approach.

There are complicated scripting techniques that could keep it all in RAM, if you are feeling brave.

1 Like

I agree, use tag history, but I would leave the prune alone, or set to something more useable, like a year. You can then get min/max/average for the last 15 minutes, or any duration and/or start/stop of your choosing.

1 Like

Thanks for the quick response.
My current idea of doing it is creating a min/max/avg memory tag for each tag. I'm concerned that if I make a per tag script to write potentially to 3 values at a time for 90,000 tags that it could cause performance issues.Would it be better to have one massive script run on an interval or for an on-change script on each tag to run. Or is there some other way I'm unaware of that would handle this better?

Okay, but that part, or similar, is obvious.

The issue is holding 15 minutes worth of value changes somewhere so you can compute against them. You actually need to hold onto each value change and its timestamp in order to have accurate results. Every time you calculated results, you'd need to discard any samples older than the cutoff, except for the last one (if itself older than the cutoff).

Caching via top-level dictionaries in a project library script is the most convenient place to hold such, for some definition of "convenient".