8 Replies Latest reply on Feb 3, 2017 9:56 AM by aksnk89

    Event count

    Suganya_Ganesan

      Hello

       

      I have a tag for which i am not certain about the number of events each day, as it could be 96 events (15 min freq) or 288 events(5 min) etc..

       

      I am calculating consumption for a tag using the raw (above) tag.

       

      I want to get the event count and data exactly at 15 minute(s) for the given start time and end time without interpolation.

      Is there a way i can achieve this programmatically?

       

      For eg - let's say a tag has 192 event counts for a day, i want to get data exactly 15 minute (96 counts) without interpolation.

       

      I am not able to find any method which i can use to achieve this.

       

       

      Thank you in advance for you help.

        • Re: Event count
          Rick Davin

          Look over this extension method, which means you must place it in a public static class.

           

                 /// <summary>
                  /// Returns the event-weighted count of an <see cref="AFAttribute"/> over the requested <see cref="AFTimeRange"/>.
                  /// </summary>
                  /// <param name="attribute"></param>
                  /// <param name="timeRange"></param>
                  /// <returns>A scalar int of the events within the time range.</returns>
                  public static int GetEventCount(this AFAttribute attribute, AFTimeRange timeRange)
                  {
                      var summaries = attribute.Data.Summary(timeRange, AFSummaryTypes.Count, AFCalculationBasis.EventWeighted, AFTimestampCalculation.Auto);
                      AFValue summary;
                      if (summaries.TryGetValue(AFSummaryTypes.Count, out summary))
                      {
                          if (summary.IsGood)
                          {
                              // One day this may have to be an Int64 or long
                              return Convert.ToInt32(summary.Value);
                          }
                      }
                      return 0;
                  }
          
          1 of 1 people found this helpful
            • Re: Event count
              Suganya_Ganesan

              Hello Rick Davin and Gregor Beck

               

              Thank you for your suggestions.


              The readings are stored in a PI Tag and i am using PISDK to achieve this.
              I tried summary/summaries from PISDK but that doesn't fulfill my expectation here.

               

              Also, the code Rick has provided looks like getting data from AF attribute.

               

              Could you please suggest an alternative for PI Tag?

               

              My motive is to get data only at 15th minute whenever it is available in the archive.

               

              Lets say
              I have data at
              00:00 - data is available - fetch it
              00:15 - data is available- fetch it
              00:25 - data is available - don't fetch it
              00:30 - no data is available - don't fetch it and move to 00:45 and so on for every 15th minute.

               

              Hope this provides better clarity.

            • Re: Event count
              gregor

              Hello Suganya,

               

              Yes, you can do this using EventCount and there are actually many places / ways to do this because PI Equation syntax also referred to as Expressions are supported in many products e.g. PI DataLink

              1 of 1 people found this helpful