I have to calculate average of a pi point in an AF attribute.
The time span however to calculate the average should come from another pi point which gives data in days.
How to do it.
You can use the ParseTime function to 'build' a timestamp using your PI point.For example, ParseTime(Concat("*-", '<attribute with the number of days', "d"))
Can you please let me know where to put/refer this function?
Attached is a snapshot.
Rick Davin your inputs are also requested.
Your 'Tag' attribute has a text entry of a tag name; update your 'Days' attribute to use the PI Data Archive and tag from 'Tag'.
What are the time ranges for your average?If it is from now to a number of days in the past, use the ParseTime function in an analysis to build your timestamp.
ParseTime(Concat("*-", 'Days', "d")) --- 'Days' it the attribute that has the tag with the number of days
Your average, in an analysis, would be TagAvg('metered tags','*','<parsed time>') --- the 'parsed time' is the timestamp just built and assigned to a local variable.
Finally, the average needs to be written back to an attribute with a PI tag.
Can you please tell me what is the "metered tags"?
I have performed the task as suggested by you. I think it is showing some contextual error?
Attached snapshots Rick Davin Yours inputs are also requested
Since it is asking for an example element, I assume this is built from template.
Click on the 'Select an example element' and select an element built from the template.
Then, click on 'Evaluate' to see what the results are.
These are the results on doing evaluation of an element from the same template.
Attached for reference:
Need your guidance.
In the top image, variable Local is a DateTime value being saved to an output PI Point via attribute Code1. I presume the underlying tag to Code1 is being used to trigger the bottom analysis.
The best guess of what's not working is that the underlying PI Point for Code1 is has a data type of Single (or Float32). This will cause an implicit conversion from DateTime to a Single representing seconds. Note that it would be a unitless scalar value.
I personally wouldn't have 2 analyses as this. If A triggers to output to B, which then causes B to trigger to output to C, then really A has triggered both B and C. You may as well have 1 analysis, and I see no real need to output to Code1, as it seems to be only an intermediate value.
Dear Rick Davin & Tim Carmichael,
Thanks for your help on this. Really appreciate!
By putting these into one analysis and referencing Variable 1 (Timestamp) to Variable 2 (TagAvg) which is mapped to an attribute with Pi tag works perfectly fine.
Great learning here!
I'm glad the combined efforts helped; others read the messages and can learn from them.
Related thread: Attributes referencing in PI AF
You say you have an attribute containing a time span. What is it's data type? Is it a string representing a time span, in which case you require additional parsing to convert to an actual TimeSpan object? Or is the attribute's data type Anything, and you have stored a .NET TimeSpan object as its value?
The PI Point DR cannot use a dynamic or varying time span to perform averages. It works fine with a fixed relative time, e.g. "-24h" or "-1h". You will need to use Asset Analytics to use a dynamic time span. I suggest you save the output to a new PI point in order to improve performance. Note that the PI Point DR limits %variables% as the server and time name; attempting to use %variables% elsewhere in the ConfigString will throw an exception.
The biggest trick to know when dealing with time spans is the the time string should begin with a + or - sign inside single quotes. If you use double quotes, it will be a literal string. Single quotes are used to denote tags, attributes, times, and time spans. Double quotes would need to be converted with the ParseTime function but it will convert it to fixed time stamp. The image above shows how to convert it to an actual time span object.
The data type is "Single"
Attached a snapshot
You should assign a UOM of day to the attribute.
For any time math operations, such as subtracting scalar values (be they Single, Double, or any integers), then a UOM of second is assumed. You will need to convert your days to seconds. This is best done by assigning the day UOM to "Read Tag" and performing a Convert as shown below.
Note the UOM in the Value column for days (15 d) and seconds (1.286E+06 s).
Retrieving data ...