Exemplo n.º 1
0
        private void AddDuplicatePlanEvents(DateTime start, DateTime end, string signalId, InMemoryMOEDatabase _db)
        {
            var ex = new Controller_Event_Log();

            ex.EventCode  = 131;
            ex.EventParam = 10;
            ex.SignalID   = signalId;
            ex.Timestamp  = start.AddHours(-3);

            _db.Controller_Event_Log.Add(ex);

            int x = 1;

            for (DateTime time = start; time < end; time = time.AddHours(1))
            {
                var e = new Controller_Event_Log();
                e.SignalID  = signalId;
                e.Timestamp = time.AddMinutes(30);
                e.EventCode = 131;

                if (x % 2 == 0)
                {
                    e.EventParam = x - 1;
                }
                else
                {
                    e.EventParam = x;
                }
                x++;
                _db.Controller_Event_Log.Add(e);
            }
        }
Exemplo n.º 2
0
        public void LastTwoPlansAreTheSameShouldOnlyAddTheEarierEventTest()
        {
            AddDuplicatePlanEvents(DateTime.Now.AddDays(-1), DateTime.Now, "1001", _db);
            var lastplan = (from r in _db.Controller_Event_Log
                            where r.EventCode == 131
                            orderby r.Timestamp
                            select r).Last();

            var NextToLastPlan = new Controller_Event_Log();

            NextToLastPlan.Timestamp  = lastplan.Timestamp.AddMinutes(-30);
            NextToLastPlan.SignalID   = lastplan.SignalID;
            NextToLastPlan.EventCode  = lastplan.EventCode;
            NextToLastPlan.EventParam = lastplan.EventParam;

            _db.Controller_Event_Log.Add(NextToLastPlan);

            var plans = PlanFactory.GetBasicPlans(DateTime.Now.AddDays(-1), DateTime.Now, "1001");

            Assert.IsTrue(plans.Count == 13);

            bool adjDupPlans = false;

            for (int i = 0; i > plans.Count; i++)
            {
                if (plans[i].PlanNumber == plans[i + i].PlanNumber)
                {
                    adjDupPlans = true;
                }
            }

            Assert.IsFalse(adjDupPlans);
        }
