Beispiel #1
0
        public void Statistics(int startYear, int startMonth, int startDay, int endYear, int endMonth, int endDay)
        {
            DateTime             startDate = new DateTime(startYear, startMonth, startDay);
            DateTime             endDate   = new DateTime(endYear, endMonth, endDay);
            int                  days      = Convert.ToInt32((endDate - startDate).TotalDays + 1);
            List <DensityDevice> devices   = DensityDbSimulator.CreateDensityDevice(TestInit.ServiceProvider, 1, 6, 6, "", true);

            //创建每小时两条条数据
            EventDbSimulator.CreateData(TestInit.ServiceProvider, devices, startDate, endDate, DataCreateMode.Fixed, true);
            TestInit.RefreshDensityCache(devices);
            EventsController service = new EventsController(TestInit.ServiceProvider.GetRequiredService <DensityContext>(),
                                                            TestInit.ServiceProvider.GetRequiredService <IMemoryCache>());

            foreach (DensityDevice device in devices)
            {
                foreach (var relation in device.DensityDevice_DensityChannels)
                {
                    var roadList = service.StatisticsByRoad(relation.Channel.CrossingId.Value, startDate, endDate.AddDays(1));
                    //验证按路口按小时分组统计次数
                    Assert.AreEqual(days * 24, roadList.Count);

                    //验证按区域按小时分组统计次数
                    foreach (TrafficRegion region in relation.Channel.Regions)
                    {
                        var regionList = service.StatisticsByRegion(region.DataId, startDate, endDate.AddDays(1));
                        Assert.AreEqual(days * 24, regionList.Count);
                    }
                }
            }
        }
Beispiel #2
0
        public void Last10()
        {
            List <DensityDevice> devices = DensityDbSimulator.CreateDensityDevice(TestInit.ServiceProvider, 1, 1, 10, "", true);

            TestInit.RefreshDensityCache(devices);
            EventDbSimulator.CreateData(TestInit.ServiceProvider, devices, DateTime.Today, true);
            EventsController service = new EventsController(TestInit.ServiceProvider.GetRequiredService <DensityContext>(),
                                                            TestInit.ServiceProvider.GetRequiredService <IMemoryCache>());
            var v         = service.QueryLast10();
            int itemCount = devices[0].DensityDevice_DensityChannels[0].Channel.Regions.Count;

            for (int i = 0; i < 10; ++i)
            {
                Assert.AreEqual(v[i].DataId, devices[0].DensityDevice_DensityChannels[0].Channel.Regions[itemCount - 1 - i].DataId);
            }
        }
Beispiel #3
0
        public void Rank(int startYear, int startMonth, int startDay, int endYear, int endMonth, int endDay)
        {
            DateTime             startDate = new DateTime(startYear, startMonth, startDay);
            DateTime             endDate   = new DateTime(endYear, endMonth, endDay);
            List <DensityDevice> devices   = DensityDbSimulator.CreateDensityDevice(TestInit.ServiceProvider, 1, 6, 6, "", true);
            //随机出的值表示次数,每次1分钟
            Dictionary <TrafficEvent, int> trafficEvents = EventDbSimulator.CreateData(TestInit.ServiceProvider, devices, startDate, endDate, DataCreateMode.Random, true);

            TestInit.RefreshDensityCache(devices);
            EventsController service = new EventsController(TestInit.ServiceProvider.GetRequiredService <DensityContext>(),
                                                            TestInit.ServiceProvider.GetRequiredService <IMemoryCache>());
            IMemoryCache memoryCache = TestInit.ServiceProvider.GetRequiredService <IMemoryCache>();

            //要验证的值
            var regions = trafficEvents
                          .Select(p => new KeyValuePair <string, int>(p.Key.DataId, p.Value))
                          .OrderByDescending(p => p.Value)
                          .ToList();
            var roads = trafficEvents
                        .GroupBy(p => memoryCache.GetRegion(p.Key.DataId).Channel.CrossingId)
                        .Select(g => new KeyValuePair <int, int>(g.Key.Value, g.Sum(p => p.Value)))
                        .OrderByDescending(p => p.Value)
                        .ToList();

            //区域次数
            var countRegionTop = service.CountRankByRegion(startDate, endDate.AddDays(1));

            for (int i = 0; i < countRegionTop.Count; ++i)
            {
                //验证次数和区域编号
                Assert.AreEqual(countRegionTop[i].Value, regions[i].Value);
                Assert.AreEqual(countRegionTop[i].Axis, regions[i].Key);
            }

            //路口次数
            var countRoadTop = service.CountRankByRoad(startDate, endDate.AddDays(1));

            for (int i = 0; i < countRoadTop.Count; ++i)
            {
                //验证次数和路口编号
                Assert.AreEqual(countRoadTop[i].Value, roads[i].Value);
                Assert.AreEqual(countRoadTop[i].Axis, roads[i].Key);
            }

            //区域时长
            var spanRegionTop = service.SpanRankByRegion(startDate, endDate.AddDays(1));

            for (int i = 0; i < spanRegionTop.Count; ++i)
            {
                //验证时长(秒)和区域编号
                Assert.AreEqual(spanRegionTop[i].Value, regions[i].Value);
                Assert.AreEqual(spanRegionTop[i].Axis, regions[i].Key);
            }

            //路口时长
            var spanRoadTop = service.SpanRankByRoad(startDate, endDate.AddDays(1));

            for (int i = 0; i < countRoadTop.Count; ++i)
            {
                //验证时长(秒)和路口编号
                Assert.AreEqual(spanRoadTop[i].Value, roads[i].Value);
                Assert.AreEqual(spanRoadTop[i].Axis, roads[i].Key);
            }
        }