Esempio n. 1
0
        /// <summary>
        /// Determines of the system performance points are all the same
        /// </summary>
        /// <param name="prevDataPoint">The previous data point to compare to.</param>
        /// <param name="nextDataPoint">The next data point to compare to.</param>
        /// <returns></returns>
        public bool IsTheSameAs(SystemPerformance prevDataPoint, SystemPerformance nextDataPoint)
        {
            bool areAllTheSame = prevDataPoint != null &&
                                 nextDataPoint != null &&
                                 prevDataPoint.Value == this.Value &&
                                 this.Value == nextDataPoint.Value;

            return(areAllTheSame);
        }
Esempio n. 2
0
        /// <summary>
        /// Compacts the data, to make it easier to render out
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="secondsInterval">The seconds interval.</param>
        public static void CompactData(IList <SystemPerformance> data, int secondsInterval)
        {
            Debug.Assert(secondsInterval >= 0, "secondsInterval cannot be less than zero");

            bool keepSameValue = false;

            for (var i = 0; i < data.Count; i++)
            {
                SystemPerformance prevDataPoint = i > 0 ? data[i - 1] : null;
                SystemPerformance dataPoint     = data[i];
                SystemPerformance nextDataPoint = i < data.Count - 1 ? data[i + 1] : null;

                bool areAllTheSame = dataPoint.IsTheSameAs(prevDataPoint, nextDataPoint);

                if (prevDataPoint != null &&
                    (dataPoint.AuditTime - prevDataPoint.AuditTime).TotalSeconds > secondsInterval &&
                    dataPoint.Value != 0 &&
                    (!keepSameValue || prevDataPoint.Value != dataPoint.Value))
                {
                    // if there is a greater-than-interval time difference between the previous and
                    // current data points, insert zero record at current position (to push the rest out by one)
                    data.Insert(i, new SystemPerformance {
                        AuditTime = dataPoint.AuditTime.AddSeconds(-1), Value = 0
                    });
                    keepSameValue = false;
                }
                else if (nextDataPoint != null &&
                         (nextDataPoint.AuditTime - dataPoint.AuditTime).TotalSeconds > secondsInterval &&
                         dataPoint.Value != 0 &&
                         (!keepSameValue || dataPoint.Value != nextDataPoint.Value))
                {
                    // if there is a greater-than-interval time difference between the current and
                    // next data points, insert zero record at current position + 1 (to be processed next pass)
                    data.Insert(i + 1, new SystemPerformance {
                        AuditTime = dataPoint.AuditTime.AddSeconds(1), Value = 0
                    });
                    keepSameValue = false;
                }
                else if (areAllTheSame)
                {
                    // if the data is the same in all instances, remove it
                    data.RemoveAt(i);
                    keepSameValue = true;
                    i--; // adjust i
                }
            }
        }