Exemplo n.º 3
0
        public static List <Controller_Event_Log> GetPlanEvents(DateTime startDate, DateTime endDate, string signalId)
        {
            var db             = new SPM();
            var celRepository  = ControllerEventLogRepositoryFactory.Create(db);
            var planEvents     = new List <Controller_Event_Log>();
            var firstPlanEvent = celRepository.GetFirstEventBeforeDate(signalId, 131, startDate);

            if (firstPlanEvent != null)
            {
                firstPlanEvent.Timestamp = startDate;
                planEvents.Add(firstPlanEvent);
            }
            else
            {
                firstPlanEvent = new Controller_Event_Log
                {
                    Timestamp  = startDate,
                    EventCode  = 131,
                    EventParam = 0,
                    SignalID   = signalId
                };
                planEvents.Add(firstPlanEvent);
            }
            var tempPlanEvents = celRepository.GetSignalEventsByEventCode(signalId, startDate, endDate, 131)
                                 .OrderBy(e => e.Timestamp).ToList();

            tempPlanEvents.Add(new Controller_Event_Log {
                SignalID = signalId, EventCode = 131, EventParam = 254, Timestamp = endDate
            });

            for (var x = 0; x < tempPlanEvents.Count(); x++)
            {
                if (x + 2 < tempPlanEvents.Count())
                {
                    if (tempPlanEvents[x].EventParam == tempPlanEvents[x + 1].EventParam)
                    {
                        planEvents.Add(tempPlanEvents[x]);
                        x++;
                    }
                    else
                    {
                        planEvents.Add(tempPlanEvents[x]);
                    }
                }
                else
                {
                    if (tempPlanEvents.Count >= 2 && tempPlanEvents.Last().EventCode ==
                        tempPlanEvents[tempPlanEvents.Count() - 2].EventCode)
                    {
                        planEvents.Add(tempPlanEvents[tempPlanEvents.Count() - 2]);
                    }
                    else
                    {
                        planEvents.Add(tempPlanEvents.Last());
                    }
                }
            }

            return(planEvents);
        }
        private void GetAdvanceCountEvents()
        {
            AdvanceCountEvents = new Dictionary <string, List <Controller_Event_Log> >();
            var controllerEventLogRepository = Models.Repositories.ControllerEventLogRepositoryFactory.Create();
            var localSortedDetectors         = Approach.Detectors.OrderByDescending(d => d.MovementType.DisplayOrder)
                                               .ThenByDescending(l => l.LaneNumber).ToList();

            foreach (var detector in localSortedDetectors)
            {
                if (detector.DetectionTypes.Any(d => d.DetectionTypeID == 2))
                {
                    var advanceEvents = controllerEventLogRepository.GetEventsByEventCodesParam(Approach.SignalID,
                                                                                                Options.StartDate, Options.EndDate, new List <int> {
                        81, 82
                    }, detector.DetChannel);
                    var laneNumber = "";
                    if (detector.LaneNumber != null)
                    {
                        laneNumber = detector.LaneNumber.Value.ToString();
                    }
                    if (advanceEvents.Count > 0)
                    {
                        AdvanceCountEvents.Add("Advanced Count (" + detector.DistanceFromStopBar + " ft) " +
                                               detector.MovementType.Abbreviation + " " +
                                               laneNumber +
                                               ", ch " + detector.DetChannel, advanceEvents);
                    }
                    else if (AdvanceCountEvents.Count == 0 && Options.ShowAllLanesInfo)
                    {
                        var forceEventsForAllLanes = new List <Controller_Event_Log>();
                        var tempEvent1             = new Controller_Event_Log()
                        {
                            SignalID   = Options.SignalID,
                            EventCode  = 82,
                            EventParam = detector.DetChannel,
                            Timestamp  = Options.StartDate.AddSeconds(-10)
                        };
                        forceEventsForAllLanes.Add(tempEvent1);
                        var tempEvent2 = new Controller_Event_Log()
                        {
                            SignalID   = Options.SignalID,
                            EventCode  = 81,
                            EventParam = detector.DetChannel,
                            Timestamp  = Options.StartDate.AddSeconds(-9)
                        };
                        forceEventsForAllLanes.Add(tempEvent2);
                        AdvanceCountEvents.Add("Advanced Count (" + detector.DistanceFromStopBar + " ft), ch " +
                                               detector.DetChannel + " " + detector.MovementType.Abbreviation + " " +
                                               laneNumber, forceEventsForAllLanes);
                    }
                }
            }
        }
Exemplo n.º 5
0
        public void GetPlanCollection(DateTime startDate, DateTime endDate,
                                      List <Controller_Event_Log> cycleEvents, SPM db)
        {
            var ds =
                new ControllerEventLogs(Approach.SignalID, startDate, endDate, new List <int> {
                131
            }, db);
            var row = new Controller_Event_Log();

            row.Timestamp = startDate;
            row.SignalID  = Approach.SignalID;
            row.EventCode = 131;
            try
            {
                row.EventParam = ControllerEventLogs.GetPreviousPlan(Approach.SignalID, startDate);

                ds.Events.Insert(0, row);
            }
            catch
            {
                row.EventParam = 0;
                ds.Events.Insert(0, row);
            }
            // remove duplicate plan entries
            ds.MergeEvents(ds);
            for (var i = 0; i < ds.Events.Count(); i++)
            {
                //if this is the last plan then we want the end of the plan
                //to cooincide with the end of the graph
                if (ds.Events.Count() - 1 == i)
                {
                    if (ds.Events[i].Timestamp != endDate)
                    {
                        var plan = new RLMPlan(ds.Events[i].Timestamp, endDate, ds.Events[i].EventParam,
                                               cycleEvents, SRLVSeconds, Approach);
                        AddItem(plan);
                    }
                }
                //else we add the plan with the next plans' time stamp as the end of the plan
                else
                {
                    if (ds.Events[i].Timestamp != ds.Events[i + 1].Timestamp)
                    {
                        var plan = new RLMPlan(ds.Events[i].Timestamp,
                                               ds.Events[i + 1].Timestamp, ds.Events[i].EventParam, cycleEvents, SRLVSeconds, Approach);
                        AddItem(plan);
                    }
                }
            }
        }
