Пример #1
0
        private static bool IsStreetSweeping(ParkingRegulation regulation, ParkingEvent parkingEvent,
                                             GeViolation geViolation, PredixContext context, Customer customer)
        {
            bool isVoilation = false;

            if (parkingEvent.EventType.Equals("PKOUT"))
            {
                using (var innerContext = new PredixContext())
                {
                    var inEvent = innerContext.GeViolations.FirstOrDefault(x =>
                                                                           x.ObjectUid == parkingEvent.Properties.ObjectUid &&
                                                                           x.LocationUid == parkingEvent.LocationUid);
                    if (inEvent?.ParkinTime != null)
                    {
                        inEvent.ParkoutTime      = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                        inEvent.EventOutDateTime =
                            parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                        inEvent.ViolationDuration = (long)parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId)
                                                    .Subtract(inEvent.ParkinTime.Value).TotalMinutes;
                        inEvent.StreetSweeping   = true;
                        inEvent.ModifiedDateTime = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                        inEvent.IsException      = true;
                        inEvent.UserAction       = "Missed_Violation";
                        innerContext.SaveChanges();
                        return(true);
                    }
                }
                return(false);
            }
            if (parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId).TimeOfDay >= regulation.StartTime &&
                parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId).TimeOfDay <= regulation.EndTime)
            {
                Commentary.Print("*** StreetWeeping Violation");

                isVoilation = true;
                geViolation.StreetSweeping = true;
                geViolation.ObjectUid      = parkingEvent.Properties.ObjectUid;
                geViolation.LocationUid    = parkingEvent.LocationUid;
                if (parkingEvent.EventType.Equals("PKIN"))
                {
                    geViolation.EventInDateTime =
                        parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                    geViolation.ParkinTime = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                }

                if (parkingEvent.EventType.Equals("PKOUT"))
                {
                    geViolation.EventOutDateTime =
                        parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                    geViolation.ParkoutTime = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                }

                geViolation.RegulationId  = regulation.RegualationId;
                geViolation.ViolationType = regulation.ViolationType;

                context.GeViolations.Add(geViolation);
            }

            return(isVoilation);
        }
Пример #2
0
        private static void ForceMarkViolation(ParkingEvent parkingEvent, Customer customer)
        {
            Commentary.Print("Force Mark Violation");
            if (parkingEvent.EventType.Equals("PKOUT"))
            {
                using (var innerContext = new PredixContext())
                {
                    var inEvent = innerContext.GeViolations.FirstOrDefault(x =>
                                                                           x.ObjectUid == parkingEvent.Properties.ObjectUid &&
                                                                           x.LocationUid == parkingEvent.LocationUid);
                    if (inEvent?.ParkinTime != null)
                    {
                        inEvent.ParkoutTime      = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                        inEvent.EventOutDateTime =
                            parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                        inEvent.ViolationDuration = (long)parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId)
                                                    .Subtract(inEvent.ParkinTime.Value).TotalMinutes;
                        //inEvent.NoParking = true;
                        inEvent.ModifiedDateTime = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                        inEvent.IsException      = true;
                        inEvent.UserAction       = "Missed_Violation";
                        innerContext.SaveChanges();
                    }
                }

                return;
            }

            GeViolation geViolation = new GeViolation
            {
                NoParking   = true,
                ObjectUid   = parkingEvent.Properties.ObjectUid,
                LocationUid = parkingEvent.LocationUid
            };

            if (parkingEvent.EventType.Equals("PKIN"))
            {
                geViolation.EventInDateTime = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                geViolation.ParkinTime      = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
            }

            if (parkingEvent.EventType.Equals("PKOUT"))
            {
                geViolation.EventOutDateTime = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                geViolation.ParkoutTime      = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
            }

            geViolation.RegulationId  = 81;
            geViolation.ViolationType = ViolationType.FireHydrant;
            using (var context = new PredixContext())
            {
                context.GeViolations.Add(geViolation);
                context.SaveChanges();
            }
        }
