Let's take a look at some of the analytics we have access to using AF. The first is the expression.
The expression analysis is a type of equation you can craft out your own analysis using different
functions in order to calculate whatever you're looking for. To craft the expression analysis
let's look at some guidelines. First, attributes, tag names and time stamps are written using single
quotes. Next, strings are written in double quotes. Numbers, operators and functions require
no special syntax and if you'd like to add a comment use the forward facing double slash
Let's take a look at building one of the expression analyses ourselves using PI
System Explorer. First I'll open up PI System Explorer. I've created a very simple database
in order to show you just how the basics of expressions are created. I can see I have a plant,
a production line and my asset. On my asset if I go over to the attributes tab I see that the
only thing that I have is a flow rate. What I would like to see is see the total amount of
flow that has gone out of my asset in the last hour. To begin configuring our analytics we'll
go over to the analysis tab. We'll click on create a new analysis. We can give it a name.
Over on the right I can see that the analysis type is expression and this
is what I would like to use. In order to calculate the total amount of flow
over the last hour I'm going to use the TagTot function. Over on the right hand
side you'll see all the functions that we have available. To learn more about these
different functions I recommend going to the help in PSE, let's take a look at that now.
In the help age I'll go to PI System Explorer 2017 asset analytics and
then expression functions reference. Below expression functions reference I have all
the different functions with some examples and how to use them. In my case I'm already
familiar with the function's reference and I know that I'll be using TagTot. So I can see
here using the reference that TagTot will give me the totalized value of a time integral of an
attribute's value over a specified time range; I can also convert the totalized
value from the current unit of measure to a specified unit of measure in the same class.
For the syntax I'll use TagTot then the attribute name, then the start time and then the end time
for the interval that I'm interested in. For me it'll be over the last hour. I also have the
optional parameter to change the units of measure and I also have the option to add in % good. What
this means is that if there are not enough good values then I will not calculate this expression.
Let's start building this function; there's also autocomplete that helps me craft my analysis.
As soon as I start typing there's a completion that allows me to choose from a drop-down menu.
Pressing the down arrow I can scroll through select TagTot and hit enter. It helps me build
out what I need next. I can see that I need the attribute name; for attribute names I'll need
to use single quotes, as soon as I use a single quote it pulls my list of attributes. I can hit
enter here or I can continue typing outflow rate or I can click on flow rate itself. After double
clicking it inserts flow rate in single quotes and marks it as green just like we intended.
I use a comma and then I need to specify my start and end times. I would like to do this
total as a rolling total over the last hour. To do so I will use from one hour ago until now as
my times. Timestamps are going to be passed using single quotes. That's my start time
and I'll put in my end time. I could include a unit of measure to convert to but in this case
I would like to leave it. I could also add in a percent good but I do not need to do that
in this case either. At this point I can click evaluate and see if it comes out to a regular
value and I could see if that makes sense to me. This answer does not seem right to me as
the total amount of flow that went through this device in the last hour. The TagTot
function by default assumes that the units are in a per day basis; because our flow rate is in
a per minute basis I'll need to multiply by 1440 which there are the amount of minutes
in a day. Once I do this and test the evaluate button again I can see a more expected result.
Now what might make this easier to read? This is a pretty simple calculation,
let's say I'm making something a bit more difficult and I want to make sure that I
annotate my work. I can add in a comment at the top. To have this comment stay at the top
I'll hold shift and hit enter. You'll notice that the entire top line is commented out,
then it goes into my typical function to create the TagTot. Let's say I'd like to make this a
little bit more sophisticated, one thing that I can do is save the first piece as a variable
and then later use that variable later on in the same analysis. Let's see how to do that.
I'm going to name instead of variable one, I'm going to give this a variable name of total flow
and I'll make sure not to include any spaces. If I include spaces I can't use it as a variable name;
and click add a new variable. And I'm going to use the total flow in some kind of logic.
I'll say if the total flow is greater than 50 I want this flag to be set to 1,
otherwise I want it set to 0. The autocomplete will also pick up
all the variables in the expression and I can click on evaluate to see.
In the next video we're going to explore some of the other functions
and we'll talk about different use cases for when you might use them.