In directed activity 6 we'll take a look at using the exit function to optimize conditional
calculations. Some analytics are expensive to run no matter what the optimizations made to them.
However these analytics might provide valuable enough data to justify their analytics cost. When
it comes to these analytics our best approach is to make sure they only run when truly necessary.
This has been possible for a while now with the no output function and using it in combination
with if-then-else logic. But in a recent version of asset analytics the exit function was added.
The exit function provides a much cleaner way to implement analytics that need to trigger on
certain conditions but not always execute by stopping processing the analytic and
exiting. In addition to looking cleaner it saves a few processing cycles on analytics
by not requiring checking if else logic throughout the analytic. Although less
necessary from a performance perspective, the exit function is also useful to build
analytics that execute on a slower schedule than the daily option provided by the analytic
scheduler. For example an analytic could be scheduled to only run on a certain
day of the week and exit otherwise, for something like a weekly total.
To show an example of using the exit function to optimize an analytic we'll take a look at the
high wind speed calculations analytic on our turbine template. Note that this analytic is
intended to calculate certain things if the wind speed is higher than a certain amount,
for example if equipment damage is possible and what percentage of the time the wind speed
is above a certain value. But notice that this analytic executes event triggered on any input
so adjusted wind speed and even if the wind speed is greater than 20 it still does these relatively
expensive calculations. We'll improve this with if-then-else logic and the exit function.
Next we'll add if-then-else logic to the wind speed high
variable such that it exits if the wind speed is less than 20.
Note that if the wind speed is greater than 20 this statement will return true just like before.
Once you have made that modification, preview results and notice that if the wind speed is
less than 20 when speed high displays a dash as does the equipment damage possible in high wind
speed percentage variables indicating that the function is executing and not calculating further.
We can also change the high wind percentage line to only execute if there's been more of this
by adding the has changed function to the calculation. I'm just going to paste this
in here and it's in the user manual if you want to just copy it yourself but we're using if has
changed and looking at the output variable high wind speed calculation high wind speed
percentage over the last minute, then we exit if it has changed else we go ahead and do the
conversion and the calculations to determine the percentage of time that the wind speed
is high. Next check in your changes and then we'll be ready to move on to the conclusion.