Пример #3
0
        public bool ProcessEvent(IImage imageService, Options options, Customer customer, ParkingEvent parkingEvent)
        {
            try
            {
                Commentary.Print($"Location ID :{parkingEvent.LocationUid}");
                parkingEvent.CustomerId = customer.Id;
                if (parkingEvent.Properties == null)
                {
                    parkingEvent.Properties = new ParkingEventProperties
                    {
                        CreatedDate  = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId),
                        ModifiedDate = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId)
                    }
                }
                ;
                parkingEvent.Properties.LocationUid = parkingEvent.LocationUid;


                var isVoilation = false;
                using (var context = new PredixContext())
                {
                    var anyRecord = context.ParkingEvents.Any(x => x.LocationUid == parkingEvent.LocationUid &&
                                                              x.EventType == parkingEvent.EventType &&
                                                              x.Properties.ObjectUid == parkingEvent.Properties.ObjectUid &&
                                                              x.Properties.ImageAssetUid == parkingEvent.Properties.ImageAssetUid);
                    if (anyRecord)
                    {
                        return(false);
                    }

                    var nodeMasterRegulations =
                        context.NodeMasterRegulations.Join(context.ParkingRegulations,
                                                           node => node.RegulationId,
                                                           regulation => regulation.RegualationId,
                                                           (node, regulation) => new { Node = node, Regulation = regulation })
                        .Where(x => x.Regulation.IsActive && x.Node.LocationUid == parkingEvent.LocationUid)
                        .Select(x => x.Regulation).ToList();

                    //var nodeMasterRegulation =
                    //    nodeMasterRegulations.Where(x => x.LocationUid == parkingEvent.LocationUid)
                    //        .ToList();
                    if (nodeMasterRegulations.Any())
                    {
                        var latLongs           = parkingEvent.Properties.GeoCoordinates.Split(',').ToList();
                        var parkingRegulations = new List <ParkingRegulation>();
                        foreach (var regulation in nodeMasterRegulations)
                        {
                            ViolationPercentage(latLongs, regulation, parkingEvent);
                            if (parkingEvent.MatchRate > 0)
                            {
                                parkingRegulations.Add(regulation);
                            }
                            Commentary.Print(
                                $"Regulation Id: {regulation.RegualationId}, Location Uid: {parkingEvent.LocationUid}, Asset Uid: {parkingEvent.AssetUid}, Match Rate {parkingEvent.MatchRate}",
                                true);
                        }

                        foreach (var regulation in parkingRegulations)
                        {
                            Commentary.Print(
                                $"Location Uid: {parkingEvent.LocationUid}, Asset Uid: {parkingEvent.AssetUid},parkingEvent.Timestamp.ToUtcDateTimeOrNull().DayOfWeek:{parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId).DayOfWeek}, ViolationType: {regulation.ViolationType}",
                                true);
                            if (regulation.DayOfWeek.Split('|').Select(x => x.ToUpper())
                                .Contains(parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId).DayOfWeek.ToString()
                                          .Substring(0, 3).ToUpper()))
                            {
                                GeViolation geViolation = new GeViolation();

                                switch (regulation.ViolationType)
                                {
                                case ViolationType.NoParking:
                                    Commentary.Print(
                                        $"Location Uid: {parkingEvent.LocationUid}, Asset Uid: {parkingEvent.AssetUid}, Checking No Parking",
                                        true);
                                    isVoilation = NoParkingCheck(regulation, parkingEvent, geViolation, context,
                                                                 customer);
                                    break;

                                case ViolationType.StreetSweeping:
                                    Commentary.Print(
                                        $"Location Uid: {parkingEvent.LocationUid}, Asset Uid: {parkingEvent.AssetUid}, Checking Street Sweeping",
                                        true);
                                    isVoilation = IsStreetSweeping(regulation, parkingEvent, geViolation, context,
                                                                   customer);
                                    break;

                                case ViolationType.TimeLimitParking:
                                    Commentary.Print(
                                        $"Location Uid: {parkingEvent.LocationUid}, Asset Uid: {parkingEvent.AssetUid}, Checking Time Limit",
                                        true);
                                    isVoilation = IsTimeLimitExceed(regulation, parkingEvent, geViolation, context,
                                                                    customer);
                                    break;

                                case ViolationType.ReservedParking:
                                    //This is out of scope for now, so we ae skipping this logic
                                    break;

                                case ViolationType.FireHydrant:
                                    Commentary.Print(
                                        $"Location Uid: {parkingEvent.LocationUid}, Asset Uid: {parkingEvent.AssetUid}, Fire Hydrant",
                                        true);
                                    isVoilation = IsFireHydrant(parkingEvent, geViolation, regulation, context,
                                                                customer);
                                    break;
                                }

                                Commentary.Print(
                                    $"Location Uid: {parkingEvent.LocationUid}, Asset Uid: {parkingEvent.AssetUid}, Is Violation: {isVoilation}",
                                    true);
                            }

                            if (isVoilation)
                            {
                                break;
                            }
                        }
                    }

                    context.SaveChanges();
                }

                if (!isVoilation)
                {
                    return(true);
                }
                Save(parkingEvent, customer);
                imageService.MediaOnDemand(parkingEvent, parkingEvent.Properties.ImageAssetUid,
                                           parkingEvent.Timestamp, customer);
                return(false);
            }
            catch (Exception e)
            {
                Commentary.Print("******************************************");
                Commentary.Print(e.ToString());
                return(false);
            }
        }