Exemplo n.º 6
0
        public static bool LineByLineWriteToDb(DataTable elTable)
        {
            //MOE.Common.Data.MOETableAdapters.QueriesTableAdapter moeTA = new MOE.Common.Data.MOETableAdapters.QueriesTableAdapter();
            using (var db = new SPM())
            {
                foreach (DataRow row in elTable.Rows)
                {
                    //Parallel.ForEach(elTable.AsEnumerable(), row =>
                    try
                    {
                        var r = new Controller_Event_Log();
                        r.SignalID   = row[0].ToString();
                        r.Timestamp  = Convert.ToDateTime(row[1]);
                        r.EventCode  = Convert.ToInt32(row[2]);
                        r.EventParam = Convert.ToInt32(row[3]);


                        if (Settings.Default.WriteToConsole)
                        {
                            Console.WriteLine("---Inserting line for ControllerType {0} at {1}---", row[0], row[1]);
                        }

                        db.Controller_Event_Log.Add(r);
                        db.SaveChangesAsync();
                    }
                    catch (SqlException sqlex)
                    {
                        if (sqlex.Number == 2627)
                        {
                            if (Settings.Default.WriteToConsole)
                            {
                                Console.WriteLine("Duplicate line for signal {0} at {1}", row[0], row[1]);
                            }
                            //duplicateLineCount++;
                        }

                        else
                        {
                            //insertErrorCount++;
                            if (Settings.Default.WriteToConsole)
                            {
                                Console.WriteLine(
                                    "Exeption {0} \n While Inserting a line for controller {1} on timestamp {2}", sqlex,
                                    row[0], row[1]);
                            }
                        }
                    }
                }
Exemplo n.º 7
0
        private void GetPhaseCustomEvents()
        {
            var startDate = Options.StartDate;
            var endDate   = Options.EndDate;

            PhaseCustomEvents = new Dictionary <string, List <Controller_Event_Log> >();
            var controllerEventLogRepository = Models.Repositories.ControllerEventLogRepositoryFactory.Create();

            if (Options.PhaseEventCodesList != null && Options.PhaseEventCodesList.Any() &&
                Options.PhaseEventCodesList.Count > 0)
            {
                foreach (var phaseEventCode in Options.PhaseEventCodesList)
                {
                    var phaseEvents = controllerEventLogRepository.GetEventsByEventCodesParam(Approach.SignalID,
                                                                                              startDate, endDate, new List <int> {
                        phaseEventCode
                    }, PhaseNumber);
                    if (phaseEvents.Count > 0)
                    {
                        PhaseCustomEvents.Add(
                            "Phase Events: " + phaseEventCode, phaseEvents);
                    }

                    if (PhaseCustomEvents.Count == 0 && Options.ShowAllLanesInfo)
                    {
                        var forceEventsForAllLanes = new List <Controller_Event_Log>();
                        var tempEvent1             = new Controller_Event_Log()
                        {
                            SignalID   = Options.SignalID,
                            EventCode  = phaseEventCode,
                            EventParam = PhaseNumber,
                            Timestamp  = Options.StartDate.AddSeconds(-10)
                        };
                        forceEventsForAllLanes.Add(tempEvent1);
                        var tempEvent2 = new Controller_Event_Log()
                        {
                            SignalID   = Options.SignalID,
                            EventCode  = phaseEventCode,
                            EventParam = PhaseNumber,
                            Timestamp  = Options.StartDate.AddSeconds(-9)
                        };
                        forceEventsForAllLanes.Add(tempEvent2);
                        PhaseCustomEvents.Add(
                            "Phase Events: " + phaseEventCode, forceEventsForAllLanes);
                    }
                }
            }
        }
Exemplo n.º 8
0
        private void AddEasyPlanEvents(DateTime start, DateTime end, string signalId, InMemoryMOEDatabase _db)
        {
            int x = 0;

            for (DateTime time = start; time < end; time = time.AddHours(2))
            {
                var e = new Controller_Event_Log();

                e.EventCode  = 131;
                e.EventParam = x;
                e.SignalID   = signalId;
                e.Timestamp  = time;

                x++;
                _db.Controller_Event_Log.Add(e);
            }
        }
Exemplo n.º 9
0
        public static void LoadControllerEventLogsFromMOEDB(InMemoryMOEDatabase db)
        {
            System.Data.SqlClient.SqlConnectionStringBuilder builder =
                new System.Data.SqlClient.SqlConnectionStringBuilder();
            builder["Data Source"]           = "spmserver";
            builder["Password"]              = "******";
            builder["Persist Security Info"] = true;
            builder["User ID"]         = "datareader";
            builder["Initial Catalog"] = "MOE";
            Console.WriteLine(builder.ConnectionString);

            SqlConnection sqlConnection1 = new SqlConnection(builder.ConnectionString);
            SqlCommand    cmd            = new SqlCommand();
            SqlDataReader reader;

            cmd.CommandText = "select * from Controller_Event_Log"
                              + " Where Timestamp between '02/01/2018 00:00' and '02/01/2018 23:59'"
                              + " and SignalID = '7185'";

            cmd.CommandType = CommandType.Text;
            cmd.Connection  = sqlConnection1;

            sqlConnection1.Open();

            reader = cmd.ExecuteReader();



            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    Controller_Event_Log cel = new Controller_Event_Log();
                    cel.SignalID   = reader.GetString(0);
                    cel.Timestamp  = reader.GetDateTime(1);
                    cel.EventCode  = reader.GetInt32(2);
                    cel.EventParam = reader.GetInt32(3);

                    db.Controller_Event_Log.Add(cel);
                }
            }
            reader.Close();
            sqlConnection1.Close();
        }
