Exemplo n.º 1
0
        public static void CreateData(TestContext testContext)
        {
            _startDate = new DateTime(2019, 1, 1);
            _days      = 1;
            List <DateTime> dates = new List <DateTime>();

            for (DateTime date = _startDate; date <= _startDate.AddDays(_days - 1); date = date.AddDays(1))
            {
                dates.Add(date);
            }

            _startDates = new List <DateTime>();
            for (int d = 0; d < _days; ++d)
            {
                _startDates.Add(_startDate.AddDays(d));
            }

            _months      = 1;
            _startMonths = new List <DateTime>();
            for (int m = 0; m < _months; ++m)
            {
                _startMonths.Add(TimePointConvert.CurrentTimePoint(DateTimeLevel.Month, _startDate).AddMonths(m));
            }

            _devices = FlowDbSimulator.CreateFlowDevice(TestInit.ServiceProvider, 1, 1, 2, true);
            TestInit.RefreshFlowCache(_devices);

            _datas = FlowDbSimulator.CreateData(TestInit.ServiceProvider, _devices, DataCreateMode.Fixed, dates, true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 拥堵时长图表查询
        /// </summary>
        /// <param name="sectionId">路段编号</param>
        /// <param name="level">日期级别</param>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <returns>查询结果</returns>
        public List <TrafficChart <DateTime, int> > QueryCongestionChart(int sectionId, DateTimeLevel level, DateTime startTime, DateTime endTime)
        {
            IQueryable <SectionStatus> whereQueryable = Where(_context.SectionStatuses, sectionId, level, startTime, endTime);
            string timeFormat = TimePointConvert.TimeFormat(level);

            if (level >= DateTimeLevel.Day)
            {
                return(whereQueryable
                       .GroupBy(f => TimePointConvert.CurrentTimePoint(level, f.DateTime))
                       .Select(g => new TrafficChart <DateTime, int>
                {
                    Axis = g.Key,
                    Remark = g.Key.ToString(timeFormat),
                    Value = g.Sum(f => f.Warning + f.Bad + f.Dead)
                })
                       .ToList());
            }
            else
            {
                return(whereQueryable
                       .Select(f => new TrafficChart <DateTime, int>
                {
                    Axis = f.DateTime,
                    Remark = f.DateTime.ToString(timeFormat),
                    Value = f.Warning + f.Bad + f.Dead
                })
                       .ToList());
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 按区域查询密度集合
        /// </summary>
        /// <param name="dataId">数据编号</param>
        /// <param name="level">时间级别</param>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <returns>高点密度数据集合</returns>
        public List <TrafficDensity> QueryList(string dataId, DateTimeLevel level, DateTime startTime, DateTime endTime)
        {
            dataId = Uri.UnescapeDataString(dataId);
            List <IQueryable <TrafficDensity> > queryables = BranchDbConvert.GetQuerables(startTime, endTime, _context.Queryable(level));
            List <TrafficDensity> result = new List <TrafficDensity>();

            foreach (IQueryable <TrafficDensity> queryable in queryables)
            {
                try
                {
                    IQueryable <TrafficDensity> whereQueryable = Where(queryable, dataId, level, startTime, endTime);
                    if (level >= DateTimeLevel.Day)
                    {
                        result.AddRange(whereQueryable
                                        .GroupBy(f => TimePointConvert.CurrentTimePoint(level, f.DateTime))
                                        .Select(g => new TrafficDensity
                        {
                            DataId   = g.First().DataId,
                            DateTime = g.Key,
                            Value    = Convert.ToInt32(g.Average(d => d.Value))
                        })
                                        .ToList());
                    }
                    else
                    {
                        result.AddRange(whereQueryable.ToList());
                    }
                }
                catch
                {
                }
            }
            return(result);
        }
Exemplo n.º 4
0
        protected override void ActionCore()
        {
            while (!IsCancelled())
            {
                DateTime now = DateTime.Now;

                foreach (var pair in _fixedJobs)
                {
                    if (now > pair.Value.ChangeTime)
                    {
                        DateTime lastTime    = pair.Value.CurrentTime;
                        DateTime currentTime = TimePointConvert.NextTimePoint(pair.Value.Level, lastTime);
                        DateTime nextTime    = TimePointConvert.NextTimePoint(pair.Value.Level, currentTime);

                        Stopwatch stopwatch = new Stopwatch();
                        stopwatch.Start();
                        try
                        {
                            pair.Key.Handle(lastTime, currentTime, nextTime);
                        }
                        catch (Exception ex)
                        {
                            _logger.LogError((int)LogEvent.定时任务, ex, $"定制任务异常 {pair.Value.Name}");
                        }
                        stopwatch.Stop();

                        _logger.LogDebug((int)LogEvent.定时任务, $"定时任务完成 任务名称:{pair.Value.Name} 执行时间:{lastTime} 当前时间:{currentTime} 下次触发:{nextTime} 耗时:{stopwatch.ElapsedMilliseconds}毫秒");
                        pair.Value.CurrentTime = currentTime;
                        pair.Value.ChangeTime  = nextTime.Add(pair.Value.Span);
                    }
                }
                Thread.Sleep(1000);
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// 筛选
 /// </summary>
 /// <param name="queryable">数据源</param>
 /// <param name="sectionId">路段编号</param>
 /// <param name="level">时间级别</param>
 /// <param name="startTime">开始时间</param>
 /// <param name="endTime">结束时间</param>
 /// <returns></returns>
 private IQueryable <SectionStatus> Where(IQueryable <SectionStatus> queryable, int sectionId, DateTimeLevel level, DateTime startTime, DateTime endTime)
 {
     if (level >= DateTimeLevel.Day)
     {
         startTime = TimePointConvert.CurrentTimePoint(level, startTime);
         endTime   = TimePointConvert.NextTimePoint(level, TimePointConvert.CurrentTimePoint(level, endTime)).AddMinutes(-1);
     }
     return(queryable
            .Where(f => f.SectionId == sectionId && f.DateTime >= startTime && f.DateTime <= endTime));
 }
Exemplo n.º 6
0
        /// <summary>
        /// 筛选
        /// </summary>
        /// <param name="queryable">数据源</param>
        /// <param name="dataIds">车道数据编号集合</param>
        /// <param name="level">时间级别</param>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <returns></returns>
        protected IQueryable <LaneFlow> Where(IQueryable <LaneFlow> queryable, HashSet <string> dataIds, DateTimeLevel level, DateTime startTime, DateTime endTime)
        {
            if (level >= DateTimeLevel.Day)
            {
                startTime = TimePointConvert.CurrentTimePoint(level, startTime);
                endTime   = TimePointConvert.NextTimePoint(level, TimePointConvert.CurrentTimePoint(level, endTime)).AddMinutes(-1);
            }

            return(queryable
                   .Where(f => dataIds.Contains(f.DataId) && f.DateTime >= startTime && f.DateTime <= endTime));
        }
Exemplo n.º 7
0
        /// <summary>
        /// 筛选
        /// </summary>
        /// <param name="queryable">数据源</param>
        /// <param name="dataId">数据编号</param>
        /// <param name="level">时间级别</param>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <returns></returns>
        private IQueryable <TrafficDensity> Where(IQueryable <TrafficDensity> queryable, string dataId, DateTimeLevel level, DateTime startTime, DateTime endTime)
        {
            if (level >= DateTimeLevel.Day)
            {
                startTime = TimePointConvert.CurrentTimePoint(level, startTime);
                endTime   = TimePointConvert.NextTimePoint(level, TimePointConvert.CurrentTimePoint(level, endTime)).AddMinutes(-1);
            }

            return(queryable
                   .Where(f => f.DataId == dataId &&
                          f.DateTime >= startTime &&
                          f.DateTime <= endTime));
        }
Exemplo n.º 8
0
        /// <summary>
        /// 初始化缓存
        /// </summary>
        /// <param name="devices">设备集合</param>
        private void InitAdapter(List <FlowDevice> devices)
        {
            _logger.LogInformation((int)LogEvent.系统, "初始化数据适配");

            DateTime         minTime          = TimePointConvert.CurrentTimePoint(BranchDbConvert.DateLevel, DateTime.Now);
            DateTime         maxTime          = TimePointConvert.NextTimePoint(BranchDbConvert.DateLevel, minTime);
            FlowAdapter      flowAdapter      = _serviceProvider.GetRequiredService <FlowAdapter>();
            FlowBranchBlock  flowBranchBlock  = _serviceProvider.GetRequiredService <FlowBranchBlock>();
            VideoBranchBlock videoBranchBlock = _serviceProvider.GetRequiredService <VideoBranchBlock>();

            flowBranchBlock.Open(devices, minTime, maxTime);
            videoBranchBlock.Open(minTime, maxTime);
            flowAdapter.Start(devices, flowBranchBlock, videoBranchBlock);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 初始化缓存
        /// </summary>
        /// <param name="devices">设备集合</param>
        private void InitAdapter(List <DensityDevice> devices)
        {
            _logger.LogInformation((int)LogEvent.系统, "初始化数据适配");

            DateTime           minTime            = TimePointConvert.CurrentTimePoint(BranchDbConvert.DateLevel, DateTime.Now);
            DateTime           maxTime            = TimePointConvert.NextTimePoint(BranchDbConvert.DateLevel, minTime);
            DensityAdapter     densityAdapter     = _serviceProvider.GetRequiredService <DensityAdapter>();
            DensityBranchBlock densityBranchBlock = _serviceProvider.GetRequiredService <DensityBranchBlock>();
            EventBranchBlock   eventBranchBlock   = _serviceProvider.GetRequiredService <EventBranchBlock>();

            densityBranchBlock.Open(devices, minTime, maxTime);
            eventBranchBlock.Open(devices);
            densityAdapter.Start(devices, densityBranchBlock, eventBranchBlock);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 添加定时任务
        /// </summary>
        /// <param name="fixedJob">定时任务</param>
        /// <param name="level">时间间隔级别</param>
        /// <param name="span">时间偏移</param>
        /// <param name="name">任务名称</param>
        public void AddFixedJob(IFixedJob fixedJob, DateTimeLevel level, TimeSpan span, string name)
        {
            DateTime currentTime = TimePointConvert.CurrentTimePoint(level, DateTime.Now);
            DateTime changeTime  = TimePointConvert.NextTimePoint(level, currentTime).Add(span);

            _logger.LogInformation((int)LogEvent.定时任务, $"添加定时任务 {name} {level} { changeTime:yyyy-MM-dd HH:mm:ss}");
            _fixedJobs.TryAdd(fixedJob, new FixedJobItem
            {
                Name        = name,
                Level       = level,
                Span        = span,
                CurrentTime = currentTime,
                ChangeTime  = changeTime
            });
        }
Exemplo n.º 11
0
 /// <summary>
 /// 处理数据块中的流量数据
 /// </summary>
 /// <param name="data">流量数据</param>
 protected override void Handle(T data)
 {
     if (data.DateTime >= _maxTime)
     {
         PostData();
         InitData();
         _minTime = TimePointConvert.CurrentTimePoint(_level, data.DateTime);
         _maxTime = TimePointConvert.NextTimePoint(_level, _minTime);
         SetData(data, _minTime);
     }
     else if (data.DateTime >= _minTime && data.DateTime < _maxTime)
     {
         SetData(data, _minTime);
     }
 }
Exemplo n.º 12
0
        /// <summary>
        /// 分组
        /// </summary>
        /// <param name="queryable">数据源</param>
        /// <param name="level">时间级别</param>
        /// <returns>分组后的数据源</returns>
        protected IQueryable <IGrouping <DateTime, LaneFlow> > Group(IQueryable <LaneFlow> queryable, DateTimeLevel level)
        {
            IQueryable <IGrouping <DateTime, LaneFlow> > groupQueryable;

            if (level >= DateTimeLevel.Day)
            {
                groupQueryable = queryable
                                 .GroupBy(f => TimePointConvert.CurrentTimePoint(level, f.DateTime));
            }
            else
            {
                groupQueryable = queryable
                                 .GroupBy(f => f.DateTime);
            }

            return(groupQueryable);
        }
Exemplo n.º 13
0
        /// <summary>
        /// 选择图表
        /// </summary>
        /// <param name="dataId">数据编号</param>
        /// <param name="level">时间级别</param>
        /// <param name="baseTime">基准时间</param>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <returns>查询结果</returns>
        private List <TrafficChart <DateTime, int> > SelectCharts(string dataId, DateTimeLevel level, DateTime baseTime, DateTime startTime, DateTime endTime)
        {
            List <IQueryable <TrafficDensity> > queryables =
                BranchDbConvert.GetQuerables(startTime, endTime, _context.Queryable(level));
            List <TrafficChart <DateTime, int> > result = new List <TrafficChart <DateTime, int> >();

            foreach (IQueryable <TrafficDensity> queryable in queryables)
            {
                try
                {
                    string   timeFormat     = TimePointConvert.TimeFormat(level);
                    TimeSpan span           = TimePointConvert.CurrentTimePoint(level, baseTime) - TimePointConvert.CurrentTimePoint(level, startTime);
                    var      whereQueryable = Where(queryable, dataId, level, startTime, endTime);
                    if (level >= DateTimeLevel.Day)
                    {
                        result.AddRange(whereQueryable
                                        .GroupBy(f => TimePointConvert.CurrentTimePoint(level, f.DateTime))
                                        .Select(g => new TrafficChart <DateTime, int>
                        {
                            Axis   = g.Key.Add(span),
                            Remark = g.Key.ToString(timeFormat),
                            Value  = Convert.ToInt32(g.Average(d => d.Value))
                        })
                                        .ToList());
                    }
                    else
                    {
                        result.AddRange(whereQueryable
                                        .ToList()
                                        .Select(d => new TrafficChart <DateTime, int>
                        {
                            Axis   = d.DateTime.Add(span),
                            Remark = d.DateTime.ToString(timeFormat),
                            Value  = d.Value
                        })
                                        .ToList());
                    }
                }
                catch
                {
                }
            }
            return(result);
        }
Exemplo n.º 14
0
        /// <summary>
        /// 按区域查询密度同比环比分析
        /// </summary>
        /// <param name="dataId">数据编号</param>
        /// <param name="level">密度时间粒度</param>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <returns>高点密度数据集合</returns>
        public List <List <TrafficChart <DateTime, int> > > QueryComparison(string dataId, DateTimeLevel level, DateTime startTime, DateTime endTime)
        {
            dataId    = Uri.UnescapeDataString(dataId);
            startTime = TimePointConvert.CurrentTimePoint(level, startTime);
            endTime   = TimePointConvert.CurrentTimePoint(level, endTime);
            List <DateTime> startTimes = new List <DateTime>();
            List <DateTime> endTimes   = new List <DateTime>();

            startTimes.Add(startTime);
            endTimes.Add(endTime);

            //同比
            if (level == DateTimeLevel.FiveMinutes ||
                level == DateTimeLevel.FifteenMinutes ||
                level == DateTimeLevel.Hour)
            {
                startTimes.Add(TimePointConvert.PreTimePoint(DateTimeLevel.Day, startTime));
                endTimes.Add(TimePointConvert.PreTimePoint(DateTimeLevel.Day, endTime));
            }

            else if (level == DateTimeLevel.Day)
            {
                startTimes.Add(TimePointConvert.PreTimePoint(DateTimeLevel.Month, startTime));
                endTimes.Add(TimePointConvert.PreTimePoint(DateTimeLevel.Month, endTime));
            }
            else if (level == DateTimeLevel.Month)
            {
                startTimes.Add(TimePointConvert.PreTimePoint(DateTimeLevel.Year, startTime));
                endTimes.Add(TimePointConvert.PreTimePoint(DateTimeLevel.Year, endTime));
            }
            else
            {
                return(new List <List <TrafficChart <DateTime, int> > >());
            }

            //环比
            startTimes.Add(TimePointConvert.PreTimePoint(level, startTime));
            endTimes.Add(TimePointConvert.PreTimePoint(level, endTime));
            return(startTimes.Select((t, i) => SelectCharts(dataId, level, startTimes[0], t, endTimes[i])).ToList());
        }
Exemplo n.º 15
0
        public List <TrafficChart <string, int> > StatisticsByRegion([FromRoute] string dataId, [FromQuery] DateTime startTime, [FromQuery] DateTime endTime)
        {
            dataId = Uri.UnescapeDataString(dataId);

            TrafficRegion region = _memoryCache.GetRegion(dataId);

            string remark = region == null?string.Empty:region.RegionName;

            DateTimeLevel level      = DateTimeLevel.Hour;
            string        timeFormat = TimePointConvert.TimeFormat(level);

            return(_context.Events
                   .Where(e => e.DataId == dataId && e.DateTime >= startTime && e.DateTime <= endTime)
                   .GroupBy(e => TimePointConvert.CurrentTimePoint(level, e.DateTime))
                   .OrderBy(g => g.Key)
                   .Select(g => new TrafficChart <string, int>
            {
                Axis = g.Key.ToString(timeFormat),
                Value = g.Count(),
                Remark = remark
            }).ToList());
        }
Exemplo n.º 16
0
        public List <TrafficChart <string, int> > StatisticsByRoad(int crossingId, [FromQuery] DateTime startTime, [FromQuery] DateTime endTime)
        {
            HashSet <string> dataIds = new HashSet <string>(
                _memoryCache.GetRegions()
                .Where(r => r.Channel.CrossingId == crossingId)
                .Select(p => p.DataId));
            string remark = _memoryCache.GetRegions().Any(r => r.Channel.CrossingId == crossingId)
                ? _memoryCache.GetRegions().First(r => r.Channel.CrossingId == crossingId).Channel.RoadCrossing?.CrossingName
                : string.Empty;
            DateTimeLevel level      = DateTimeLevel.Hour;
            string        timeFormat = TimePointConvert.TimeFormat(level);

            return(_context.Events
                   .Where(e => dataIds.Contains(e.DataId) && e.DateTime >= startTime && e.DateTime <= endTime)
                   .GroupBy(e => TimePointConvert.CurrentTimePoint(level, e.DateTime))
                   .OrderBy(g => g.Key)
                   .Select(g => new TrafficChart <string, int>
            {
                Axis = g.Key.ToString(timeFormat),
                Value = g.Count(),
                Remark = remark
            })
                   .ToList());
        }
Exemplo n.º 17
0
        /// <summary>
        /// 初始化数据库
        /// </summary>
        private async void InitDb()
        {
            _logger.LogInformation((int)LogEvent.系统, "初始化数据库");

            DateTime minTime = TimePointConvert.CurrentTimePoint(BranchDbConvert.DateLevel);

            using (IServiceScope serviceScope = _serviceProvider.CreateScope())
            {
                using (FlowContext context = serviceScope.ServiceProvider.GetRequiredService <FlowContext>())
                {
                    if (context.Database.EnsureCreated())
                    {
                        #region 用户
                        _logger.LogInformation((int)LogEvent.系统, "创建管理员用户");
                        UserManager <IdentityUser> userManager = serviceScope.ServiceProvider.GetRequiredService <UserManager <IdentityUser> >();
                        await userManager.CreateAsync(new IdentityUser("admin"), "123456");

                        #endregion

                        #region 权限
                        _logger.LogInformation((int)LogEvent.系统, "创建权限");
                        IdentityUser adminUser = await userManager.FindByNameAsync("admin");

                        List <YumekoJabami.Models.Claim> claims = new List <YumekoJabami.Models.Claim>
                        {
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02000000", Descirption = "智慧交通视频检测系统"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02010000", Descirption = "设备管理"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02010100", Descirption = "设备信息维护"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02010200", Descirption = "设备位置维护"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02010300", Descirption = "国标网关设置"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02010400", Descirption = "校时配置"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02010500", Descirption = "设备操作"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02010600", Descirption = "设备运行状态"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02010700", Descirption = "视频信息维护"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02010800", Descirption = "视频位置维护"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02020000", Descirption = "数据分析"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02020100", Descirption = "通行信息查询"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02020200", Descirption = "流量数据分析"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02020300", Descirption = "IO数据监测"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02020400", Descirption = "流量分布查询"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02020500", Descirption = "拥堵趋势分析"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02020600", Descirption = "状态时间统计"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02020700", Descirption = "交通状态分析"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02030000", Descirption = "系统设置"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02030100", Descirption = "路口维护"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02030200", Descirption = "路段维护"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02030300", Descirption = "用户管理"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02030400", Descirption = "角色管理"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02030600", Descirption = "字典管理"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02030700", Descirption = "参数管理"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02030800", Descirption = "日志查询"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02030900", Descirption = "系统监控"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02040000", Descirption = "状况监测"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "02040100", Descirption = "应用检测"
                            },
                        };
                        context.TrafficClaims.AddRange(claims);
                        foreach (YumekoJabami.Models.Claim claim in claims)
                        {
                            await userManager.AddClaimAsync(adminUser, new System.Security.Claims.Claim(claim.Type, claim.Value));
                        }
                        #endregion

                        #region 字典
                        _logger.LogInformation((int)LogEvent.系统, "创建字典");
                        List <Code> flowCodes = new List <Code>();

                        flowCodes.AddRange(Enum.GetValues(typeof(LogEvent))
                                           .Cast <LogEvent>()
                                           .Select(e => new Code {
                            Key = typeof(LogEvent).Name, Value = (int)e, Description = e.ToString()
                        }));

                        flowCodes.Add(new Code
                        {
                            Key         = "LogLevel",
                            Value       = (int)LogLevel.Debug,
                            Description = "调试"
                        });

                        flowCodes.Add(new Code
                        {
                            Key         = "LogLevel",
                            Value       = (int)LogLevel.Information,
                            Description = "消息"
                        });

                        flowCodes.Add(new Code
                        {
                            Key         = "LogLevel",
                            Value       = (int)LogLevel.Warning,
                            Description = "警告"
                        });

                        flowCodes.Add(new Code
                        {
                            Key         = "LogLevel",
                            Value       = (int)LogLevel.Error,
                            Description = "错误"
                        });


                        flowCodes.AddRange(Enum.GetValues(typeof(ChannelType))
                                           .Cast <ChannelType>()
                                           .Select(e => new Code {
                            Key = typeof(ChannelType).Name, Value = (int)e, Description = e.ToString()
                        }));

                        flowCodes.AddRange(Enum.GetValues(typeof(DeviceModel))
                                           .Cast <DeviceModel>()
                                           .Select(e => new Code {
                            Key = typeof(DeviceModel).Name, Value = (int)e, Description = e.ToString()
                        }));

                        flowCodes.AddRange(Enum.GetValues(typeof(DeviceStatus))
                                           .Cast <DeviceStatus>()
                                           .Select(e => new Code {
                            Key = typeof(DeviceStatus).Name, Value = (int)e, Description = e.ToString()
                        }));

                        flowCodes.AddRange(Enum.GetValues(typeof(RtspProtocol))
                                           .Cast <RtspProtocol>()
                                           .Select(e => new Code {
                            Key = typeof(RtspProtocol).Name, Value = (int)e, Description = e.ToString()
                        }));

                        flowCodes.AddRange(Enum.GetValues(typeof(SectionDirection))
                                           .Cast <SectionDirection>()
                                           .Select(e => new Code {
                            Key = typeof(SectionDirection).Name, Value = (int)e, Description = e.ToString()
                        }));

                        flowCodes.AddRange(Enum.GetValues(typeof(SectionType))
                                           .Cast <SectionType>()
                                           .Select(e => new Code {
                            Key = typeof(SectionType).Name, Value = (int)e, Description = e.ToString()
                        }));

                        flowCodes.AddRange(Enum.GetValues(typeof(Age))
                                           .Cast <Age>()
                                           .Select(e => new Code {
                            Key = typeof(Age).Name, Value = (int)e, Description = e.ToString()
                        }));

                        flowCodes.AddRange(Enum.GetValues(typeof(NonVehicle))
                                           .Cast <NonVehicle>()
                                           .Select(e => new Code {
                            Key = typeof(NonVehicle).Name, Value = (int)e, Description = e.ToString()
                        }));

                        flowCodes.AddRange(Enum.GetValues(typeof(CarColor))
                                           .Cast <CarColor>()
                                           .Select(e => new Code {
                            Key = typeof(CarColor).Name, Value = (int)e, Description = e.ToString()
                        }));

                        flowCodes.AddRange(Enum.GetValues(typeof(CarType))
                                           .Cast <CarType>()
                                           .Select(e => new Code {
                            Key = typeof(CarType).Name, Value = (int)e, Description = e.ToString()
                        }));

                        flowCodes.AddRange(Enum.GetValues(typeof(FlowDirection))
                                           .Cast <FlowDirection>()
                                           .Select(e => new Code {
                            Key = typeof(FlowDirection).Name, Value = (int)e, Description = e.ToString()
                        }));

                        flowCodes.Add(new Code
                        {
                            Key         = "VehicleType",
                            Value       = (int)FlowType.轮车,
                            Description = FlowType.轮车.ToString()
                        });
                        flowCodes.Add(new Code
                        {
                            Key         = "VehicleType",
                            Value       = (int)FlowType.卡车,
                            Description = FlowType.卡车.ToString()
                        });
                        flowCodes.Add(new Code
                        {
                            Key         = "VehicleType",
                            Value       = (int)FlowType.客车,
                            Description = FlowType.客车.ToString()
                        });

                        flowCodes.Add(new Code
                        {
                            Key         = "VehicleType",
                            Value       = (int)FlowType.轿车,
                            Description = FlowType.轿车.ToString()
                        });

                        flowCodes.Add(new Code
                        {
                            Key         = "VehicleType",
                            Value       = (int)FlowType.面包车,
                            Description = FlowType.面包车.ToString()
                        });
                        flowCodes.Add(new Code
                        {
                            Key         = "BikeType",
                            Value       = (int)FlowType.自行车,
                            Description = FlowType.自行车.ToString()
                        });
                        flowCodes.Add(new Code
                        {
                            Key         = "BikeType",
                            Value       = (int)FlowType.摩托车,
                            Description = FlowType.摩托车.ToString()
                        });
                        flowCodes.Add(new Code
                        {
                            Key         = "PedestrainType",
                            Value       = (int)FlowType.行人,
                            Description = FlowType.行人.ToString()
                        });
                        flowCodes.Add(new Code
                        {
                            Key         = "FlowType",
                            Value       = (int)FlowType.平均速度,
                            Description = FlowType.平均速度.ToString()
                        });
                        flowCodes.Add(new Code
                        {
                            Key         = "FlowType",
                            Value       = (int)FlowType.车头时距,
                            Description = FlowType.车头时距.ToString()
                        });
                        flowCodes.Add(new Code
                        {
                            Key         = "FlowType",
                            Value       = (int)FlowType.车头间距,
                            Description = FlowType.车头间距.ToString()
                        });
                        flowCodes.Add(new Code
                        {
                            Key         = "FlowType",
                            Value       = (int)FlowType.时间占有率,
                            Description = FlowType.时间占有率.ToString()
                        });
                        flowCodes.Add(new Code
                        {
                            Key         = "FlowType",
                            Value       = (int)FlowType.空间占有率,
                            Description = FlowType.空间占有率.ToString()
                        });

                        flowCodes.AddRange(Enum.GetValues(typeof(LaneDirection))
                                           .Cast <LaneDirection>()
                                           .Select(e => new Code {
                            Key = typeof(LaneDirection).Name, Value = (int)e, Description = e.ToString()
                        }));

                        flowCodes.AddRange(Enum.GetValues(typeof(LaneType))
                                           .Cast <LaneType>()
                                           .Select(e => new Code {
                            Key = typeof(LaneType).Name, Value = (int)e, Description = e.ToString()
                        }));

                        flowCodes.AddRange(Enum.GetValues(typeof(PlateType))
                                           .Cast <PlateType>()
                                           .Select(e => new Code {
                            Key = typeof(PlateType).Name, Value = (int)e, Description = e.ToString()
                        }));

                        flowCodes.AddRange(Enum.GetValues(typeof(Sex))
                                           .Cast <Sex>()
                                           .Select(e => new Code {
                            Key = typeof(Sex).Name, Value = (int)e, Description = e.ToString()
                        }));

                        flowCodes.AddRange(Enum.GetValues(typeof(TrafficStatus))
                                           .Cast <TrafficStatus>()
                                           .Select(e => new Code {
                            Key = typeof(TrafficStatus).Name, Value = (int)e, Description = e.ToString()
                        }));

                        flowCodes.AddRange(Enum.GetValues(typeof(UpperColor))
                                           .Cast <UpperColor>()
                                           .Select(e => new Code {
                            Key = typeof(UpperColor).Name, Value = (int)e, Description = e.ToString()
                        }));

                        flowCodes.AddRange(Enum.GetValues(typeof(VideoStructType))
                                           .Cast <VideoStructType>()
                                           .Select(e => new Code {
                            Key = typeof(VideoStructType).Name, Value = (int)e, Description = e.ToString()
                        }));

                        flowCodes.Add(new Code
                        {
                            Key         = "FlowDateLevel",
                            Value       = (int)DateTimeLevel.Minute,
                            Description = "一分钟"
                        });
                        flowCodes.Add(new Code
                        {
                            Key         = "FlowDateLevel",
                            Value       = (int)DateTimeLevel.FiveMinutes,
                            Description = "五分钟"
                        });
                        flowCodes.Add(new Code
                        {
                            Key         = "FlowDateLevel",
                            Value       = (int)DateTimeLevel.FifteenMinutes,
                            Description = "十五分钟"
                        });
                        flowCodes.Add(new Code
                        {
                            Key         = "FlowDateLevel",
                            Value       = (int)DateTimeLevel.Hour,
                            Description = "小时"
                        });
                        flowCodes.Add(new Code
                        {
                            Key         = "FlowDateLevel",
                            Value       = (int)DateTimeLevel.Day,
                            Description = "天"
                        });
                        flowCodes.Add(new Code
                        {
                            Key         = "FlowDateLevel",
                            Value       = (int)DateTimeLevel.Month,
                            Description = "月"
                        });

                        flowCodes.Add(new Code
                        {
                            Key         = "CongestionDateLevel",
                            Value       = (int)DateTimeLevel.Hour,
                            Description = "小时"
                        });
                        flowCodes.Add(new Code
                        {
                            Key         = "CongestionDateLevel",
                            Value       = (int)DateTimeLevel.Day,
                            Description = "天"
                        });
                        flowCodes.Add(new Code
                        {
                            Key         = "CongestionDateLevel",
                            Value       = (int)DateTimeLevel.Month,
                            Description = "月"
                        });

                        flowCodes.Add(new Code
                        {
                            Key         = "StatusTimeDateLevel",
                            Value       = (int)DateTimeLevel.Hour,
                            Description = "小时"
                        });
                        flowCodes.Add(new Code
                        {
                            Key         = "StatusTimeDateLevel",
                            Value       = (int)DateTimeLevel.Day,
                            Description = "天"
                        });
                        flowCodes.Add(new Code
                        {
                            Key         = "StatusTimeDateLevel",
                            Value       = (int)DateTimeLevel.Month,
                            Description = "月"
                        });
                        context.Codes.AddRange(flowCodes);

                        #endregion

                        context.Version.Add(new TrafficVersion
                        {
                            Version = Assembly.GetExecutingAssembly().GetName().Version.ToString()
                        });
                        context.SaveChanges();
                    }
                    else
                    {
                        try
                        {
                            LaneFlow laneFlow = context.LaneFlows_One.OrderByDescending(f => f.Id).FirstOrDefault();
                            if (laneFlow != null &&
                                TimePointConvert.CurrentTimePoint(BranchDbConvert.DateLevel, laneFlow.DateTime) != minTime)
                            {
                                context.ChangeDatabase(BranchDbConvert.GetTableName(laneFlow.DateTime));
                            }

                            VideoVehicle vehicle = context.Vehicles.OrderByDescending(v => v.Id).FirstOrDefault();
                            if (vehicle != null &&
                                TimePointConvert.CurrentTimePoint(BranchDbConvert.DateLevel, vehicle.DateTime) != minTime)
                            {
                                context.ChangeVehicleTable(BranchDbConvert.GetTableName(vehicle.DateTime));
                            }

                            VideoBike bike = context.Bikes.OrderByDescending(v => v.Id).FirstOrDefault();
                            if (bike != null &&
                                TimePointConvert.CurrentTimePoint(BranchDbConvert.DateLevel, bike.DateTime) != minTime)
                            {
                                context.ChangeBikeTable(BranchDbConvert.GetTableName(bike.DateTime));
                            }

                            VideoPedestrain pedestrain = context.Pedestrains.OrderByDescending(v => v.Id).FirstOrDefault();
                            if (pedestrain != null &&
                                TimePointConvert.CurrentTimePoint(BranchDbConvert.DateLevel, pedestrain.DateTime) != minTime)
                            {
                                context.ChangePedestrainTable(BranchDbConvert.GetTableName(pedestrain.DateTime));
                            }
                        }
                        catch (MySqlException)
                        {
                        }
                    }
                }
            }
        }
Exemplo n.º 18
0
 /// <summary>
 /// 查询图表
 /// </summary>
 /// <param name="queryable">数据源</param>
 /// <param name="level">时间级别</param>
 /// <param name="baseTime">基准时间</param>
 /// <param name="startTime">开始时间</param>
 /// <param name="flowTypes">数据类型</param>
 /// <returns>查询结果</returns>
 protected List <TrafficChart <DateTime, int, LaneFlow> > SelectChart(IQueryable <LaneFlow> queryable, DateTimeLevel level, DateTime baseTime, DateTime startTime, FlowType[] flowTypes)
 {
     try
     {
         IQueryable <IGrouping <DateTime, LaneFlow> > groupQueryable =
             Group(queryable, level);
         string   timeFormat = TimePointConvert.TimeFormat(level);
         TimeSpan span       = TimePointConvert.CurrentTimePoint(level, baseTime) - TimePointConvert.CurrentTimePoint(level, startTime);
         if (flowTypes == null || flowTypes.Length == 0)
         {
             return(groupQueryable
                    .Select(g => new TrafficChart <DateTime, int, LaneFlow>
             {
                 Axis = g.Key.Add(span),
                 Remark = g.Key.ToString(timeFormat),
                 Value = g.Sum(f => f.Bikes + f.Buss + f.Cars + f.Motorcycles
                               + f.Persons + f.Tricycles + f.Trucks + f.Vans)
             })
                    .ToList());
         }
         else if (flowTypes.Contains(FlowType.平均速度))
         {
             return(groupQueryable
                    .Select(g => new TrafficChart <DateTime, int, LaneFlow>
             {
                 Axis = g.Key.Add(span),
                 Remark = g.Key.ToString(timeFormat),
                 Value = g.Sum(f => f.TravelTime) > 0
                             ? Convert.ToInt32(g.Sum(f => f.Distance) / g.Sum(f => f.TravelTime) * 3600 / 1000)
                             : 0
             })
                    .ToList());
         }
         else if (flowTypes.Contains(FlowType.车头时距))
         {
             return(groupQueryable
                    .Select(g => new TrafficChart <DateTime, int, LaneFlow>
             {
                 Axis = g.Key.Add(span),
                 Remark = g.Key.ToString(timeFormat),
                 Value = g.Sum(f => f.Count) > 0
                         ? Convert.ToInt32(g.Sum(f => f.HeadDistance) / g.Sum(f => f.Count))
                         : 0
             })
                    .ToList());
         }
         else if (flowTypes.Contains(FlowType.车头间距))
         {
             return(groupQueryable
                    .Select(g => new TrafficChart <DateTime, int, LaneFlow>
             {
                 Axis = g.Key.Add(span),
                 Remark = g.Key.ToString(timeFormat),
                 Value = g.Sum(f => f.Count) > 0 && g.Sum(f => f.TravelTime) > 0
                     ? Convert.ToInt32(g.Sum(f => f.HeadDistance) / g.Sum(f => f.Count) * (g.Sum(f => f.Distance) / g.Sum(f => f.TravelTime)))
                     : 0
             })
                    .ToList());
         }
         else if (flowTypes.Contains(FlowType.空间占有率))
         {
             return(groupQueryable
                    .Select(g => new TrafficChart <DateTime, int, LaneFlow>
             {
                 Axis = g.Key.Add(span),
                 Remark = g.Key.ToString(timeFormat),
                 Value = g.Sum(f => f.Count) > 0
                         ? Convert.ToInt32(g.Sum(f => f.Occupancy) / g.Sum(f => f.Count))
                         : 0
             })
                    .ToList());
         }
         else if (flowTypes.Contains(FlowType.时间占有率))
         {
             return(groupQueryable
                    .Select(g => new TrafficChart <DateTime, int, LaneFlow>
             {
                 Axis = g.Key.Add(span),
                 Remark = g.Key.ToString(timeFormat),
                 Value = g.Sum(f => f.Count) > 0
                         ? Convert.ToInt32(g.Sum(f => f.TimeOccupancy) / g.Sum(f => f.Count))
                         : 0
             })
                    .ToList());
         }
         else
         {
             return(groupQueryable
                    .Select(g => new TrafficChart <DateTime, int, LaneFlow>
             {
                 Axis = g.Key.Add(span),
                 Remark = g.Key.ToString(timeFormat),
                 Value = g.Sum(f => (flowTypes.Contains(FlowType.自行车) ? f.Bikes : 0)
                               + (flowTypes.Contains(FlowType.客车) ? f.Buss : 0)
                               + (flowTypes.Contains(FlowType.轿车) ? f.Cars : 0)
                               + (flowTypes.Contains(FlowType.摩托车) ? f.Motorcycles : 0)
                               + (flowTypes.Contains(FlowType.轮车) ? f.Tricycles : 0)
                               + (flowTypes.Contains(FlowType.卡车) ? f.Trucks : 0)
                               + (flowTypes.Contains(FlowType.行人) ? f.Persons : 0)
                               + (flowTypes.Contains(FlowType.面包车) ? f.Vans : 0)),
                 Data = new LaneFlow
                 {
                     DataId = g.First().DataId,
                     Cars = g.Sum(f => f.Cars),
                     Tricycles = g.Sum(f => f.Tricycles),
                     Trucks = g.Sum(f => f.Trucks),
                     Vans = g.Sum(f => f.Vans),
                     Buss = g.Sum(f => f.Buss),
                     Motorcycles = g.Sum(f => f.Motorcycles),
                     Bikes = g.Sum(f => f.Bikes),
                     Persons = g.Sum(f => f.Persons),
                     LaneName = _memoryCache.GetLane(g.First().DataId).LaneName,
                     FlowDirection_Desc = _memoryCache.GetLane(g.First().DataId).FlowDirection_Desc
                 }
             })
                    .ToList());
         }
     }
     catch
     {
         return(new List <TrafficChart <DateTime, int, LaneFlow> >());
     }
 }
Exemplo n.º 19
0
        public void QueryList()
        {
            DateTime             startDate = new DateTime(2019, 5, 10);
            DateTime             endDate   = new DateTime(2019, 5, 11);
            int                  days      = Convert.ToInt32((endDate - startDate).TotalDays + 1);
            int                  months    = startDate.Month == endDate.Month ? 1 : 2;
            List <DensityDevice> devices   = DensityDbSimulator.CreateDensityDevice(TestInit.ServiceProvider, 1, 1, 2, "127.0.0.1", true);

            DensityDbSimulator.CreateData(TestInit.ServiceProvider, devices, DataCreateMode.Sequence, startDate, endDate, true);
            DensitiesManager manager = TestInit.ServiceProvider.GetRequiredService <DensitiesManager>();
            int average = 720;

            foreach (DensityDevice device in devices)
            {
                foreach (var relation in device.DensityDevice_DensityChannels)
                {
                    foreach (TrafficRegion region in relation.Channel.Regions)
                    {
                        var oneMinuteList = manager.QueryList(region.DataId, DateTimeLevel.Minute, startDate, endDate.AddDays(1).AddMinutes(-1));
                        //验证查询数量
                        Assert.AreEqual(24 * 60 * days, oneMinuteList.Count);
                        //验证平均密度
                        Assert.AreEqual(average, Convert.ToInt32(oneMinuteList.Average(d => d.Value)));

                        var fiveMinuteList = manager.QueryList(region.DataId, DateTimeLevel.FiveMinutes, startDate, endDate.AddDays(1).AddMinutes(-5));
                        Assert.AreEqual(24 * 60 / 5 * days, fiveMinuteList.Count);
                        Assert.AreEqual(average, Convert.ToInt32(fiveMinuteList.Average(d => d.Value)));

                        var fifteenMinuteList = manager.QueryList(region.DataId, DateTimeLevel.FifteenMinutes, startDate, endDate.AddDays(1).AddMinutes(-15));
                        Assert.AreEqual(24 * 60 / 15 * days, fifteenMinuteList.Count);
                        Assert.AreEqual(average, Convert.ToInt32(fifteenMinuteList.Average(d => d.Value)));

                        var sixtyMinuteList = manager.QueryList(region.DataId, DateTimeLevel.Hour, startDate, endDate.AddDays(1).AddHours(-1));
                        Assert.AreEqual(24 * days, sixtyMinuteList.Count);
                        Assert.AreEqual(average, Convert.ToInt32(sixtyMinuteList.Average(d => d.Value)));

                        var dayList = manager.QueryList(region.DataId, DateTimeLevel.Day, startDate, endDate);
                        Assert.AreEqual(days, dayList.Count);
                        Assert.AreEqual(average, Convert.ToInt32(dayList.Average(d => d.Value)));

                        var monthList = manager.QueryList(region.DataId, DateTimeLevel.Month, TimePointConvert.CurrentTimePoint(DateTimeLevel.Month, startDate), TimePointConvert.CurrentTimePoint(DateTimeLevel.Month, endDate));
                        Assert.AreEqual(months, monthList.Count);
                        Assert.AreEqual(average, Convert.ToInt32(monthList.Average(d => d.Value)));
                    }
                }
            }
        }
Exemplo n.º 20
0
        public void QueryComparison()
        {
            //创建某天的模拟数据
            DateTime             startDate = new DateTime(2019, 7, 1);
            List <DensityDevice> devices   = DensityDbSimulator.CreateDensityDevice(TestInit.ServiceProvider, 1, 1, 2, "", true);
            List <DateTime>      dates     = new List <DateTime>
            {
                startDate.AddYears(-1),
                startDate.AddMonths(-1),
                startDate.AddDays(-1),
                startDate
            };

            DensityDbSimulator.CreateData(TestInit.ServiceProvider, devices, DataCreateMode.Sequence, dates, true);
            DensitiesManager manager = TestInit.ServiceProvider.GetRequiredService <DensitiesManager>();

            foreach (DensityDevice device in devices)
            {
                foreach (var relation in device.DensityDevice_DensityChannels)
                {
                    foreach (TrafficRegion region in relation.Channel.Regions)
                    {
                        //验证5分钟
                        var fiveCharts = manager.QueryComparison(region.DataId, DateTimeLevel.FiveMinutes, startDate, startDate.AddDays(1).AddMinutes(-5));
                        for (int i = 0; i < fiveCharts.Count; ++i)
                        {
                            fiveCharts[i] = fiveCharts[i].OrderBy(c => c.Axis).ToList();
                        }
                        //验证同比环比的图表时间对其到第一个时间段
                        Assert.AreEqual(startDate, fiveCharts[0][0].Axis);
                        Assert.AreEqual(startDate, fiveCharts[1][0].Axis);
                        Assert.AreEqual(startDate, fiveCharts[2][0].Axis);

                        //验证同比环比的remark是真实的时间
                        Assert.AreEqual(startDate.ToString("yyyy-MM-dd HH:mm"), fiveCharts[0][0].Remark);
                        Assert.AreEqual(startDate.AddDays(-1).ToString("yyyy-MM-dd HH:mm"), fiveCharts[1][0].Remark);
                        Assert.AreEqual(startDate.AddMinutes(-5).ToString("yyyy-MM-dd HH:mm"), fiveCharts[2][0].Remark);
                        //验证图表中的数据数量
                        foreach (List <TrafficChart <DateTime, int> > charts in fiveCharts)
                        {
                            Assert.AreEqual(24 * 60 / 5, charts.Count);
                        }

                        var fifteenCharts = manager.QueryComparison(region.DataId, DateTimeLevel.FifteenMinutes, startDate, startDate.AddDays(1).AddMinutes(-15));
                        for (int i = 0; i < fifteenCharts.Count; ++i)
                        {
                            fifteenCharts[i] = fifteenCharts[i].OrderBy(c => c.Axis).ToList();
                        }
                        Assert.AreEqual(startDate, fifteenCharts[0][0].Axis);
                        Assert.AreEqual(startDate, fifteenCharts[1][0].Axis);
                        Assert.AreEqual(startDate, fifteenCharts[2][0].Axis);

                        Assert.AreEqual(startDate.ToString("yyyy-MM-dd HH:mm"), fifteenCharts[0][0].Remark);
                        Assert.AreEqual(startDate.AddDays(-1).ToString("yyyy-MM-dd HH:mm"), fifteenCharts[1][0].Remark);
                        Assert.AreEqual(startDate.AddMinutes(-15).ToString("yyyy-MM-dd HH:mm"), fifteenCharts[2][0].Remark);

                        foreach (List <TrafficChart <DateTime, int> > charts in fifteenCharts)
                        {
                            Assert.AreEqual(24 * 60 / 15, charts.Count);
                        }

                        var hourCharts = manager.QueryComparison(region.DataId, DateTimeLevel.Hour, startDate, startDate.AddDays(1).AddHours(-1));
                        for (int i = 0; i < hourCharts.Count; ++i)
                        {
                            hourCharts[i] = hourCharts[i].OrderBy(c => c.Axis).ToList();
                        }
                        Assert.AreEqual(startDate, hourCharts[0][0].Axis);
                        Assert.AreEqual(startDate, hourCharts[1][0].Axis);
                        Assert.AreEqual(startDate, hourCharts[2][0].Axis);

                        Assert.AreEqual(startDate.ToString("yyyy-MM-dd HH"), hourCharts[0][0].Remark);
                        Assert.AreEqual(startDate.AddDays(-1).ToString("yyyy-MM-dd HH"), hourCharts[1][0].Remark);
                        Assert.AreEqual(startDate.AddHours(-1).ToString("yyyy-MM-dd HH"), hourCharts[2][0].Remark);

                        foreach (List <TrafficChart <DateTime, int> > charts in hourCharts)
                        {
                            Assert.AreEqual(24, charts.Count);
                        }

                        var dayCharts = manager.QueryComparison(region.DataId, DateTimeLevel.Day, startDate, startDate);

                        for (int i = 0; i < dayCharts.Count; ++i)
                        {
                            dayCharts[i] = dayCharts[i].OrderBy(c => c.Axis).ToList();
                        }
                        Assert.AreEqual(startDate, dayCharts[0][0].Axis);
                        Assert.AreEqual(startDate, dayCharts[1][0].Axis);
                        Assert.AreEqual(startDate, dayCharts[2][0].Axis);

                        Assert.AreEqual(startDate.ToString("yyyy-MM-dd"), dayCharts[0][0].Remark);
                        Assert.AreEqual(startDate.AddMonths(-1).ToString("yyyy-MM-dd"), dayCharts[1][0].Remark);
                        Assert.AreEqual(startDate.AddDays(-1).ToString("yyyy-MM-dd"), dayCharts[2][0].Remark);

                        foreach (List <TrafficChart <DateTime, int> > charts in dayCharts)
                        {
                            Assert.AreEqual(1, charts.Count);
                        }

                        var monthCharts = manager.QueryComparison(region.DataId, DateTimeLevel.Month, TimePointConvert.CurrentTimePoint(DateTimeLevel.Month, startDate), TimePointConvert.CurrentTimePoint(DateTimeLevel.Month, startDate));
                        for (int i = 0; i < monthCharts.Count; ++i)
                        {
                            monthCharts[i] = monthCharts[i].OrderBy(c => c.Axis).ToList();
                        }
                        Assert.AreEqual(TimePointConvert.CurrentTimePoint(DateTimeLevel.Month, startDate), monthCharts[0][0].Axis);
                        Assert.AreEqual(TimePointConvert.CurrentTimePoint(DateTimeLevel.Month, startDate), monthCharts[1][0].Axis);
                        Assert.AreEqual(TimePointConvert.CurrentTimePoint(DateTimeLevel.Month, startDate), monthCharts[2][0].Axis);

                        Assert.AreEqual(startDate.ToString("yyyy-MM"), monthCharts[0][0].Remark);
                        Assert.AreEqual(startDate.AddYears(-1).ToString("yyyy-MM"), monthCharts[1][0].Remark);
                        Assert.AreEqual(startDate.AddMonths(-1).ToString("yyyy-MM"), monthCharts[2][0].Remark);

                        foreach (List <TrafficChart <DateTime, int> > charts in monthCharts)
                        {
                            Assert.AreEqual(1, charts.Count);
                        }
                    }
                }
            }
        }
Exemplo n.º 21
0
        public static Dictionary <TrafficRegion, int> CreateData(IServiceProvider serviceProvider, List <DensityDevice> devices, List <DataCreateMode> modes, List <DateTime> startTimes, List <DateTime> endTimes, bool initDatabase = false)
        {
            if (initDatabase)
            {
                ResetDatabase(serviceProvider);
            }



            Dictionary <TrafficRegion, int> regions = new Dictionary <TrafficRegion, int>();

            for (int i = 0; i < startTimes.Count; ++i)
            {
                DateTime           minTime = TimePointConvert.CurrentTimePoint(BranchDbConvert.DateLevel, startTimes[i]);
                DateTime           maxTime = TimePointConvert.NextTimePoint(BranchDbConvert.DateLevel, minTime);
                DensityBranchBlock branch  = new DensityBranchBlock(serviceProvider);
                branch.Open(devices, minTime, maxTime);
                Random random = new Random();
                foreach (DensityDevice device in devices)
                {
                    foreach (var relation in device.DensityDevice_DensityChannels)
                    {
                        foreach (TrafficRegion region in relation.Channel.Regions)
                        {
                            int randomValue = random.Next(1, 1000);
                            if (modes[i] == DataCreateMode.Random)
                            {
                                regions[region] = randomValue;
                            }

                            int value = 1;
                            for (int m = 0; m < 1440; ++m)
                            {
                                DateTime dataTime = startTimes[i].AddMinutes(m);
                                if (dataTime > DateTime.Now)
                                {
                                    break;
                                }
                                if (dataTime >= startTimes[i] && dataTime < endTimes[i])
                                {
                                    TrafficDensity density;
                                    if (modes[i] == DataCreateMode.Fixed)
                                    {
                                        density = new TrafficDensity
                                        {
                                            MatchId  = $"{device.Ip}_{relation.Channel.ChannelIndex}_{region.RegionIndex}",
                                            DateTime = new DateTime(dataTime.Year, dataTime.Month, dataTime.Day, dataTime.Hour, dataTime.Minute, 0),
                                            Value    = 1
                                        };
                                    }
                                    else if (modes[i] == DataCreateMode.Sequence)
                                    {
                                        density = new TrafficDensity
                                        {
                                            MatchId  = $"{device.Ip}_{relation.Channel.ChannelIndex}_{region.RegionIndex}",
                                            DateTime = new DateTime(dataTime.Year, dataTime.Month, dataTime.Day, dataTime.Hour, dataTime.Minute, 0),
                                            Value    = value
                                        };
                                    }
                                    else
                                    {
                                        density = new TrafficDensity
                                        {
                                            MatchId  = $"{device.Ip}_{relation.Channel.ChannelIndex}_{region.RegionIndex}",
                                            DateTime = new DateTime(dataTime.Year, dataTime.Month, dataTime.Day, dataTime.Hour, dataTime.Minute, 0),
                                            Value    = randomValue
                                        };
                                    }
                                    branch.Post(density);
                                }
                                ++value;
                            }
                        }
                    }
                }

                branch.Close();
                if (i == startTimes.Count - 1)
                {
                    DateTime currentTime = TimePointConvert.CurrentTimePoint(BranchDbConvert.DateLevel);
                    if (minTime != currentTime)
                    {
                        using (DensityContext context = serviceProvider.GetRequiredService <DensityContext>())
                        {
                            context.ChangeDatabase(BranchDbConvert.GetTableName(minTime));
                        }
                        branch.SwitchBranch(maxTime, TimePointConvert.NextTimePoint(BranchDbConvert.DateLevel, maxTime));
                    }
                }
                else
                {
                    DateTime nextItem = TimePointConvert.CurrentTimePoint(BranchDbConvert.DateLevel, startTimes[i + 1]);
                    if (minTime != nextItem)
                    {
                        using (DensityContext context = serviceProvider.GetRequiredService <DensityContext>())
                        {
                            context.ChangeDatabase(BranchDbConvert.GetTableName(minTime));
                        }
                        branch.SwitchBranch(maxTime, TimePointConvert.NextTimePoint(BranchDbConvert.DateLevel, maxTime));
                    }
                }
            }

            return(regions);
        }
Exemplo n.º 22
0
        public void QueryList_ByLane()
        {
            LaneFlowManager_Alone service = TestInit.ServiceProvider.CreateScope().ServiceProvider.GetRequiredService <LaneFlowManager_Alone>();

            foreach (FlowDevice device in _devices)
            {
                foreach (var relation in device.FlowDevice_FlowChannels)
                {
                    foreach (Lane lane in relation.Channel.Lanes)
                    {
                        var list1 = service.QueryList(lane.DataId, DateTimeLevel.Minute, _startDate, _startDate.AddDays(_days).AddMinutes(-1));
                        Assert.AreEqual(24 * 60 * _days, list1.Count);
                        for (int i = 0; i < list1.Count; ++i)
                        {
                            Assert.AreEqual(_datas[lane.DataId][i].Total, list1[i].Total);
                            Assert.IsTrue(Math.Abs(_datas[lane.DataId][i].AverageSpeed - list1[i].AverageSpeed) < 0.1);
                            Assert.IsTrue(Math.Abs(_datas[lane.DataId][i].HeadDistance - list1[i].HeadDistance) < 0.1);
                            Assert.IsTrue(Math.Abs(_datas[lane.DataId][i].HeadSpace - list1[i].HeadSpace) < 0.1);
                            Assert.AreEqual(_datas[lane.DataId][i].Occupancy, list1[i].Occupancy);
                            Assert.AreEqual(_datas[lane.DataId][i].TimeOccupancy, list1[i].TimeOccupancy);
                        }

                        var list5  = service.QueryList(lane.DataId, DateTimeLevel.FiveMinutes, _startDate, _startDate.AddDays(_days).AddMinutes(-1));
                        var datas5 = _datas[lane.DataId]
                                     .GroupBy(f => TimePointConvert.CurrentTimePoint(DateTimeLevel.FiveMinutes, f.DateTime))
                                     .Select(g => new LaneFlow
                        {
                            Cars          = g.Sum(f => f.Cars),
                            Vans          = g.Sum(f => f.Vans),
                            Tricycles     = g.Sum(f => f.Tricycles),
                            Trucks        = g.Sum(f => f.Trucks),
                            Buss          = g.Sum(f => f.Buss),
                            Motorcycles   = g.Sum(f => f.Motorcycles),
                            Bikes         = g.Sum(f => f.Bikes),
                            Persons       = g.Sum(f => f.Persons),
                            Occupancy     = g.Sum(f => f.Occupancy),
                            TimeOccupancy = g.Sum(f => f.TimeOccupancy),
                            HeadDistance  = g.Sum(f => f.HeadDistance),
                            TravelTime    = g.Sum(f => f.TravelTime),
                            Distance      = g.Sum(f => f.Distance),
                            Count         = g.Count()
                        }).ToList();
                        for (int i = 0; i < list5.Count; ++i)
                        {
                            Assert.AreEqual(datas5[i].Total, list5[i].Total);
                            Assert.IsTrue(Math.Abs(datas5[i].AverageSpeed - list5[i].AverageSpeed) < 0.1);
                            Assert.IsTrue(Math.Abs(datas5[i].HeadDistance - list5[i].HeadDistance) < 0.1);
                            Assert.IsTrue(Math.Abs(datas5[i].HeadSpace - list5[i].HeadSpace) < 0.1);
                            Assert.AreEqual(datas5[i].Occupancy, list5[i].Occupancy);
                            Assert.AreEqual(datas5[i].TimeOccupancy, list5[i].TimeOccupancy);
                        }

                        var list15 = service.QueryList(lane.DataId, DateTimeLevel.FifteenMinutes, _startDate, _startDate.AddDays(_days).AddMinutes(-1));

                        var datas15 = _datas[lane.DataId]
                                      .GroupBy(f => TimePointConvert.CurrentTimePoint(DateTimeLevel.FifteenMinutes, f.DateTime))
                                      .Select(g => new LaneFlow
                        {
                            Cars          = g.Sum(f => f.Cars),
                            Vans          = g.Sum(f => f.Vans),
                            Tricycles     = g.Sum(f => f.Tricycles),
                            Trucks        = g.Sum(f => f.Trucks),
                            Buss          = g.Sum(f => f.Buss),
                            Motorcycles   = g.Sum(f => f.Motorcycles),
                            Bikes         = g.Sum(f => f.Bikes),
                            Persons       = g.Sum(f => f.Persons),
                            Occupancy     = g.Sum(f => f.Occupancy),
                            TimeOccupancy = g.Sum(f => f.TimeOccupancy),
                            HeadDistance  = g.Sum(f => f.HeadDistance),
                            TravelTime    = g.Sum(f => f.TravelTime),
                            Distance      = g.Sum(f => f.Distance),
                            Count         = g.Count()
                        }).ToList();
                        for (int i = 0; i < list15.Count; ++i)
                        {
                            Assert.AreEqual(datas15[i].Total, list15[i].Total);
                            Assert.IsTrue(Math.Abs(datas15[i].AverageSpeed - list15[i].AverageSpeed) < 0.1);
                            Assert.IsTrue(Math.Abs(datas15[i].HeadDistance - list15[i].HeadDistance) < 0.1);
                            Assert.IsTrue(Math.Abs(datas15[i].HeadSpace - list15[i].HeadSpace) < 0.1);
                            Assert.AreEqual(datas15[i].Occupancy, list15[i].Occupancy);
                            Assert.AreEqual(datas15[i].TimeOccupancy, list15[i].TimeOccupancy);
                        }

                        var list60 = service.QueryList(lane.DataId, DateTimeLevel.Hour, _startDate, _startDate.AddDays(_days).AddMinutes(-1));

                        var datas60 = _datas[lane.DataId]
                                      .GroupBy(f => TimePointConvert.CurrentTimePoint(DateTimeLevel.Hour, f.DateTime))
                                      .Select(g => new LaneFlow
                        {
                            Cars          = g.Sum(f => f.Cars),
                            Vans          = g.Sum(f => f.Vans),
                            Tricycles     = g.Sum(f => f.Tricycles),
                            Trucks        = g.Sum(f => f.Trucks),
                            Buss          = g.Sum(f => f.Buss),
                            Motorcycles   = g.Sum(f => f.Motorcycles),
                            Bikes         = g.Sum(f => f.Bikes),
                            Persons       = g.Sum(f => f.Persons),
                            Occupancy     = g.Sum(f => f.Occupancy),
                            TimeOccupancy = g.Sum(f => f.TimeOccupancy),
                            HeadDistance  = g.Sum(f => f.HeadDistance),
                            TravelTime    = g.Sum(f => f.TravelTime),
                            Distance      = g.Sum(f => f.Distance),
                            Count         = g.Count()
                        }).ToList();
                        for (int i = 0; i < list60.Count; ++i)
                        {
                            Assert.AreEqual(datas60[i].Total, list60[i].Total);
                            Assert.IsTrue(Math.Abs(datas60[i].AverageSpeed - list60[i].AverageSpeed) < 0.1);
                            Assert.IsTrue(Math.Abs(datas60[i].HeadDistance - list60[i].HeadDistance) < 0.1);
                            Assert.IsTrue(Math.Abs(datas60[i].HeadSpace - list60[i].HeadSpace) < 0.1);
                            Assert.AreEqual(datas60[i].Occupancy, list60[i].Occupancy);
                            Assert.AreEqual(datas60[i].TimeOccupancy, list60[i].TimeOccupancy);
                        }

                        var listDay = service.QueryList(lane.DataId, DateTimeLevel.Day, _startDate, _startDate.AddDays(_days).AddMinutes(-1));

                        var datasDay = _datas[lane.DataId]
                                       .GroupBy(f => TimePointConvert.CurrentTimePoint(DateTimeLevel.Day, f.DateTime))
                                       .Select(g => new LaneFlow
                        {
                            Cars          = g.Sum(f => f.Cars),
                            Vans          = g.Sum(f => f.Vans),
                            Tricycles     = g.Sum(f => f.Tricycles),
                            Trucks        = g.Sum(f => f.Trucks),
                            Buss          = g.Sum(f => f.Buss),
                            Motorcycles   = g.Sum(f => f.Motorcycles),
                            Bikes         = g.Sum(f => f.Bikes),
                            Persons       = g.Sum(f => f.Persons),
                            Occupancy     = g.Sum(f => f.Occupancy),
                            TimeOccupancy = g.Sum(f => f.TimeOccupancy),
                            HeadDistance  = g.Sum(f => f.HeadDistance),
                            TravelTime    = g.Sum(f => f.TravelTime),
                            Distance      = g.Sum(f => f.Distance),
                            Count         = g.Count()
                        }).ToList();
                        for (int i = 0; i < listDay.Count; ++i)
                        {
                            Assert.AreEqual(datasDay[i].Total, listDay[i].Total);
                            Assert.IsTrue(Math.Abs(datasDay[i].AverageSpeed - listDay[i].AverageSpeed) < 0.1);
                            Assert.IsTrue(Math.Abs(datasDay[i].HeadDistance - listDay[i].HeadDistance) < 0.1);
                            Assert.IsTrue(Math.Abs(datasDay[i].HeadSpace - listDay[i].HeadSpace) < 0.1);
                            Assert.AreEqual(datasDay[i].Occupancy, listDay[i].Occupancy);
                            Assert.AreEqual(datasDay[i].TimeOccupancy, listDay[i].TimeOccupancy);
                        }

                        var listMonth = service.QueryList(lane.DataId, DateTimeLevel.Month, _startDate, _startDate.AddDays(_days).AddMinutes(-1));

                        var datasMonth = _datas[lane.DataId]
                                         .GroupBy(f => TimePointConvert.CurrentTimePoint(DateTimeLevel.Month, f.DateTime))
                                         .Select(g => new LaneFlow
                        {
                            Cars          = g.Sum(f => f.Cars),
                            Vans          = g.Sum(f => f.Vans),
                            Tricycles     = g.Sum(f => f.Tricycles),
                            Trucks        = g.Sum(f => f.Trucks),
                            Buss          = g.Sum(f => f.Buss),
                            Motorcycles   = g.Sum(f => f.Motorcycles),
                            Bikes         = g.Sum(f => f.Bikes),
                            Persons       = g.Sum(f => f.Persons),
                            Occupancy     = g.Sum(f => f.Occupancy),
                            TimeOccupancy = g.Sum(f => f.TimeOccupancy),
                            HeadDistance  = g.Sum(f => f.HeadDistance),
                            TravelTime    = g.Sum(f => f.TravelTime),
                            Distance      = g.Sum(f => f.Distance),
                            Count         = g.Count()
                        }).ToList();
                        for (int i = 0; i < listMonth.Count; ++i)
                        {
                            Assert.AreEqual(datasMonth[i].Total, listMonth[i].Total);
                            Assert.IsTrue(Math.Abs(datasMonth[i].AverageSpeed - datasMonth[i].AverageSpeed) < 0.1);
                            Assert.IsTrue(Math.Abs(datasMonth[i].HeadDistance - listMonth[i].HeadDistance) < 0.1);
                            Assert.IsTrue(Math.Abs(datasMonth[i].HeadSpace - listMonth[i].HeadSpace) < 0.1);
                            Assert.AreEqual(datasMonth[i].Occupancy, listMonth[i].Occupancy);
                            Assert.AreEqual(datasMonth[i].TimeOccupancy, listMonth[i].TimeOccupancy);
                        }
                    }
                }
            }
        }
Exemplo n.º 23
0
        public static Dictionary <string, List <LaneFlow> > CreateData(IServiceProvider serviceProvider, List <FlowDevice> devices, List <DataCreateMode> modes, List <DateTime> startTimes, List <DateTime> endTimes, bool initDatabase = false)
        {
            if (initDatabase)
            {
                ResetDatabase(serviceProvider);
            }
            Dictionary <string, List <LaneFlow> > datas = new Dictionary <string, List <LaneFlow> >();

            foreach (FlowDevice device in devices)
            {
                foreach (var relation in device.FlowDevice_FlowChannels)
                {
                    foreach (Lane lane in relation.Channel.Lanes)
                    {
                        datas.Add(lane.DataId, new List <LaneFlow>());
                    }
                }
            }
            for (int i = 0; i < startTimes.Count; ++i)
            {
                DateTime        minTime = TimePointConvert.CurrentTimePoint(BranchDbConvert.DateLevel, startTimes[i]);
                DateTime        maxTime = TimePointConvert.NextTimePoint(BranchDbConvert.DateLevel, minTime);
                FlowBranchBlock branch  = new FlowBranchBlock(serviceProvider);
                branch.Open(devices, minTime, maxTime);
                Random random = new Random();
                foreach (FlowDevice device in devices)
                {
                    foreach (var relation in device.FlowDevice_FlowChannels)
                    {
                        foreach (Lane lane in relation.Channel.Lanes)
                        {
                            int value = 1;
                            for (int m = 0; m < 1440; ++m)
                            {
                                DateTime dataTime = startTimes[i].AddMinutes(m);
                                if (dataTime > DateTime.Now)
                                {
                                    break;
                                }
                                if (dataTime >= startTimes[i] && dataTime < endTimes[i])
                                {
                                    LaneFlow laneFlow;
                                    if (modes[i] == DataCreateMode.Fixed)
                                    {
                                        laneFlow = new LaneFlow
                                        {
                                            DataId           = lane.DataId,
                                            DateTime         = new DateTime(dataTime.Year, dataTime.Month, dataTime.Day, dataTime.Hour, dataTime.Minute, 0),
                                            Cars             = 1,
                                            Buss             = 1,
                                            Trucks           = 1,
                                            Vans             = 1,
                                            Tricycles        = 1,
                                            Motorcycles      = 1,
                                            Bikes            = 1,
                                            Persons          = 1,
                                            AverageSpeedData = 50,
                                            HeadDistance     = 10,
                                            Occupancy        = 30,
                                            TimeOccupancy    = 40,
                                            TrafficStatus    = TrafficStatus.轻度拥堵,
                                            Count            = 1
                                        };
                                    }
                                    else if (modes[i] == DataCreateMode.Sequence)
                                    {
                                        laneFlow = new LaneFlow
                                        {
                                            DataId           = lane.DataId,
                                            DateTime         = new DateTime(dataTime.Year, dataTime.Month, dataTime.Day, dataTime.Hour, dataTime.Minute, 0),
                                            Cars             = value++,
                                            Buss             = 2,
                                            Trucks           = 3,
                                            Vans             = 4,
                                            Tricycles        = 5,
                                            Motorcycles      = 6,
                                            Bikes            = 7,
                                            Persons          = 8,
                                            AverageSpeedData = 9,
                                            HeadDistance     = 10,
                                            Occupancy        = 12,
                                            TimeOccupancy    = 13,
                                            TrafficStatus    = TrafficStatus.通畅,
                                            Count            = 1
                                        };
                                    }
                                    else
                                    {
                                        laneFlow = new LaneFlow
                                        {
                                            DataId           = lane.DataId,
                                            DateTime         = new DateTime(dataTime.Year, dataTime.Month, dataTime.Day, dataTime.Hour, dataTime.Minute, 0),
                                            Cars             = random.Next(1, 10),
                                            Buss             = random.Next(1, 10),
                                            Trucks           = random.Next(1, 10),
                                            Vans             = random.Next(1, 10),
                                            Tricycles        = random.Next(1, 10),
                                            Motorcycles      = random.Next(1, 10),
                                            Bikes            = random.Next(1, 10),
                                            Persons          = random.Next(1, 10),
                                            AverageSpeedData = random.Next(1, 10),
                                            HeadDistance     = random.Next(1, 10),
                                            Occupancy        = random.Next(1, 10),
                                            TimeOccupancy    = random.Next(1, 10),
                                            TrafficStatus    = (TrafficStatus)random.Next(1, 6),
                                            Count            = 1
                                        };
                                    }

                                    laneFlow.SectionId     = lane.Channel.RoadSection.SectionId;
                                    laneFlow.SectionType   = lane.Channel.RoadSection.SectionType;
                                    laneFlow.SectionLength = lane.Channel.RoadSection.Length;
                                    laneFlow.FreeSpeed     = lane.Channel.RoadSection.FreeSpeed;
                                    laneFlow.Distance      = laneFlow.Vehicle * lane.Length;
                                    laneFlow.TravelTime    = laneFlow.AverageSpeedData > 0
                                        ? laneFlow.Vehicle * lane.Length / Convert.ToDouble(laneFlow.AverageSpeedData * 1000 / 3600)
                                        : 0;
                                    datas[lane.DataId].Add(laneFlow);
                                    branch.Post(laneFlow);
                                }
                                ++value;
                            }
                        }
                    }
                }

                branch.Close();
                if (i == startTimes.Count - 1)
                {
                    DateTime currentTime = TimePointConvert.CurrentTimePoint(BranchDbConvert.DateLevel);
                    if (minTime != currentTime)
                    {
                        using (FlowContext context = serviceProvider.GetRequiredService <FlowContext>())
                        {
                            context.ChangeDatabase(BranchDbConvert.GetTableName(minTime));
                        }
                        branch.SwitchBranch(maxTime, TimePointConvert.NextTimePoint(BranchDbConvert.DateLevel, maxTime));
                    }
                }
                else
                {
                    DateTime nextItem = TimePointConvert.CurrentTimePoint(BranchDbConvert.DateLevel, startTimes[i + 1]);
                    if (minTime != nextItem)
                    {
                        using (FlowContext context = serviceProvider.GetRequiredService <FlowContext>())
                        {
                            context.ChangeDatabase(BranchDbConvert.GetTableName(minTime));
                        }
                        branch.SwitchBranch(maxTime, TimePointConvert.NextTimePoint(BranchDbConvert.DateLevel, maxTime));
                    }
                }
            }

            return(datas);
        }
Exemplo n.º 24
0
        public static void CreateData(IServiceProvider serviceProvider, List <FlowDevice> devices, DataCreateMode mode, DateTime startDate, DateTime endDate, bool initDatabase = false)
        {
            if (initDatabase)
            {
                using (FlowContext context = serviceProvider.CreateScope().ServiceProvider.GetRequiredService <FlowContext>())
                {
                    context.Database.EnsureDeleted();
                    context.Database.EnsureCreated();
                }
            }

            DateTime         minTime = TimePointConvert.CurrentTimePoint(BranchDbConvert.DateLevel, startDate);
            DateTime         maxTime = TimePointConvert.NextTimePoint(BranchDbConvert.DateLevel, minTime);
            VideoBranchBlock branch  = new VideoBranchBlock(serviceProvider);

            branch.Open(minTime, maxTime);
            Random random = new Random();

            for (DateTime date = startDate; date <= endDate; date = date.AddDays(1))
            {
                int value = 1;
                for (int i = 0; i < 1440; ++i)
                {
                    DateTime startTime = startDate.AddMinutes(i);
                    foreach (FlowDevice device in devices)
                    {
                        foreach (var relation in device.FlowDevice_FlowChannels)
                        {
                            foreach (Lane lane in relation.Channel.Lanes)
                            {
                                VideoVehicle    videoVehicle;
                                VideoBike       bike;
                                VideoPedestrain pedestrain;
                                if (mode == DataCreateMode.Fixed)
                                {
                                    videoVehicle = new VideoVehicle
                                    {
                                        DataId      = lane.DataId,
                                        DateTime    = new DateTime(startTime.Year, startTime.Month, startTime.Day, startTime.Hour, startTime.Minute, 0),
                                        Image       = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAA0JCgsKCA0LCgsODg0PEyAVExISEyccHhcgLikxMC4p\r\nLSwzOko+MzZGNywtQFdBRkxOUlNSMj5aYVpQYEpRUk//2wBDAQ4ODhMREyYVFSZPNS01T09PT09P\r\nT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0//wAARCAAkACoDASEA\r\nAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA\r\nAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3\r\nODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm\r\np6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEA\r\nAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSEx\r\nBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElK\r\nU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3\r\nuLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDpWXAw\r\nenaq8gVepAq0SV32/wB4fnUDAdiDTGRlaNh9T+dSBvSDPTrjpTwba1toBdWJlnlUsVP8I/GmIYs+\r\nl4+bSnX6N/8AXqIrpV3J5NqlxBclSUBRsOR7nigZmKxkQMylTyCD2I60nFAjdhsIbq7Erq3mICUI\r\nJwD2JFTNbaurY/twrjpmyX5v1zUsaAwa4Rxq0eR62R5+tQuPEeQFvdJLg8eZE4/rQgMKK0uWv724\r\nu54PtJfE8MWdqnsR9RT/ACz6H8qoRd1bVptEEE8SQu8wYIkjY3Yx0OaxZviNerFgQWfmE4OA7bPc\r\n/wD66mwy4fHVoyIV1bD7RvH2QlQfbvUcXj2TczPp8NwycCVJNm4euG6UWGTaZcNq1tdauYxCLiXa\r\nEDZwB61YwaZJh/EuRo10srj5EcgdutS6c1hd2kHn6LphJRckQkE8A+tMZtxeF9AlSF20mAGTOQrO\r\nB/Os7xp4Z0bSfDVxc2NkscygBX3MSvPbJpAL4MHm+Cogxx++bOO/Irof7Ph/vP8AmP8ACmI//9k=",
                                        Feature     = "",
                                        CarType     = 1,
                                        CarBrand    = "brand" + 1,
                                        CarColor    = 1,
                                        PlateNumber = "京A0000" + 1,
                                        PlateType   = 1
                                    };
                                    bike = new VideoBike
                                    {
                                        DataId   = lane.DataId,
                                        DateTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, startTime.Hour, startTime.Minute, 0),
                                        Image    = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAA0JCgsKCA0LCgsODg0PEyAVExISEyccHhcgLikxMC4p\r\nLSwzOko+MzZGNywtQFdBRkxOUlNSMj5aYVpQYEpRUk//2wBDAQ4ODhMREyYVFSZPNS01T09PT09P\r\nT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0//wAARCAAkACoDASEA\r\nAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA\r\nAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3\r\nODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm\r\np6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEA\r\nAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSEx\r\nBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElK\r\nU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3\r\nuLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDpWXAw\r\nenaq8gVepAq0SV32/wB4fnUDAdiDTGRlaNh9T+dSBvSDPTrjpTwba1toBdWJlnlUsVP8I/GmIYs+\r\nl4+bSnX6N/8AXqIrpV3J5NqlxBclSUBRsOR7nigZmKxkQMylTyCD2I60nFAjdhsIbq7Erq3mICUI\r\nJwD2JFTNbaurY/twrjpmyX5v1zUsaAwa4Rxq0eR62R5+tQuPEeQFvdJLg8eZE4/rQgMKK0uWv724\r\nu54PtJfE8MWdqnsR9RT/ACz6H8qoRd1bVptEEE8SQu8wYIkjY3Yx0OaxZviNerFgQWfmE4OA7bPc\r\n/wD66mwy4fHVoyIV1bD7RvH2QlQfbvUcXj2TczPp8NwycCVJNm4euG6UWGTaZcNq1tdauYxCLiXa\r\nEDZwB61YwaZJh/EuRo10srj5EcgdutS6c1hd2kHn6LphJRckQkE8A+tMZtxeF9AlSF20mAGTOQrO\r\nB/Os7xp4Z0bSfDVxc2NkscygBX3MSvPbJpAL4MHm+Cogxx++bOO/Irof7Ph/vP8AmP8ACmI//9k=",
                                        Feature  = "",
                                        BikeType = (int)NonVehicle.自行车
                                    };
                                    pedestrain = new VideoPedestrain
                                    {
                                        DataId     = lane.DataId,
                                        DateTime   = new DateTime(startTime.Year, startTime.Month, startTime.Day, startTime.Hour, startTime.Minute, 0),
                                        Image      = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAA0JCgsKCA0LCgsODg0PEyAVExISEyccHhcgLikxMC4p\r\nLSwzOko+MzZGNywtQFdBRkxOUlNSMj5aYVpQYEpRUk//2wBDAQ4ODhMREyYVFSZPNS01T09PT09P\r\nT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0//wAARCAAkACoDASEA\r\nAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA\r\nAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3\r\nODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm\r\np6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEA\r\nAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSEx\r\nBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElK\r\nU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3\r\nuLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDpWXAw\r\nenaq8gVepAq0SV32/wB4fnUDAdiDTGRlaNh9T+dSBvSDPTrjpTwba1toBdWJlnlUsVP8I/GmIYs+\r\nl4+bSnX6N/8AXqIrpV3J5NqlxBclSUBRsOR7nigZmKxkQMylTyCD2I60nFAjdhsIbq7Erq3mICUI\r\nJwD2JFTNbaurY/twrjpmyX5v1zUsaAwa4Rxq0eR62R5+tQuPEeQFvdJLg8eZE4/rQgMKK0uWv724\r\nu54PtJfE8MWdqnsR9RT/ACz6H8qoRd1bVptEEE8SQu8wYIkjY3Yx0OaxZviNerFgQWfmE4OA7bPc\r\n/wD66mwy4fHVoyIV1bD7RvH2QlQfbvUcXj2TczPp8NwycCVJNm4euG6UWGTaZcNq1tdauYxCLiXa\r\nEDZwB61YwaZJh/EuRo10srj5EcgdutS6c1hd2kHn6LphJRckQkE8A+tMZtxeF9AlSF20mAGTOQrO\r\nB/Os7xp4Z0bSfDVxc2NkscygBX3MSvPbJpAL4MHm+Cogxx++bOO/Irof7Ph/vP8AmP8ACmI//9k=",
                                        Feature    = "",
                                        Age        = (int)Age.儿童,
                                        Sex        = (int)Sex.女,
                                        UpperColor = (int)UpperColor.红
                                    };
                                }
                                else if (mode == DataCreateMode.Sequence)
                                {
                                    int temp = value;
                                    value       += 1;
                                    videoVehicle = new VideoVehicle
                                    {
                                        DataId      = lane.DataId,
                                        DateTime    = new DateTime(startTime.Year, startTime.Month, startTime.Day, startTime.Hour, startTime.Minute, 0),
                                        Image       = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAA0JCgsKCA0LCgsODg0PEyAVExISEyccHhcgLikxMC4p\r\nLSwzOko+MzZGNywtQFdBRkxOUlNSMj5aYVpQYEpRUk//2wBDAQ4ODhMREyYVFSZPNS01T09PT09P\r\nT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0//wAARCAAkACoDASEA\r\nAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA\r\nAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3\r\nODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm\r\np6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEA\r\nAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSEx\r\nBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElK\r\nU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3\r\nuLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDpWXAw\r\nenaq8gVepAq0SV32/wB4fnUDAdiDTGRlaNh9T+dSBvSDPTrjpTwba1toBdWJlnlUsVP8I/GmIYs+\r\nl4+bSnX6N/8AXqIrpV3J5NqlxBclSUBRsOR7nigZmKxkQMylTyCD2I60nFAjdhsIbq7Erq3mICUI\r\nJwD2JFTNbaurY/twrjpmyX5v1zUsaAwa4Rxq0eR62R5+tQuPEeQFvdJLg8eZE4/rQgMKK0uWv724\r\nu54PtJfE8MWdqnsR9RT/ACz6H8qoRd1bVptEEE8SQu8wYIkjY3Yx0OaxZviNerFgQWfmE4OA7bPc\r\n/wD66mwy4fHVoyIV1bD7RvH2QlQfbvUcXj2TczPp8NwycCVJNm4euG6UWGTaZcNq1tdauYxCLiXa\r\nEDZwB61YwaZJh/EuRo10srj5EcgdutS6c1hd2kHn6LphJRckQkE8A+tMZtxeF9AlSF20mAGTOQrO\r\nB/Os7xp4Z0bSfDVxc2NkscygBX3MSvPbJpAL4MHm+Cogxx++bOO/Irof7Ph/vP8AmP8ACmI//9k=",
                                        Feature     = "",
                                        CarType     = 1,
                                        CarBrand    = "brand" + temp,
                                        CarColor    = 1,
                                        PlateNumber = "京A0000" + 1,
                                        PlateType   = 1
                                    };
                                    bike = new VideoBike
                                    {
                                        DataId   = lane.DataId,
                                        DateTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, startTime.Hour, startTime.Minute, 0),
                                        Image    = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAA0JCgsKCA0LCgsODg0PEyAVExISEyccHhcgLikxMC4p\r\nLSwzOko+MzZGNywtQFdBRkxOUlNSMj5aYVpQYEpRUk//2wBDAQ4ODhMREyYVFSZPNS01T09PT09P\r\nT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0//wAARCAAkACoDASEA\r\nAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA\r\nAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3\r\nODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm\r\np6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEA\r\nAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSEx\r\nBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElK\r\nU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3\r\nuLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDpWXAw\r\nenaq8gVepAq0SV32/wB4fnUDAdiDTGRlaNh9T+dSBvSDPTrjpTwba1toBdWJlnlUsVP8I/GmIYs+\r\nl4+bSnX6N/8AXqIrpV3J5NqlxBclSUBRsOR7nigZmKxkQMylTyCD2I60nFAjdhsIbq7Erq3mICUI\r\nJwD2JFTNbaurY/twrjpmyX5v1zUsaAwa4Rxq0eR62R5+tQuPEeQFvdJLg8eZE4/rQgMKK0uWv724\r\nu54PtJfE8MWdqnsR9RT/ACz6H8qoRd1bVptEEE8SQu8wYIkjY3Yx0OaxZviNerFgQWfmE4OA7bPc\r\n/wD66mwy4fHVoyIV1bD7RvH2QlQfbvUcXj2TczPp8NwycCVJNm4euG6UWGTaZcNq1tdauYxCLiXa\r\nEDZwB61YwaZJh/EuRo10srj5EcgdutS6c1hd2kHn6LphJRckQkE8A+tMZtxeF9AlSF20mAGTOQrO\r\nB/Os7xp4Z0bSfDVxc2NkscygBX3MSvPbJpAL4MHm+Cogxx++bOO/Irof7Ph/vP8AmP8ACmI//9k=",
                                        Feature  = "",
                                        BikeType = (temp % 2 == 0 ? 2 : 3)
                                    };
                                    pedestrain = new VideoPedestrain
                                    {
                                        DataId     = lane.DataId,
                                        DateTime   = new DateTime(startTime.Year, startTime.Month, startTime.Day, startTime.Hour, startTime.Minute, 0),
                                        Image      = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAA0JCgsKCA0LCgsODg0PEyAVExISEyccHhcgLikxMC4p\r\nLSwzOko+MzZGNywtQFdBRkxOUlNSMj5aYVpQYEpRUk//2wBDAQ4ODhMREyYVFSZPNS01T09PT09P\r\nT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0//wAARCAAkACoDASEA\r\nAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA\r\nAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3\r\nODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm\r\np6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEA\r\nAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSEx\r\nBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElK\r\nU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3\r\nuLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDpWXAw\r\nenaq8gVepAq0SV32/wB4fnUDAdiDTGRlaNh9T+dSBvSDPTrjpTwba1toBdWJlnlUsVP8I/GmIYs+\r\nl4+bSnX6N/8AXqIrpV3J5NqlxBclSUBRsOR7nigZmKxkQMylTyCD2I60nFAjdhsIbq7Erq3mICUI\r\nJwD2JFTNbaurY/twrjpmyX5v1zUsaAwa4Rxq0eR62R5+tQuPEeQFvdJLg8eZE4/rQgMKK0uWv724\r\nu54PtJfE8MWdqnsR9RT/ACz6H8qoRd1bVptEEE8SQu8wYIkjY3Yx0OaxZviNerFgQWfmE4OA7bPc\r\n/wD66mwy4fHVoyIV1bD7RvH2QlQfbvUcXj2TczPp8NwycCVJNm4euG6UWGTaZcNq1tdauYxCLiXa\r\nEDZwB61YwaZJh/EuRo10srj5EcgdutS6c1hd2kHn6LphJRckQkE8A+tMZtxeF9AlSF20mAGTOQrO\r\nB/Os7xp4Z0bSfDVxc2NkscygBX3MSvPbJpAL4MHm+Cogxx++bOO/Irof7Ph/vP8AmP8ACmI//9k=",
                                        Feature    = "",
                                        Age        = (int)Age.儿童,
                                        Sex        = (temp % 2 == 0 ? 1 : 2),
                                        UpperColor = (int)UpperColor.红
                                    };
                                }
                                else
                                {
                                    videoVehicle = new VideoVehicle
                                    {
                                        DataId      = lane.DataId,
                                        DateTime    = new DateTime(startTime.Year, startTime.Month, startTime.Day, startTime.Hour, startTime.Minute, 0),
                                        Image       = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAA0JCgsKCA0LCgsODg0PEyAVExISEyccHhcgLikxMC4p\r\nLSwzOko+MzZGNywtQFdBRkxOUlNSMj5aYVpQYEpRUk//2wBDAQ4ODhMREyYVFSZPNS01T09PT09P\r\nT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0//wAARCAAkACoDASEA\r\nAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA\r\nAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3\r\nODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm\r\np6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEA\r\nAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSEx\r\nBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElK\r\nU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3\r\nuLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDpWXAw\r\nenaq8gVepAq0SV32/wB4fnUDAdiDTGRlaNh9T+dSBvSDPTrjpTwba1toBdWJlnlUsVP8I/GmIYs+\r\nl4+bSnX6N/8AXqIrpV3J5NqlxBclSUBRsOR7nigZmKxkQMylTyCD2I60nFAjdhsIbq7Erq3mICUI\r\nJwD2JFTNbaurY/twrjpmyX5v1zUsaAwa4Rxq0eR62R5+tQuPEeQFvdJLg8eZE4/rQgMKK0uWv724\r\nu54PtJfE8MWdqnsR9RT/ACz6H8qoRd1bVptEEE8SQu8wYIkjY3Yx0OaxZviNerFgQWfmE4OA7bPc\r\n/wD66mwy4fHVoyIV1bD7RvH2QlQfbvUcXj2TczPp8NwycCVJNm4euG6UWGTaZcNq1tdauYxCLiXa\r\nEDZwB61YwaZJh/EuRo10srj5EcgdutS6c1hd2kHn6LphJRckQkE8A+tMZtxeF9AlSF20mAGTOQrO\r\nB/Os7xp4Z0bSfDVxc2NkscygBX3MSvPbJpAL4MHm+Cogxx++bOO/Irof7Ph/vP8AmP8ACmI//9k=",
                                        Feature     = "",
                                        CarType     = random.Next(1, 21),
                                        CarBrand    = "brand" + random.Next(1, 100),
                                        CarColor    = random.Next(1, 13),
                                        PlateNumber = "京A0000" + random.Next(1, 9),
                                        PlateType   = random.Next(1, 29)
                                    };
                                    bike = new VideoBike
                                    {
                                        DataId   = lane.DataId,
                                        DateTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, startTime.Hour, startTime.Minute, 0),
                                        Image    = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAA0JCgsKCA0LCgsODg0PEyAVExISEyccHhcgLikxMC4p\r\nLSwzOko+MzZGNywtQFdBRkxOUlNSMj5aYVpQYEpRUk//2wBDAQ4ODhMREyYVFSZPNS01T09PT09P\r\nT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0//wAARCAAkACoDASEA\r\nAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA\r\nAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3\r\nODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm\r\np6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEA\r\nAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSEx\r\nBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElK\r\nU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3\r\nuLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDpWXAw\r\nenaq8gVepAq0SV32/wB4fnUDAdiDTGRlaNh9T+dSBvSDPTrjpTwba1toBdWJlnlUsVP8I/GmIYs+\r\nl4+bSnX6N/8AXqIrpV3J5NqlxBclSUBRsOR7nigZmKxkQMylTyCD2I60nFAjdhsIbq7Erq3mICUI\r\nJwD2JFTNbaurY/twrjpmyX5v1zUsaAwa4Rxq0eR62R5+tQuPEeQFvdJLg8eZE4/rQgMKK0uWv724\r\nu54PtJfE8MWdqnsR9RT/ACz6H8qoRd1bVptEEE8SQu8wYIkjY3Yx0OaxZviNerFgQWfmE4OA7bPc\r\n/wD66mwy4fHVoyIV1bD7RvH2QlQfbvUcXj2TczPp8NwycCVJNm4euG6UWGTaZcNq1tdauYxCLiXa\r\nEDZwB61YwaZJh/EuRo10srj5EcgdutS6c1hd2kHn6LphJRckQkE8A+tMZtxeF9AlSF20mAGTOQrO\r\nB/Os7xp4Z0bSfDVxc2NkscygBX3MSvPbJpAL4MHm+Cogxx++bOO/Irof7Ph/vP8AmP8ACmI//9k=",
                                        Feature  = "",
                                        BikeType = random.Next(2, 3)
                                    };
                                    pedestrain = new VideoPedestrain
                                    {
                                        DataId     = lane.DataId,
                                        DateTime   = new DateTime(startTime.Year, startTime.Month, startTime.Day, startTime.Hour, startTime.Minute, 0),
                                        Image      = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAA0JCgsKCA0LCgsODg0PEyAVExISEyccHhcgLikxMC4p\r\nLSwzOko+MzZGNywtQFdBRkxOUlNSMj5aYVpQYEpRUk//2wBDAQ4ODhMREyYVFSZPNS01T09PT09P\r\nT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0//wAARCAAkACoDASEA\r\nAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA\r\nAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3\r\nODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm\r\np6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEA\r\nAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSEx\r\nBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElK\r\nU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3\r\nuLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDpWXAw\r\nenaq8gVepAq0SV32/wB4fnUDAdiDTGRlaNh9T+dSBvSDPTrjpTwba1toBdWJlnlUsVP8I/GmIYs+\r\nl4+bSnX6N/8AXqIrpV3J5NqlxBclSUBRsOR7nigZmKxkQMylTyCD2I60nFAjdhsIbq7Erq3mICUI\r\nJwD2JFTNbaurY/twrjpmyX5v1zUsaAwa4Rxq0eR62R5+tQuPEeQFvdJLg8eZE4/rQgMKK0uWv724\r\nu54PtJfE8MWdqnsR9RT/ACz6H8qoRd1bVptEEE8SQu8wYIkjY3Yx0OaxZviNerFgQWfmE4OA7bPc\r\n/wD66mwy4fHVoyIV1bD7RvH2QlQfbvUcXj2TczPp8NwycCVJNm4euG6UWGTaZcNq1tdauYxCLiXa\r\nEDZwB61YwaZJh/EuRo10srj5EcgdutS6c1hd2kHn6LphJRckQkE8A+tMZtxeF9AlSF20mAGTOQrO\r\nB/Os7xp4Z0bSfDVxc2NkscygBX3MSvPbJpAL4MHm+Cogxx++bOO/Irof7Ph/vP8AmP8ACmI//9k=",
                                        Feature    = "",
                                        Age        = (int)Age.儿童,
                                        Sex        = (int)Sex.女,
                                        UpperColor = random.Next(1, 9)
                                    };
                                }
                                branch.Post(videoVehicle);
                                branch.Post(bike);
                                branch.Post(pedestrain);
                            }
                        }
                    }
                }
            }

            DateTime currentTime = TimePointConvert.CurrentTimePoint(BranchDbConvert.DateLevel, DateTime.Now);

            branch.Close();
            if (currentTime != minTime)
            {
                using (FlowContext context = serviceProvider.GetRequiredService <FlowContext>())
                {
                    context.ChangeBikeTable(BranchDbConvert.GetTableName(minTime));
                    context.ChangePedestrainTable(BranchDbConvert.GetTableName(minTime));
                    context.ChangeVehicleTable(BranchDbConvert.GetTableName(minTime));
                }
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// 初始化数据库
        /// </summary>
        private async void InitDb()
        {
            _logger.LogInformation((int)LogEvent.系统, "初始化数据库");

            DateTime minTime = TimePointConvert.CurrentTimePoint(BranchDbConvert.DateLevel);

            using (IServiceScope serviceScope = _serviceProvider.CreateScope())
            {
                using (DensityContext context = serviceScope.ServiceProvider.GetRequiredService <DensityContext>())
                {
                    if (context.Database.EnsureCreated())
                    {
                        #region 用户
                        _logger.LogInformation((int)LogEvent.系统, "创建管理员用户");
                        UserManager <IdentityUser> userManager = serviceScope.ServiceProvider.GetRequiredService <UserManager <IdentityUser> >();
                        await userManager.CreateAsync(new IdentityUser("admin"), "123456");

                        #endregion

                        #region 权限
                        _logger.LogInformation((int)LogEvent.系统, "创建权限");
                        IdentityUser adminUser = await userManager.FindByNameAsync("admin");

                        List <YumekoJabami.Models.Claim> claims = new List <YumekoJabami.Models.Claim>
                        {
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "03000000", Descirption = "智慧高点视频检测系统"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "03010000", Descirption = "设备管理"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "03010100", Descirption = "设备信息维护"
                            },
                            //new YumekoJabami.Models.Claim{ Type = ClaimTypes.Webpage, Value = "03010200", Descirption = "设备位置维护"},
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "03010300", Descirption = "国标网关设置"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "03010400", Descirption = "设备运行状态"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "03010500", Descirption = "视频信息维护"
                            },
                            //new YumekoJabami.Models.Claim{ Type = ClaimTypes.Webpage, Value = "03010600", Descirption = "视频位置维护"},
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "03020000", Descirption = "数据分析"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "03020100", Descirption = "交通密度查询"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "03020200", Descirption = "交通密度分析"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "03020300", Descirption = "拥堵事件统计"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "03020400", Descirption = "拥堵事件排名"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "03020500", Descirption = "拥堵高发时段"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "03030000", Descirption = "系统设置"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "03030100", Descirption = "路口维护"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "03030300", Descirption = "用户管理"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "03030400", Descirption = "角色管理"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "03030600", Descirption = "字典管理"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "03030700", Descirption = "参数管理"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "03030800", Descirption = "日志查询"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "03030900", Descirption = "系统监控"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "03040000", Descirption = "状况监测"
                            },
                            new YumekoJabami.Models.Claim {
                                Type = ClaimTypes.Webpage, Value = "03040100", Descirption = "应用检测"
                            },
                        };
                        context.TrafficClaims.AddRange(claims);
                        foreach (YumekoJabami.Models.Claim claim in claims)
                        {
                            await userManager.AddClaimAsync(adminUser, new Claim(claim.Type, claim.Value));
                        }
                        #endregion

                        #region 字典
                        _logger.LogInformation((int)LogEvent.系统, "创建字典");

                        List <Code> densityCodes = new List <Code>
                        {
                            new Code
                            {
                                Key         = "DensityDateLevel",
                                Value       = (int)DateTimeLevel.FiveMinutes,
                                Description = "五分钟密度"
                            },
                            new Code
                            {
                                Key         = "DensityDateLevel",
                                Value       = (int)DateTimeLevel.FifteenMinutes,
                                Description = "十五分钟密度"
                            },
                            new Code
                            {
                                Key         = "DensityDateLevel",
                                Value       = (int)DateTimeLevel.Hour,
                                Description = "一小时密度"
                            },
                            new Code
                            {
                                Key         = "DensityDateLevel",
                                Value       = (int)DateTimeLevel.Day,
                                Description = "一天密度"
                            },
                            new Code
                            {
                                Key         = "DensityDateLevel",
                                Value       = (int)DateTimeLevel.Month,
                                Description = "一月密度"
                            }
                        };

                        densityCodes.AddRange(Enum.GetValues(typeof(ChannelType))
                                              .Cast <ChannelType>()
                                              .Select(e => new Code {
                            Key = typeof(ChannelType).Name, Value = (int)e, Description = e.ToString()
                        }));

                        densityCodes.AddRange(Enum.GetValues(typeof(DeviceModel))
                                              .Cast <DeviceModel>()
                                              .Select(e => new Code {
                            Key = typeof(DeviceModel).Name, Value = (int)e, Description = e.ToString()
                        }));

                        densityCodes.AddRange(Enum.GetValues(typeof(DeviceStatus))
                                              .Cast <DeviceStatus>()
                                              .Select(e => new Code {
                            Key = typeof(DeviceStatus).Name, Value = (int)e, Description = e.ToString()
                        }));

                        densityCodes.AddRange(Enum.GetValues(typeof(RtspProtocol))
                                              .Cast <RtspProtocol>()
                                              .Select(e => new Code {
                            Key = typeof(RtspProtocol).Name, Value = (int)e, Description = e.ToString()
                        }));

                        densityCodes.AddRange(Enum.GetValues(typeof(LogEvent))
                                              .Cast <LogEvent>()
                                              .Select(e => new Code {
                            Key = typeof(LogEvent).Name, Value = (int)e, Description = e.ToString()
                        }));

                        densityCodes.Add(new Code
                        {
                            Key         = "LogLevel",
                            Value       = (int)LogLevel.Debug,
                            Description = "调试"
                        });

                        densityCodes.Add(new Code
                        {
                            Key         = "LogLevel",
                            Value       = (int)LogLevel.Information,
                            Description = "消息"
                        });

                        densityCodes.Add(new Code
                        {
                            Key         = "LogLevel",
                            Value       = (int)LogLevel.Warning,
                            Description = "警告"
                        });

                        densityCodes.Add(new Code
                        {
                            Key         = "LogLevel",
                            Value       = (int)LogLevel.Error,
                            Description = "错误"
                        });
                        context.Codes.AddRange(densityCodes);

                        #endregion
                        context.Version.Add(new TrafficVersion
                        {
                            Version = Assembly.GetExecutingAssembly().GetName().Version.ToString()
                        });
                        context.SaveChanges();
                    }
                    else
                    {
                        context.SaveChanges();
                        try
                        {
                            TrafficDensity_One density = context.Densities_One.OrderByDescending(d => d.Id).FirstOrDefault();
                            if (density != null &&
                                TimePointConvert.CurrentTimePoint(BranchDbConvert.DateLevel, density.DateTime) != minTime)
                            {
                                context.ChangeDatabase(BranchDbConvert.GetTableName(density.DateTime));
                            }
                        }
                        catch (MySqlException)
                        {
                        }
                    }
                }
            }
        }