Esempio n. 1
0
        public void LowerResolution_WorksWithEmptyList()
        {
            IList <SystemPerformance> data = new List <SystemPerformance>();

            SystemPerformance.LowerResolution(data, 1, 0);
            CollectionAssert.AreEqual(new List <SystemPerformance>(), data.ToList());
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
0
        public void LowerResolution_WorksWithSingleItemInTheList(int maxPoints, decimal threshold)
        {
            IList <SystemPerformance> data = new List <SystemPerformance>
            {
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 0, 0), Value = 10
                }
            };

            SystemPerformance.LowerResolution(data, maxPoints, threshold);
            Assert.AreEqual(1, data.Count, "Records were incorrectly removed.");
            AssertPerformanceEquality(10m, new DateTime(2015, 1, 1, 6, 0, 0), data[0]);
        }
Esempio n. 4
0
        [TestCase(1, 0.075, 1)] // 7.5% threshold
        public void LowerResolution_ThresholdWorksWithEightPoints(int maxPoints, decimal threshold, int expectedValuesIndex)
        {
            // These aren't great tests - they're looking at way too much data to test.
            // TODO: Rework this test into smaller tests and manybe use the TestCaseSource
            var expectedValues = new List <List <TimeValue> >
            {
                new List <TimeValue>
                {
                    // all records returned
                    new TimeValue(new DateTime(2015, 1, 1, 6, 0, 0), 10),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 0, 0), 10.25m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 1, 0), 10.763m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 2, 0), 11.57m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 3, 0), 12.727m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 4, 0), 13.682m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 4, 0), 14.365m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 5, 0), 14.724m)
                },
                new List <TimeValue>
                {
                    // all records returned
                    new TimeValue(new DateTime(2015, 1, 1, 6, 0, 0), 10),
                    //new TimeValue(new DateTime(2015, 1, 1, 6, 0, 0), 10.25m),
                    //new TimeValue(new DateTime(2015, 1, 1, 6, 1, 0), 10.763m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 2, 0), 11.57m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 3, 0), 12.727m),
                    //new TimeValue(new DateTime(2015, 1, 1, 6, 4, 0), 13.682m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 4, 0), 14.365m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 5, 0), 14.724m)
                }
            };

            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, 0, 0), Value = 10.25m
                },                                                                                       // +2.5%
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 1, 0), Value = 10.763m
                },                                                                                        // +5%
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 2, 0), Value = 11.57m
                },                                                                                       // +7.5%
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 3, 0), Value = 12.727m
                },                                                                                        // +10%
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 4, 0), Value = 13.682m
                },                                                                                        // +7.5%
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 4, 0), Value = 14.365m
                },                                                                                        // +5%
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 5, 0), Value = 14.724m
                }                                                                                        // +2.5%
            };

            SystemPerformance.LowerResolution(data, maxPoints, threshold);

            Assert.AreEqual(expectedValues[expectedValuesIndex].Count, data.Count, "Records were incorrectly removed (or added).");
            for (int i = 0; i < expectedValues[expectedValuesIndex].Count; i++)
            {
                var timeValue = expectedValues[expectedValuesIndex].ElementAt(i);
                AssertPerformanceEquality(timeValue.Value, timeValue.DateTime, data[i]);
            }
        }
Esempio n. 5
0
        [TestCase(5, 1, 4)]   // with zero threshold, all points should be returned
        public void LowerResolution_MaxPointsWorksWithSixItemsInTheList(int maxPoints, decimal threshold, int expectedValuesIndex)
        {
            // These aren't great tests - they're looking at way too much data to test.
            // TODO: Rework this test into smaller tests and manybe use the TestCaseSource
            var expectedValues = new List <List <TimeValue> >
            {
                new List <TimeValue>
                {
                    // all records returned
                    new TimeValue(new DateTime(2015, 1, 1, 6, 0, 0), 10m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 1, 0), 10.5m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 2, 0), 11.55m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 3, 0), 13.286m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 4, 0), 14.611m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 5, 0), 15.341m)
                },
                new List <TimeValue>
                {
                    // 2 records (0 + ends)
                    new TimeValue(new DateTime(2015, 1, 1, 6, 0, 0), 10m),
                    //new TimeValue(new DateTime(2015, 1, 1, 6, 1, 0), 10.5m),
                    //new TimeValue(new DateTime(2015, 1, 1, 6, 2, 0), 11.55m),
                    //new TimeValue(new DateTime(2015, 1, 1, 6, 3, 0), 13.286m),
                    //new TimeValue(new DateTime(2015, 1, 1, 6, 4, 0), 14.611m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 5, 0), 15.341m)
                },
                new List <TimeValue>
                {
                    // 3 records returned (1 + ends)
                    new TimeValue(new DateTime(2015, 1, 1, 6, 0, 0), 10m),
                    //new TimeValue(new DateTime(2015, 1, 1, 6, 1, 0), 10.5m),
                    //new TimeValue(new DateTime(2015, 1, 1, 6, 2, 0), 11.55m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 3, 0), 13.286m),
                    //new TimeValue(new DateTime(2015, 1, 1, 6, 4, 0), 14.611m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 5, 0), 15.341m)
                },
                new List <TimeValue>
                {
                    // 4 records returned (2 + ends)
                    new TimeValue(new DateTime(2015, 1, 1, 6, 0, 0), 10m),
                    //new TimeValue(new DateTime(2015, 1, 1, 6, 1, 0), 10.5m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 2, 0), 11.55m),
                    //new TimeValue(new DateTime(2015, 1, 1, 6, 3, 0), 13.286m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 4, 0), 14.611m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 5, 0), 15.341m)
                },
                new List <TimeValue>
                {
                    // 5 records returned (3 + ends)
                    new TimeValue(new DateTime(2015, 1, 1, 6, 0, 0), 10m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 1, 0), 10.5m),
                    //new TimeValue(new DateTime(2015, 1, 1, 6, 2, 0), 11.55m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 3, 0), 13.286m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 4, 0), 14.611m),
                    new TimeValue(new DateTime(2015, 1, 1, 6, 5, 0), 15.341m)
                },
            };

            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.5m
                },                                                                                      // +5%
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 2, 0), Value = 11.55m
                },                                                                                       // +10%
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 3, 0), Value = 13.286m
                },                                                                                        // +15%
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 4, 0), Value = 14.611m
                },                                                                                        // +10%
                new SystemPerformance {
                    AuditTime = new DateTime(2015, 1, 1, 6, 5, 0), Value = 15.341m
                }                                                                                        // +5%
            };

            SystemPerformance.LowerResolution(data, maxPoints, threshold);

            Assert.AreEqual(expectedValues[expectedValuesIndex].Count, data.Count, "Records were incorrectly removed (or added).");
            for (int i = 0; i < expectedValues[expectedValuesIndex].Count; i++)
            {
                var timeValue = expectedValues[expectedValuesIndex].ElementAt(i);
                AssertPerformanceEquality(timeValue.Value, timeValue.DateTime, data[i]);
            }
        }