Exemplo n.º 10
0
        public PlansBase(string signalID, DateTime startDate, DateTime endDate) :
            base(signalID, startDate, endDate, new List <int> {
            131
        })
        {
            //Get the plan Previous to the start date
            //if(this.Events.Count > 0)
            //{
            var tempEvent = new Controller_Event_Log();

            tempEvent.SignalID   = signalID;
            tempEvent.Timestamp  = startDate;
            tempEvent.EventCode  = 131;
            tempEvent.EventParam = GetPreviousPlan(signalID, startDate);

            Events.Insert(0, tempEvent);
            //}

            //Remove Duplicate Plans
            var x    = -1;
            var temp = new List <Controller_Event_Log>();

            foreach (var cel in Events)
            {
                temp.Add(cel);
            }
            foreach (var cel in temp)
            {
                if (x == -1)
                {
                    x = cel.EventParam;
                }
                else if (x != cel.EventParam)
                {
                    x = cel.EventParam;
                }
                else if (x == cel.EventParam)
                {
                    x = cel.EventParam;
                    Events.Remove(cel);
                }
            }
        }
Exemplo n.º 11
0
        private PreemptCycle StartCycle(Controller_Event_Log controller_Event_Log)
        {
            var cycle = new PreemptCycle();


            cycle.CycleStart = controller_Event_Log.Timestamp;

            if (controller_Event_Log.EventCode == 105)
            {
                cycle.EntryStarted = controller_Event_Log.Timestamp;
                cycle.HasDelay     = false;
            }

            if (controller_Event_Log.EventCode == 102)
            {
                cycle.StartInputOn = controller_Event_Log.Timestamp;
                cycle.HasDelay     = true;
            }

            return(cycle);
        }
