예제 #1
0
 public async Task RefreshLogs()
 {
     await Task.Run(delegate
     {
         Directory.CreateDirectory(LogsPath);
         string[] files = Directory.GetFiles(LogsPath);
         var logs       = new List <ViolationLog>();
         foreach (var file in files)
         {
             var log = ViolationLog.FromFile(session, file);
             if (log != null)
             {
                 logs.Add(log);
             }
         }
         ViolationLogs = logs.OrderByDescending(i => i.DateTime);
         OnRefreshLogs?.Invoke();
     });
 }
예제 #2
0
        public void CheckViolation()
        {
            var redis  = _redisClientsManager.GetClient();
            var assets = redis.GetAllKeys();

            foreach (var item in assets)
            {
                bool         isEnd        = false;
                bool         isStart      = false;
                var          currentAsset = redis.Get <AssetRedis>(item);
                ViolationLog log          = new ViolationLog()
                {
                    AssetId       = currentAsset.Id,
                    Description   = "Test",
                    Severity      = 1,
                    TypeViolation = 1
                };
                Geometry locationGeometry = null;
                if (currentAsset.Location.Contains(","))
                {
                    locationGeometry = GeoJsonHelper.ParseStringToLineString(currentAsset.Location);
                }
                else
                {
                    locationGeometry = GeoJsonHelper.ParseStringToLineString(currentAsset.Location);
                }

                var tradeZones = _unitOfWork.Repository <TradeZoneVersion>().GetAll().Where(x => x.BrandId == currentAsset.BrandId && x.IsActive == true).Select(x => x.TradeZones).SingleOrDefault();

                var tradezone = tradeZones.Where(x => x.StoreTradeZones.Any(x => x.StoreId == currentAsset.StoreId)).FirstOrDefault();
                if (!(tradezone is null))
                {
                    log.Geom = locationGeometry.Difference(tradezone.Geom);
                    string[] points = currentAsset.Location.Split(", ");
                    for (int i = 0; i < points.Length; i++)
                    {
                        var point = GeoJsonHelper.ParseStringToPoint(points.ElementAt(i));
                        if (!tradezone.Geom.Intersects(point))
                        {
                            if (!isStart)
                            {
                                log.StartTime = currentAsset.StartTime.AddSeconds(3 * i);
                                isStart       = true;
                            }
                            else
                            {
                                isEnd       = true;
                                log.EndTime = currentAsset.StartTime.AddSeconds(3 * i);
                            }
                        }
                    }
                    if (isStart)
                    {
                        if (!isEnd)
                        {
                            log.EndTime = log.StartTime;
                        }
                        _unitOfWork.Repository <ViolationLog>().Insert(log);
                        _unitOfWork.Commit();
                    }
                }
            }
        }
예제 #3
0
 public async void SetViolationLog(Mat frame, int violationsCount, int violatorsCount)
 {
     ViolationLog.Create(session, DateTime.Now, violationsCount, violatorsCount, frame);
     await RefreshLogs();
 }