/// <summary>
        /// Calculates a new kpi value.
        /// </summary>
        /// <param name="keyTimeStamp">The timestamp which is used for the result object.</param>
        /// <param name="minTimeStamp">The timestamp which is the minimum for current calculation step.</param>
        /// <param name="maxTimeStamp">The maximum timestamp up to which to calculate the next kpi.</param>
        /// <param name="calculationInterval">The interval from which to take all values from.</param>
        internal override PerformanceAnalyzeResultBase Calculate(
            DateTime keyTimeStamp,
            DateTime minTimeStamp, DateTime maxTimeStamp,
            TimeSpan calculationInterval)
        {
            if (!m_lastDurationItems.HasAny())
            {
                return(null);
            }
            else
            {
                // Throw away all items which are too old
                foreach (var dummy in m_lastDurationItems.DequeueWhile((actItem) => actItem.Item1 < minTimeStamp))
                {
                }

                // Check again wether we have any items
                if (!m_lastDurationItems.HasAny())
                {
                    return(null);
                }

                // Calculate result values
                long minValue  = long.MaxValue;
                long maxValue  = long.MinValue;
                long sumValue  = 0;
                long itemCount = 0;
                foreach (var actItem in m_lastDurationItems.PeekWhile((actTuple) => actTuple.Item1 < maxTimeStamp))
                {
                    if (minValue > actItem.Item2)
                    {
                        minValue = actItem.Item2;
                    }
                    if (maxValue < actItem.Item2)
                    {
                        maxValue = actItem.Item2;
                    }
                    sumValue += actItem.Item2;
                    itemCount++;
                }

                // Check again wether we have any items
                if (itemCount == 0)
                {
                    return(null);
                }

                // Calculate average time value
                long avgValue = sumValue / itemCount;

                // Create result object
                return(new DurationPerformanceResult(this, keyTimeStamp, avgValue, maxValue, minValue));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Calculates a new kpi value based on given timestamp parameters.
        /// </summary>
        /// <param name="keyTimeStamp">The timestamp which is used for the result object.</param>
        /// <param name="minTimeStamp">The timestamp which is the minimum for current calculation step.</param>
        /// <param name="maxTimeStamp">The maximum timestamp up to which to calculate the next kpi.</param>
        /// <param name="calculationInterval">The interval from which to take all values from.</param>
        /// <returns></returns>
        internal override PerformanceAnalyzeResultBase Calculate(
            DateTime keyTimeStamp,
            DateTime minTimeStamp, DateTime maxTimeStamp,
            TimeSpan calculationInterval)
        {
            if (!m_lastReportedTimestamps.HasAny())
            {
                return(new FlowRatePerformanceResult(this, keyTimeStamp, 0.0));
            }
            else
            {
                // Throw away all items which are too old
                foreach (var dummy in m_lastReportedTimestamps.DequeueWhile((actItem) => actItem < minTimeStamp))
                {
                }

                // Check again wether we have any items
                if (!m_lastReportedTimestamps.HasAny())
                {
                    return(new FlowRatePerformanceResult(this, keyTimeStamp, 0.0));
                }

                // Counts all relevant items
                double resultValue = (double)(m_lastReportedTimestamps
                                              .PeekWhile((actTuple) => actTuple < maxTimeStamp)
                                              .Count());

                // Handle case where measured timespan in more less than the calculation timespan
                TimeSpan currentValueTimespan = maxTimeStamp - minTimeStamp;
                if (currentValueTimespan != calculationInterval)
                {
                    double timespanFactor = (double)calculationInterval.Ticks / (double)currentValueTimespan.Ticks;
                    resultValue *= timespanFactor;
                }

                // Generate the result object
                return(new FlowRatePerformanceResult(this, keyTimeStamp, resultValue));
            }
        }