need duration from event frames in AF as attribute to be able to use for calculations. can this be done.
My understanding is that you can only get access to the duration of the event frame within the event frame attributes, not within the element it's referenced from. Here you can use the duration in formula calculations, but you don't have access to AF Analyses.
There are workarounds though:
If anyone else have different approaches I'd be interested in hearing them!
I've used the OLEDB Enterprise and linked AFTable approach as well, and found it to be a fairly reliable method of accessing EF data. It's a bit of a pain to have to go that way, but it does work.
Exactly the approach we have been using Asle Frantzen. Doing the analysis for duration of the event or even phases within an event have been helpful. It can be tricky, but works well.
You could also get the duration using a custom data reference:
public override AFValue GetValue(object context, object timeContext, AFAttributeList inputAttributes, AFValues inputValues)
var element = this.Attribute.Element;
if (element == null) return new AFValue(-1);
var database = Element.Database;
AFNamedCollectionList<AFEventFrame> frames=AFEventFrame.FindEventFrames(database, null, new AFTime(DateTime.Now), 0, 1,
"", element.Name, null, element.Template, true);
if(frames.Count!=1) return new AFValue(-1);
return new AFValue(frames.TimeRange.Span.TotalSeconds);
I'm not sure if this will address your use case, but there is a work around that can be used to handle some of these cases. On your referenced element, create attributes:
The last step is to evaluate the Calculation data reference from an attribute on the Event Frame so that the time context of the event frame is passed along and used to evaluate the StartTime and EndTime attributes. This is done by creating an attribute on the event frame like:
You can mark the StartTime, EndTime, and Calculation attributes on the referenced element as "Hidden" since these are just intermediate values and might not make sense in client UIs.
Rick has written an excellent blog with methods with their performance result to retrieve EventFrame Duration here.
Just to follow up with newer version functionality. You can now output the EF duration to a PI Pt attribute on the reference element when the EF is closed. See here for more details: KB01884 - Output Event Frame Start Time, End Time, and Duration to a PI Tag
That is great - no need to convert event frames back to tags ...
Retrieving data ...