Beispiel #1
0
        public void GetMetricsInPeriod_GivenValidPeriodShouldReturnDevices()
        {
            var mockCollection = new Mock <IMongoCollection <RawMetric> >();

            var ctx = new Mock <RawMetricsContext>(false);

            ctx.Setup(c => c.RawMetrics).Returns(mockCollection.Object);

            var dao = new RawMetricsDAO(ctx.Object);

            dao.GetMetricsInPeriodASC(1, 2);
            mockCollection.Verify(c => c.FindSync(It.IsAny <FilterDefinition <RawMetric> >(), It.IsAny <FindOptions <RawMetric, RawMetric> >(), It.IsAny <CancellationToken>()), Times.Once());
        }
Beispiel #2
0
        public async Task <List <CalculatedMetricsModel> > generateCalculatedMetrics()
        {
            RawMetricsContext context       = new RawMetricsContext(true);
            RawMetricsDAO     rawMetricsDAO = new RawMetricsDAO(context);

            // If we are on monday, we look for the rawdata of the week
            List <RawMetric> rawMetrics = new List <RawMetric>();
            // Otherwise, we look for  the rawdata of the previous 24h
            DateTime dateOfTheDay = new DateTime();

            if (dateOfTheDay.DayOfWeek == DayOfWeek.Monday)
            {
                dateOfTheDay = DateTime.Now;
                rawMetrics   =
                    await rawMetricsDAO.GetMetricsInPeriodASC(DateTimeToUnixLong(dateOfTheDay.AddDays(-7)), DateTimeToUnixLong(dateOfTheDay));
            }
            else
            {
                rawMetrics =
                    await rawMetricsDAO.GetMetricsInPeriodASC(DateTimeToUnixLong(dateOfTheDay.AddDays(-1)), DateTimeToUnixLong(dateOfTheDay));
            }
            return(Calculation(rawMetrics));
        }