In this video we're gonna walk through how to develop your functions in order
to make sure you can solve your data needs. We'll remember to use
the right syntax which we learned in the previous video. As these are all examples,
anything written in bold we can just assume is an attribute that's in our AF structure.
Before I go through all the solutions I recommend trying to sit down and developing
these yourself. After you've finished writing out the solutions take a look at
the video to compare your answers. There may be multiple ways of doing the same function;
we'll talk about the one that I think is the most direct way to get your answer. For this
first one we can see that we want to get a 10-minute rolling average of the temperature
attribute. To get a 10-minute rolling average, our hint is to use the tag average function.
Let's take a look at the tag average function in the Help section of PI System Explorer.
Again in PI system Explorer you can hit the Help button and you can navigate down to asset
analytics expression functions reference and then take a look at tag average. In this syntax we can
see we need an attribute name, a start time and an end time and an optional parameter is
a percent good. Writing this out we can see that we want to get a ten-minute rolling average for
the temperature attribute. Our attribute name in that case is going to be temperature. Our
start time is going to be ten minutes ago from now which would be star meaning now,
minus 10 M, and our end time is now to complete the ten-minute rolling average time period. We can
see that we're not asked to specify any percent good so we'll leave the optional parameter out.
Making sure that we envelop our attribute value as well as our timestamps in single
quotes we can see that if we take the tag average temperature attribute we can see
that the following function will answer our problem. Let's take a look at the next one:
get the time-weighted total for the flow in attribute over the last hour,
but only if at least 80% of the values used in the calculation are considered good. In this
case the function that we'll want to use is the TagTot function. Again looking up some of our
syntax in the help menu, we can see that we'll need an attribute name and similar to the tag
average function these start time and end time. We can also specify a two-unit and a percent good,
in this case we're going to use the percent good and make sure that we set that at 80. Let's take
a look at the solution. Again making sure that we enclose the attribute value and time
stamps and single quotes and because 80 is just a number we can leave that without any other syntax.
The third problem states how much time in the percentage of a day was the pressure attribute
between 30 and 70 excluding the time when the value is at 30 or 70 for the whole day yesterday.
Here we're going to need to combine two different functions, so our hint here shows that the TimeGT
and TimeGE. Time GT is greater than and TimeGE is greater than or equal to. Let's take a look
at one of those in the help menu. We can see that we need to specify the attribute name,
the start time and the end time, as well as X. If we look at the definition it says find the total
time within a range when an attribute value is greater than a specified value. Time returned is
in seconds. It's important to note that the time returned is in seconds and that we need to put in
a specified value. In that case the attribute name will know is pressure, the start time and end time
we can configure using yesterday and today and X represents the value that we'd like to specify.
We need to combine the greater than and greater than or equal to functions in order to make sure
that we exclude the right amount of time. In this case we're going to take the time
that the pressure attribute from yesterday at midnight until today at midnight was greater
than 30 and we'll subtract out the portion of time where it was greater than or equal
to 70. After that we'll divide by the amount of seconds in a day which is 86,400 and to make it
a percentage we'll multiply by a hundred. This is a good example to show you that you
can string together multiple functions in order to get a more sophisticated equation together.
For the last problem we would like to display overload when the level attribute is greater than
or equal to 90, normal when it's between 10 and 90 and we'd like to exclude the boundary values and
if it's less than 10 or equal to 10 we'd like you to display empty. In this case there's a few ways
that we can go about it. The way that I find to be most straightforward is using some if-then-else
logic. Taking a look at one of these conditional statements we can see it will return the second
of two specified values in the if then else statement if the conditional expression is false.
That's if you look up else in the help menu. In that case let's walk through the solution.
Notice that if I just want to specify the attribute value at the time of now,
I can just put in the attribute name. So if level is greater than or equal to 90 then
we'd like you to display overload. I'll put else if the level is less than or equal to
ten then I'll specify empty. The middle range which I haven't specified yet will now be the
only other option and there I will write normal. Take note that the string values
that I'd like to write to the value of the output are in double quotes. It is possible
to rearrange this however I believe this is the most straightforward way. If we were to
try to specify the normal level after overload we might be including too much in the range. We
would need to specify that it is both greater than or equal to 10 and less than or equal to
90 which is more difficult than just putting it in the way that I've outlined in the solution.
There are obviously many more functions to explore and I recommend taking a look at the help menu if
you'd like to get insight into using the many different functions that we have available.