예제 #1
0
        public void CompactData_WorksWithTwoEntriesThatAreFarApart()
        {
            // Since it will be greater than the secondsInterval, 2 should be inserted to represent the gap
            IList <SystemPerformance> data = new List <SystemPerformance>
            {
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 0, 0), Value = 10
                },
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 10, 0), Value = 10
                },
            };

            SystemPerformance.CompactData(data, secondsInterval);
            CollectionAssert.AreEqual(new List <SystemPerformance>
            {
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 0, 0), Value = 10
                },
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 0, 1), Value = 0
                },
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 9, 59), Value = 0
                },
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 10, 0), Value = 10
                },
            }, data.ToList(), string.Format("Different number of elements: {0}", data.Count));
        }
예제 #2
0
        public void CompactData_WorksWithThreeEntriesThatAreTheSame()
        {
            IList <SystemPerformance> data = new List <SystemPerformance>
            {
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 0, 0), Value = 10
                },
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 1, 0), Value = 10
                },
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 2, 0), Value = 10
                },
            };

            SystemPerformance.CompactData(data, secondsInterval);
            CollectionAssert.AreEqual(new List <SystemPerformance>
            {
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 0, 0), Value = 10
                },
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 2, 0), Value = 10
                },
            }, data.ToList());
        }
예제 #3
0
        public void CompactData_WorksWithEmptyList()
        {
            IList <SystemPerformance> data = new List <SystemPerformance>();

            SystemPerformance.CompactData(data, secondsInterval);
            CollectionAssert.AreEqual(new List <SystemPerformance>(), data.ToList());
        }
예제 #4
0
        public IList <SystemPerformance> GetSystemCpuPerformanceData(string cpuFrom, string to, bool?raw = null)
        {
            try
            {
                DateTime fromDate = DateTime.ParseExact(cpuFrom, Constants.DateFormat, CultureInfo.InvariantCulture);
                DateTime toDate   = DateTime.ParseExact(to, Constants.DateFormat, CultureInfo.InvariantCulture);

                using (var dao = _daoFactory.Create <ISystemDao>())
                {
                    var data = dao.GetCpuPerformanceData(fromDate, toDate);

                    if (raw != true)
                    {
                        SystemPerformance.CompactData(data, SecondsInterval);
                        SystemPerformance.LowerResolution(
                            data,
                            ApplicationSettings.Current.PerformanceGraphMaxPoints,
                            ApplicationSettings.Current.PerformanceGraphThreshold);
                    }

                    return(data);
                }
            }
            catch (Exception e)
            {
                log.Error("REST API Error", e);
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
        }
예제 #5
0
        public void CompatData_WorksWithSingleEntry()
        {
            IList <SystemPerformance> data = new List <SystemPerformance>
            {
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 0, 0), Value = 10
                }
            };

            SystemPerformance.CompactData(data, secondsInterval);
            CollectionAssert.AreEqual(new List <SystemPerformance>
            {
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 0, 0), Value = 10
                }
            }, data.ToList());
        }