TimCarmichael

Conquering Looping

Blog Post created by TimCarmichael Champion on Jun 20, 2019

I have been tasked with replacing some scripts written in another system with AF based calculations for multiple sites... this is not going to be a fast process. For one site, there are over 300 AF based outputs so far.

But.. more to the point.

 

One of the scripts calculates a 24-hour total of a flow; the flow goes from 0 to its terminal point and then resets to 0. The values to be used in the total are the last values below the 0. It executes a query to find a 0 value where the previous value was not zero, loops through all of these values to get the total.

 

Obviously, because there is no looping mechanism in AF, an alternate solution was required.

Simple enough for the first part: create a tag to hold the terminal values and associated analytic. When the value goes to 0, use the previous value and save it how. The terminal value tag is set to step.

 

Then to get the 24-hour total at that point... thank you PI Square for a rich array of information! (searched for an event weighted total and found the result). Create an analysis to get the TagMean for the terminal value tag for the previous 24 hours and multiply that by the EventCount for same tag, same time period.

 

The value from the legacy system is being pulled into PI, so a quick trend of the legacy and AF generated values shows they are both trending together.

Outcomes