Ejemplo n.º 1
0
        public static void CreateData(IServiceProvider serviceProvider, List <DensityDevice> devices, DateTime startDate, bool initDatabase = false)
        {
            if (initDatabase)
            {
                ResetDatabase(serviceProvider);
            }

            using (IServiceScope serviceScope = serviceProvider.CreateScope())
            {
                EventBranchBlock branch = new EventBranchBlock(serviceScope.ServiceProvider);
                branch.Open(devices);
                int h = 0;
                foreach (DensityDevice device in devices)
                {
                    foreach (var relation in device.DensityDevice_DensityChannels)
                    {
                        foreach (TrafficRegion region in relation.Channel.Regions)
                        {
                            branch.Post(new TrafficEvent
                            {
                                MatchId  = $"{device.Ip}_{relation.Channel.ChannelIndex}_{region.RegionIndex}",
                                DateTime = startDate.AddHours(h)
                            });
                            ++h;
                        }
                    }
                }

                branch.Close();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 接收数据处理函数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ReceiveHandler(object sender, WebSocketReceivedEventArges e)
        {
            string json = Encoding.UTF8.GetString(e.Packet.ToArray());

            if (_clients.TryGetValue(e.Uri.Authority, out Item item))
            {
                try
                {
                    var v = JsonConvert.DeserializeObject <DensityAdapterData>(json);
                    if (v.type == "car_count")
                    {
                        _densityBranchBlock.Post(new TrafficDensity
                        {
                            MatchId  = $"{e.Uri.Host}_{v.data.channel_id}_{v.data.region_id}",
                            DateTime =
                                DateTime.ParseExact(v.data.record_time, "yyyyMMddHHmmss", CultureInfo.CurrentCulture),
                            Value = v.data.count
                        });
                        item.DensitySuccess += 1;
                    }
                    else if (v.type == "crowd_data")
                    {
                        _eventBranchBlock.Post(new TrafficEvent
                        {
                            MatchId  = $"{e.Uri.Host}_{v.data.channel_id}_{v.data.region_id}",
                            DateTime = DateTime.ParseExact(v.data.record_time, "yyyyMMddHHmmss", CultureInfo.CurrentCulture)
                        });
                        item.EventSuccess += 1;
                    }
                }
                catch (Exception ex)
                {
                    item.Failed += 1;
                    _logger.LogError((int)LogEvent.数据适配, ex, "密度数据解析异常");
                }
            }
            else
            {
                _logger.LogWarning((int)LogEvent.数据适配, $"未知的数据项 {e.Uri.Authority}");
            }
        }