/// <summary> /// Returns the event-weighted count of a <see cref="PIPoint"/> over the requested <see cref="AFTimeRange"/>. /// </summary> /// <param name="tag">A PIPoint</param> /// <param name="timeRange">An AFTimeRange</param> /// <returns>A scalar int of the events within the time range.</returns> public static int GetEventCount(this PIPoint tag, AFTimeRange timeRange) { var summaries = tag.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); }
}//DetermineHistoricalTimeRanges private int FindEventCount(PIPoint point, AFTime startTime, AFTime endTime) { //This method returns the event count for the specified PI point over the specified time range int eventCount = 0; //Create time range AFTimeRange timeRange = new AFTimeRange(startTime, endTime); //Call the AFSDK PIPoint.Summary method for Count. This should return a dictionary which contains the event count. var summaryResult = point.Summary(timeRange, OSIsoft.AF.Data.AFSummaryTypes.Count, OSIsoft.AF.Data.AFCalculationBasis.EventWeighted, OSIsoft.AF.Data.AFTimestampCalculation.Auto); //Pull our desired summary type from the summary result dictionary as an integer eventCount = summaryResult[OSIsoft.AF.Data.AFSummaryTypes.Count].ValueAsInt32(); return(eventCount); }//FindEventCount