/// <summary> /// Create a new event metric object from the provided raw data packet /// </summary> /// <remarks>The new metric will automatically be added to the metric definition's metrics collection.</remarks> /// <param name="definition">The object that defines this metric</param> /// <param name="packet">The raw data packet</param> internal EventMetric(EventMetricDefinition definition, EventMetricPacket packet) : base(definition, packet) { // We created an EventMetricSampleCollection when base constructor called our OnSampleCollectionCreate(). m_Samples = (EventMetricSampleCollection)base.Samples; m_MetricDefinition = definition; m_Packet = packet; }
/// <summary> /// Compute the resultant value for this sample compared with the provided baseline sample. /// </summary> /// <remarks> /// <para>The baseline sample must be for a date and time prior to this sample for correct results.</para> /// <para>If the supplied trendValue isn't trendable, the number of samples with a non-null value will be counted.</para> /// <para>If the supplied trendValue is trendable, the Default Trend (average or sum) will be calculated for all /// samples between the supplied baseline sample and this sample, inclusive.</para> /// </remarks> /// <param name="baselineSample">The previous baseline sample to calculate a difference for</param> /// <param name="trendValue">The definition of the value from this event metric to trend.</param> /// <returns>The calculated counter value</returns> public double ComputeValue(IEventMetricSample baselineSample, IEventMetricValueDefinition trendValue) { //we have to figure out all of the samples to include between these points. List <EventMetricSample> valueSamples = new List <EventMetricSample>(); EventMetricSampleCollection samples = Metric.Samples; int startIndex = (baselineSample == null) ? 0 : samples.IndexOf(baselineSample); int ourIndex = samples.IndexOf(this); for (int sampleIndex = startIndex; sampleIndex <= ourIndex; sampleIndex++) { valueSamples.Add(samples[sampleIndex]); } return(Metric.CalculateSample(null, valueSamples, 0, 0, Timestamp, (EventMetricValueDefinition)trendValue)); }