Exemplo n.º 12
0
 private void EndCycle(PreemptCycle cycle, Controller_Event_Log controller_Event_Log,
                       List <PreemptCycle> CycleCollection)
 {
     cycle.CycleEnd = controller_Event_Log.Timestamp;
     CycleCollection.Add(cycle);
 }
Exemplo n.º 13
0
        private void GetAdvancePresenceEvents()
        {
            var extendBothStartStopSearch = Options.ExtendStartStopSearch * 60.0;

            AdvancePresenceEvents = new Dictionary <string, List <Controller_Event_Log> >();
            var controllerEventLogRepository = ControllerEventLogRepositoryFactory.Create();
            var localSortedDetectors         = Approach.Detectors.OrderByDescending(d => d.MovementType.DisplayOrder)
                                               .ThenByDescending(l => l.LaneNumber).ToList();

            //Parallel.ForEach(localSortedDetectors, detector =>
            foreach (var detector in localSortedDetectors)
            {
                if (detector.DetectionTypes.Any(d => d.DetectionTypeID == 7))
                {
                    var advancePresence = controllerEventLogRepository.GetEventsByEventCodesParam(Approach.SignalID,
                                                                                                  Options.StartDate.AddSeconds(-extendBothStartStopSearch),
                                                                                                  Options.EndDate.AddSeconds(extendBothStartStopSearch),
                                                                                                  new List <int> {
                        81, 82
                    }, detector.DetChannel);
                    var laneNumber = "";
                    if (detector.LaneNumber != null)
                    {
                        laneNumber = detector.LaneNumber.Value.ToString();
                    }

                    if (advancePresence.Count > 0)
                    {
                        //var minTimeStamp = advancePresence[0].Timestamp.ToString(" hh:mm:ss ");
                        //var maxTimeStamp = advancePresence[advancePresence.Count - 1].Timestamp.ToString(" hh:mm:ss ");
                        var keyLabel = "Advanced Presence, " +
                                       detector.MovementType.Abbreviation + " " + laneNumber + ", ch " +
                                       detector.DetChannel;
                        //+ minTimeStamp + " -> " + maxTimeStamp;
                        AdvancePresenceEvents.Add(keyLabel, advancePresence);
                        //AdvancePresenceEvents.Add("Advanced Presence, " + detector.MovementType.Abbreviation + " " +
                        //                          laneNumber + ", ch " + detector.DetChannel, advancePresence);
                    }
                    else if (AdvancePresenceEvents.Count == 0 && Options.ShowAllLanesInfo)
                    {
                        var forceEventsForAllLanes = new List <Controller_Event_Log>();
                        var tempEvent1             = new Controller_Event_Log()
                        {
                            SignalID   = Options.SignalID,
                            EventCode  = 82,
                            EventParam = detector.DetChannel,
                            Timestamp  = Options.StartDate.AddSeconds(-10)
                        };
                        forceEventsForAllLanes.Add(tempEvent1);
                        var tempEvent2 = new Controller_Event_Log()
                        {
                            SignalID   = Options.SignalID,
                            EventCode  = 81,
                            EventParam = detector.DetChannel,
                            Timestamp  = Options.StartDate.AddSeconds(-9)
                        };
                        forceEventsForAllLanes.Add(tempEvent2);
                        AdvancePresenceEvents.Add("Advanced Presence, ch " + detector.DetChannel + " " +
                                                  detector.MovementType.Abbreviation + " " +
                                                  laneNumber, forceEventsForAllLanes);
                    }
                }
            }
            //});
        }