4 Replies Latest reply on Jan 14, 2016 6:10 PM by PIAdminUnison

    Search for EventFrames between two dates based on Attribute value

    PIAdminUnison

      Hey all,

       

      I am working with AFSDK and VB.Net and I have a question but first some background:

       

      I have some meters in the field with some events I want to record in AF EventFrames.  Not to difficult, but now I discovered my meters don't like me and I get 30,000 events in 30 minutes sometimes.  Yes, I know, "Way too much information".  In actual fact, I only need to record a few of those events into PI and I can discard the rest.  So my thoughts on this matter is to set a limit of number of EventFrames to record per minute, this way I will get some of the events that happen and discard the unnecessary ones.  One other thing, I need to do this by also looking at the value of one attribute in the EventFrame.  Now for my question.  Is there an AFSDK call that allows me to search for the EventFrames on an AFElement based on a time range (i.e. between a start and end time) and an EF Attribute called phase=1?  It seems you can do this in the PI System Explorer but I can't seem to do it so far with the AFSDK.

       

      I'm using AFSDK 2.6 and any help would be much appreciated, please.

       

      Thanks,

      Jimmy

        • Re: Search for EventFrames between two dates based on Attribute value
          Dan Fishman

          There are really three ways to search for event frames.  For an AFElement, you can call GetEventFrames; howerver, this won't let you do the filtering you need.  Within the OSIsoft.AF.EventFrame namepsace you can use the FindEventFrames method of the AFEventFrame object to find your Event Frames.  The only issue with the FindEVentFrames method I see is that it takes an element name and not the id of the element.  Basically, if you have elements with the same name you might have to filter out your results. 

           

          If you are using AF 2.7.5 you can use the newest search in the OSIsoft.AF.Search Namespace.  I have not yet used this but it is the most flexible search and I'm sure with AF 2.8 we'll be seeing more usage of this in the future.

          1 of 1 people found this helpful
          • Re: Search for EventFrames between two dates based on Attribute value
            pthivierge

            Hello Jimmy,

             

            Yes this is possible, to me to best explanation of how the event frames search works is :

            AFSearchMode Enumeration

             

            --

             

            I wrote an EventFrames search sample in the PI AF SDK Clues project sample.  And this may help get you started:

            AFEventFramesSearch.cs

             

            In your case, if you need to search based on a specific Element, you'll need to pass the element to the searchRoot parameter.

            Also, to filter by EF attribute value, you may use the valueQuery parameter.

             

            Let us know if things are working for you.

            • Re: Search for EventFrames between two dates based on Attribute value
              PIAdminUnison

              Hey All,

               

              Thanks for the help.  I think I may have been half awake when I originally tried to do this task.  In the end I used the FindEventFramesByAttribute method, which allowed for all the parameters I needed to get my desired results.  Below is my code and yes I may have been fully asleep when first trying to do this query, because it is straight forward.

               

               

              Dim tmpEventFrames As New AFNamedCollectionList(Of AFEventFrame)

               

               

              Dim avQuery1 As New AFAttributeValueQuery

               

               

              avQuery1.AttributeTemplate = tmpElement.Database.ElementTemplates("SagSwellEventFrame").AttributeTemplates("Phase")

               

               

              avQuery1.Operator = Search.AFSearchOperator.Equal

               

              avQuery1.AttributeValue = tmpSagSwellItem.Phase

               

               

               

               

              Dim avQueries() As AFAttributeValueQuery = New AFAttributeValueQuery() {avQuery1}

               

               

               

              tmpEventFrames =AFEventFrame.FindEventFramesByAttribute(Nothing, AFSearchMode.StartInclusive, tmpStartTime.UtcDateTime, tmpStartTime.UtcDateTime.AddMinutes(1), Nothing, tmpElement.Name, Nothing, avQueries, True, AFSortField.StartTime, AFSortOrder.Ascending, 0, tmpEventFrameCount.MaxEventCountAllowed)

               

               

               

              Again, thanks for your guys help and putting me on the right path.

               

              Cheers,

              Jimmy