Exemplo n.º 1
0
 public ImportChecker()
 {
     StartTime       = DateTime.Now.AddMinutes(-30);
     EndTime         = DateTime.Now;
     ThereIsAProblem = false;
     try
     {
         CELRepository = MOE.Common.Models.Repositories.ControllerEventLogRepositoryFactory.Create();
         _db           = new SPM();
         var testSignals = _db.Signals.Take(1).FirstOrDefault();
     }
     catch
     {
         ThereIsAProblem = true;
         message.Body    = "The import checker could not find the database.";
     }
     if (_db != null && CELRepository != null && !ThereIsAProblem)
     {
         List <MOE.Common.Models.ControllerType> TypesInUse = FindControllerTypesInUse();
         foreach (var t in TypesInUse)
         {
             CheckControllerEventLogByControllerType(t);
         }
         CheckSpeedRecords();
         CheckSpeedService();
     }
     if (ThereIsAProblem)
     {
         CreateAndSendEmail();
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Constructor used for split monitor
        /// </summary>
        /// <param name="signalId"></param>
        /// <param name="starttime"></param>
        /// <param name="endtime"></param>
        public AnalysisPhaseCollection(string signalId, DateTime starttime, DateTime endtime)
        {
            MOE.Common.Models.Repositories.IControllerEventLogRepository cel = MOE.Common.Models.Repositories.ControllerEventLogRepositoryFactory.Create();



            List <Models.Controller_Event_Log> PTEDT = cel.GetSignalEventsByEventCodes(signalId, starttime, endtime, new List <int>()
            {
                1, 11, 4, 5, 6, 7, 21, 23
            });
            List <Models.Controller_Event_Log> DAPTA = cel.GetSignalEventsByEventCodes(signalId, starttime, endtime, new List <int>()
            {
                1
            });


            var PhasesInUse = (from r in DAPTA
                               where r.EventCode == 1
                               select r.EventParam).Distinct();


            Plans = new PlanCollection(starttime, endtime, signalId);


            foreach (int row in PhasesInUse)
            {
                Business.AnalysisPhase aPhase = new AnalysisPhase(row, signalId, PTEDT);

                Items.Add(aPhase);
            }
            OrderPhases();
        }
Exemplo n.º 3
0
        private void CheckSignalRecordCount(DateTime dateToCheck, Models.Signal signal)
        {
            MOE.Common.Models.Repositories.IControllerEventLogRepository controllerEventLogRepository =
                MOE.Common.Models.Repositories.ControllerEventLogRepositoryFactory.Create();

            if (controllerEventLogRepository.GetRecordCount(signal.SignalID, dateToCheck.AddDays(-1), dateToCheck) > Settings.MinimumRecords)
            {
                Console.WriteLine("Signal " + signal.SignalID + " Has Current records");
                signalsWithRecords.Add(signal);
            }
            else
            {
                Console.WriteLine("Signal " + signal.SignalID + " Does Not Have Current records");
                signalsNoRecords.Add(signal);
                MOE.Common.Models.SPMWatchDogErrorEvent error = new MOE.Common.Models.SPMWatchDogErrorEvent();
                error.SignalID   = signal.SignalID;
                error.DetectorID = "0";
                error.Phase      = 0;
                error.Direction  = "";
                error.TimeStamp  = ScanDate;
                error.Message    = "Missing Records - IP: " + signal.IPAddress;
                error.ErrorCode  = 1;
                MissingRecords.Add(error);
            }
        }
Exemplo n.º 4
0
        private void AddDetectorData()
        {
            MOE.Common.Models.Repositories.IControllerEventLogRepository repository =
                MOE.Common.Models.Repositories.ControllerEventLogRepositoryFactory.Create();
            var detectors = Approach.GetDetectorsForMetricType(11);
            List <Models.Controller_Event_Log> detectorActivations = new List <Models.Controller_Event_Log>();

            foreach (var d in detectors)
            {
                detectorActivations.AddRange(repository.GetEventsByEventCodesParam(Approach.SignalID, this.StartTime, this.EndTime,
                                                                                   new List <int> {
                    82
                }, d.DetChannel));
            }
            this.totalVolume = detectorActivations.Count;
            foreach (RLMCycle cycle in rlmCycleCollection)
            {
                var events = detectorActivations.Where(d => d.Timestamp >= cycle.StartTime && d.Timestamp < cycle.EndTime);
                foreach (var cve in events)
                {
                    RLMDetectorDataPoint ddp = new RLMDetectorDataPoint(cycle.StartTime, cve.Timestamp);
                    cycle.AddDetector(ddp);
                }
            }
        }
Exemplo n.º 5
0
        private void GetSignalPhaseData(DateTime startDate, DateTime endDate, bool showVolume, int binSize, bool usePermissivePhase)
        {
            DateTime redLightTimeStamp = DateTime.MinValue;

            MOE.Common.Models.Repositories.IControllerEventLogRepository controllerRepository =
                MOE.Common.Models.Repositories.ControllerEventLogRepositoryFactory.Create();
            List <Models.Controller_Event_Log> cycleEvents;

            if (!usePermissivePhase)
            {
                PhaseNumber = Approach.ProtectedPhaseNumber;
            }
            else
            {
                PhaseNumber = Approach.PermissivePhaseNumber ?? 0;
            }

            totalVolume = controllerRepository.GetTMCVolume(startDate, endDate, Approach.SignalID, PhaseNumber);
            cycleEvents = controllerRepository.GetEventsByEventCodesParam(Approach.SignalID,
                                                                          startDate, endDate, new List <int>()
            {
                1, 8, 9, 10, 11
            }, PhaseNumber);

            plans = new RLMPlanCollection(cycleEvents, startDate, endDate, this.SRLVSeconds, Approach);
            if (plans.PlanList.Count == 0)
            {
                plans.AddItem(new RLMPlan(startDate, endDate, 0, cycleEvents, this.SRLVSeconds, Approach));
            }
        }
Exemplo n.º 6
0
        public Phase(Models.Approach approach,
                     DateTime startDate, DateTime endDate, List <int> eventCodes, int StartofCycleEvent, bool UsePermissivePhase)


        {
            startDate = startDate.AddMinutes(-1);
            endDate   = endDate.AddMinutes(+1);

            Approach = approach;

            StartDate = startDate;
            _EndDate  = endDate;
            if (!UsePermissivePhase)
            {
                PhaseNumber = Approach.ProtectedPhaseNumber;
            }
            else
            {
                PhaseNumber = Approach.PermissivePhaseNumber ?? 0;
            }
            IsOverlap = false;
            SignalID  = Approach.Signal.SignalID;


            MOE.Common.Models.Repositories.IControllerEventLogRepository cer = MOE.Common.Models.Repositories.ControllerEventLogRepositoryFactory.Create();

            Events = cer.GetEventsByEventCodesParam(SignalID, startDate, endDate,
                                                    eventCodes, PhaseNumber);

            GetCycles(StartofCycleEvent);
        }
Exemplo n.º 7
0
 public List <MOE.Common.Models.Controller_Event_Log> GetDetectorOnEvents(DateTime startTime, DateTime endTime)
 {
     MOE.Common.Models.Repositories.IControllerEventLogRepository repository =
         MOE.Common.Models.Repositories.ControllerEventLogRepositoryFactory.Create();
     return(repository.GetEventsByEventCodesParam(this.Approach.SignalID, startTime,
                                                  endTime, new List <int>()
     {
         82
     }, DetChannel));
 }
Exemplo n.º 8
0
        public RLMPlan(DateTime start, DateTime end, int planNumber,
                       List <MOE.Common.Models.Controller_Event_Log> cycleEvents,
                       double srlvSeconds, Models.Approach approach)
        {
            Approach        = approach;
            startTime       = start;
            endTime         = end;
            this.planNumber = planNumber;
            bool usePermissivePhase = false;

            MOE.Common.Models.SPM db = new MOE.Common.Models.SPM();
            List <int>            l  = new List <int> {
                1, 8, 9, 10, 11
            };
            List <MOE.Common.Models.Controller_Event_Log> permEvents = null;

            if (Approach.PermissivePhaseNumber != null)
            {
                usePermissivePhase = true;
                MOE.Common.Models.Repositories.IControllerEventLogRepository cveRepository =
                    MOE.Common.Models.Repositories.ControllerEventLogRepositoryFactory.Create();
                permEvents = cveRepository.GetEventsByEventCodesParam(Approach.SignalID,
                                                                      start, end, l, Approach.ProtectedPhaseNumber);
                foreach (Models.Controller_Event_Log row in cycleEvents)
                {
                    if (row.Timestamp >= start && row.Timestamp <= end && GetEventType(row.EventCode) == RLMCycle.EventType.BeginYellowClearance)
                    {
                        foreach (MOE.Common.Models.Controller_Event_Log permRow in permEvents)
                        {
                            if (GetEventType(permRow.EventCode) == RLMCycle.EventType.BeginYellowClearance)
                            {
                                if (row.Timestamp == permRow.Timestamp)
                                {
                                    usePermissivePhase = false;
                                }
                            }
                        }
                    }
                }
            }
            this.srlvSeconds = srlvSeconds;
            startTime        = start;
            endTime          = end;
            if (usePermissivePhase)
            {
                GetRedCycle(start, end, permEvents);
            }
            else
            {
                GetRedCycle(start, end, cycleEvents);
            }
        }
Exemplo n.º 9
0
        private int ExistingRecords(string signal, string file, MOE.Common.Models.Repositories.IControllerEventLogRepository celRepository)
        {
            string[] filename = file.Split('_');
            var      start    = new DateTime(Int32.Parse(filename[2]),
                                             Int32.Parse(filename[3]),
                                             Int32.Parse(filename[4]),
                                             Int32.Parse(filename[5].Substring(0, 2)),
                                             0,
                                             0,
                                             0);
            var end = start + new TimeSpan(0, 1, 59, 59, 999);

            return(celRepository.GetRecordCount(signal, start, end));
        }
Exemplo n.º 10
0
 public void SetRedYellowGreenEvents(DateTime startTime, DateTime endTime)
 {
     MOE.Common.Models.Repositories.IControllerEventLogRepository repository =
         MOE.Common.Models.Repositories.ControllerEventLogRepositoryFactory.Create();
     //TODO:ConfigChange
     //if (IsProtectedPhaseOverlap)
     //{
     //    RedYellowGreenEvents = repository.GetEventsByEventCodesParam(Approach.SignalID, startTime,
     //        endTime, new List<int>() { 62, 63, 64 }, ProtectedPhaseNumber);
     //}
     //else
     //{
     //    RedYellowGreenEvents = repository.GetEventsByEventCodesParam(Approach.SignalID, startTime,
     //        endTime, new List<int>() { 1, 8, 10 }, ProtectedPhaseNumber);
     //}
 }
Exemplo n.º 11
0
        private void GetSignalOverlapData(DateTime startDate, DateTime endDate, bool showVolume, int binSize)
        {
            DateTime   redLightTimeStamp = DateTime.MinValue;
            List <int> li = new List <int> {
                62, 63, 64
            };

            MOE.Common.Models.Repositories.IControllerEventLogRepository controllerRepository =
                MOE.Common.Models.Repositories.ControllerEventLogRepositoryFactory.Create();
            var cycleEvents = controllerRepository.GetEventsByEventCodesParam(Approach.SignalID,
                                                                              startDate, endDate, li, Approach.ProtectedPhaseNumber);

            plans = new RLMPlanCollection(cycleEvents, startDate, endDate, this.SRLVSeconds, Approach);
            if (plans.PlanList.Count == 0)
            {
                Plans.AddItem(new RLMPlan(startDate, endDate, 0, cycleEvents, this.SRLVSeconds, Approach));
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Default constructor for the Detector class use in the Turning Movement Count Charts
        /// </summary>
        /// <param name="detid"></param>
        /// <param name="signalid"></param>
        /// <param name="channelid"></param>
        /// <param name="laneid"></param>
        /// <param name="approachdirection"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <param name="binsize"></param>
        public Detector(MOE.Common.Models.Detector detector, DateTime startDate, DateTime endDate, int binsize)
        {
            detID    = detector.DetectorID;
            channel  = detector.DetChannel;
            Approach = detector.Approach;
            signal   = detector.Approach.SignalID;
            LaneType = detector.LaneType;
            MOE.Common.Models.Repositories.IControllerEventLogRepository celRepository =
                MOE.Common.Models.Repositories.ControllerEventLogRepositoryFactory.Create();
            List <Models.Controller_Event_Log> detectorEvents = new List <Models.Controller_Event_Log>();

            detectorEvents.AddRange(celRepository.GetEventsByEventCodesParam(detector.Approach.SignalID, startDate,
                                                                             endDate, new List <int> {
                82
            }, channel));

            volumes = new VolumeCollection(startDate, endDate, detectorEvents, binsize);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Gets the data for the green yellow and red lines as well as the
        /// detector events
        /// </summary>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <param name="signalId"></param>
        /// <param name="eventData1"></param>
        /// <param name="region"></param>
        /// <param name="detChannel"></param>
        private void GetSignalPhaseData(DateTime startDate, DateTime endDate,
                                        bool showVolume, int binSize, int metricTypeID)
        {
            MOE.Common.Models.Repositories.IControllerEventLogRepository celRepository =
                MOE.Common.Models.Repositories.ControllerEventLogRepositoryFactory.Create();
            this.cycleEvents = celRepository.GetEventsByEventCodesParam(approach.SignalID, startDate,
                                                                        endDate, new List <int>()
            {
                1, 8, 10
            }, approach.ProtectedPhaseNumber);
            this.preemptEvents = celRepository.GetSignalEventsByEventCodes(approach.SignalID, startDate,
                                                                           endDate, new List <int>()
            {
                102
            });



            this.detectorEvents = new List <Models.Controller_Event_Log>();
            var detectorsForMetric = approach.GetDetectorsForMetricType(metricTypeID);

            foreach (Models.Detector d in detectorsForMetric)
            {
                this.detectorEvents.AddRange(celRepository.GetEventsByEventCodesParamWithOffset(approach.SignalID, startDate,
                                                                                                endDate, new List <int> {
                    81
                }, d.DetChannel, d.GetOffset()));
            }



            plans = new PlanCollection(cycleEvents, detectorEvents, startDate, endDate, approach, preemptEvents);

            if (plans.PlanList.Count == 0)
            {
                plans.AddItem(new Plan(startDate, endDate, 0, cycleEvents, detectorEvents, preemptEvents, approach));
            }

            if (showVolume)
            {
                SetVolume(detectorEvents, startDate, endDate, binSize);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Gets the data for the green yellow and red lines as well as the
        /// detector events for overlap phases
        /// </summary>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <param name="signalId"></param>
        /// <param name="eventData1"></param>
        /// <param name="region"></param>
        /// <param name="detChannel"></param>
        private void GetSignalOverlapData(DateTime startDate, DateTime endDate,
                                          bool showVolume, int binSize)
        {
            MOE.Common.Models.Repositories.IControllerEventLogRepository celRepository =
                MOE.Common.Models.Repositories.ControllerEventLogRepositoryFactory.Create();
            this.cycleEvents = celRepository.GetEventsByEventCodesParam(approach.SignalID, startDate,
                                                                        endDate, new List <int>()
            {
                61, 63, 64
            }, approach.ProtectedPhaseNumber);
            this.preemptEvents = celRepository.GetSignalEventsByEventCodes(approach.SignalID, startDate,
                                                                           endDate, new List <int>()
            {
                102
            });


            this.detectorEvents = new List <Models.Controller_Event_Log>();
            foreach (Models.Detector d in approach.Detectors)
            {
                this.detectorEvents.AddRange(celRepository.GetEventsByEventCodesParam(approach.SignalID, startDate,
                                                                                      endDate, new List <int> {
                    81
                }, d.DetChannel));
            }
            plans = new PlanCollection(cycleEvents, detectorEvents, startDate, endDate, approach, preemptEvents);

            if (plans.PlanList.Count == 0)
            {
                Plans.AddItem(new Plan(startDate, endDate, 0, cycleEvents, detectorEvents, preemptEvents, approach));
            }

            if (showVolume)
            {
                SetVolume(detectorEvents, startDate, endDate, binSize);
            }
        }
Exemplo n.º 15
0
        //subroutine to write the decoded log to the database.
        //this is where most of the work is done.

        //The only way we match signalid to the collected logs is by the directory name.
        //static void WritetoDB(string dir, string file, MOEDataSetTableAdapters.QueriesTableAdapter MoeTA)
        private void SaveEvents()
        {
            int                      insertErrorCount  = 0;
            int                      insertedLinecount = 0;
            double                   errorRatio        = 0;
            DateTime                 startTime         = new DateTime();
            DateTime                 endTime           = new DateTime();
            TimeSpan                 elapsedTime       = new TimeSpan();
            string                   CWD           = Properties.Settings.Default.LogPath;
            List <string>            dirList       = new List <string>();
            List <string>            fileList      = new List <string>();
            ConcurrentQueue <string> FilesToDelete = new ConcurrentQueue <string>();
            var                      lastrecords   = new Dictionary <string, DateTime>();
            var                      countrecords  = new Dictionary <string, int>();

            MOE.Common.Models.Repositories.IControllerEventLogRepository celRepository =
                MOE.Common.Models.Repositories.ControllerEventLogRepositoryFactory.Create();

            foreach (string s in Directory.GetDirectories(CWD))
            {
                dirList.Add(s);
                var signalID = s.Split(new char[] { '\\' }).Last();
                lastrecords.Add(signalID, celRepository.GetMostRecentRecordTimestamp(signalID));
                foreach (var file in Directory.GetFiles(s))
                {
                    countrecords.Add(file, ExistingRecords(signalID, file, celRepository));
                }
            }
            var options = new ParallelOptions {
                MaxDegreeOfParallelism = Convert.ToInt32(Properties.Settings.Default.MaxThreads)
            };

            Parallel.ForEach(dirList.AsEnumerable(), options, dir =>
                             //foreach (var dir in dirList.AsEnumerable())
            {
                //get the name of the directory and casting it to an int
                //This is the only way the program knows the signal number of the controller.
                string[] strsplit = dir.Split(new char[] { '\\' });
                string dirname    = strsplit.Last();
                string sigid      = dirname;
                var dstOffset     = Math.Abs(DateTimeOffset.Now.Offset.Hours);
                WriteToConsole("Starting signal " + dirname);
                var options1 = new ParallelOptions {
                    MaxDegreeOfParallelism = Convert.ToInt32(Properties.Settings.Default.MaxThreads)
                };
                //Parallel.ForEach(Directory.GetFiles(dir, "*.csv").OrderBy(f => f), options1, file =>
                foreach (var file in Directory.GetFiles(dir, "*.csv").OrderBy(f => f))
                {
                    if (countrecords[file] >= File.ReadAllLines(file).Length - 1)
                    {
                        var delete = Properties.Settings.Default.DeleteFiles;
                        WriteToConsole(String.Format("Skipping {0} {1}, we already imported this.", (delete ? "and deleting" : ""), file));
                        if (delete)
                        {
                            try
                            {
                                File.Delete(file);
                            }
                            catch (Exception e)
                            {
                                WriteToConsole(String.Format("Unable to delete {0}: {1}", file, e.Message));
                            }
                        }
                        continue;
                        //return;
                    }
                    int skippedrecords = 0;
                    DataTable elTable  = new DataTable();
                    elTable.Columns.Add("sigid", System.Type.GetType("System.String"));
                    elTable.Columns.Add("timeStamp", System.Type.GetType("System.DateTime"));
                    elTable.Columns.Add("eventCode", System.Type.GetType("System.Int32"));
                    elTable.Columns.Add("eventParam", System.Type.GetType("System.Int32"));
                    UniqueConstraint custUnique = new UniqueConstraint(new DataColumn[] {
                        elTable.Columns[0],
                        elTable.Columns[1],
                        elTable.Columns[2],
                        elTable.Columns[3]
                    });
                    elTable.Constraints.Add(custUnique);
                    startTime = DateTime.Now;
                    //Siemens decoder makes the first line the IP address, so skip it.
                    foreach (string line in File.ReadAllLines(file).Skip(1))
                    {
                        //Every other line is blank.  We only care about the lines that have data, and
                        //every data line has a comma
                        if (line.Contains(','))
                        {
                            //split the line on commas and assign each split to a var
                            string[] lineSplit = line.Split(new char[] { ',' });
                            DateTime timeStamp = new DateTime();
                            int eventCode      = 0;
                            int eventParam     = 0;
                            //it might happen that the character on the line are not quite right.
                            //the Try/catch stuff is an attempt to deal with that.
                            try
                            {
                                timeStamp = Convert.ToDateTime(lineSplit[0]);
                                //Siemens decoder is converting to local time from UTC, so convert back to local time
                                //Not perfect during DST transitions (at 2:00 AM twice per year)
                                timeStamp = timeStamp + TimeSpan.FromHours(dstOffset);
                                if (timeStamp < lastrecords[sigid])
                                {
                                    skippedrecords++;
                                    continue;
                                }
                                eventCode  = Convert.ToInt32(lineSplit[1]);
                                eventParam = Convert.ToInt32(lineSplit[2]);
                            }
                            catch (Exception ex)
                            {
                                WriteToConsole(String.Format("{0} while converting {1} to event.  Skipping line", ex, lineSplit[0]));
                                continue;
                            }
                            try
                            {
                                elTable.Rows.Add(sigid, timeStamp, eventCode, eventParam);
                            }
                            catch (Exception ex)
                            {
                                WriteToConsole(String.Format("{0} while adding event to data table", ex.ToString()));
                            }
                        }
                    }
                    WriteToConsole(String.Format("{0} has been parsed. Skipped {1} old records", file, skippedrecords));

                    //Do the Math to find out if the error ratio is intolerably high before deleting the file
                    if (insertErrorCount > 0)
                    {
                        errorRatio = Convert.ToDouble(insertErrorCount) / Convert.ToDouble((insertedLinecount + insertErrorCount));
                    }
                    else
                    {
                        errorRatio = 0;
                    }

                    string connectionString = Properties.Settings.Default.SPM.ToString();
                    MOE.Common.Business.BulkCopyOptions bulkOptions = new MOE.Common.Business.BulkCopyOptions(connectionString, Properties.Settings.Default.DestinationTableName,
                                                                                                              Properties.Settings.Default.WriteToConsole, Properties.Settings.Default.forceNonParallel, Properties.Settings.Default.MaxThreads, Properties.Settings.Default.DeleteFile,
                                                                                                              Properties.Settings.Default.EarliestAcceptableDate, Properties.Settings.Default.BulkCopyBatchSize, Properties.Settings.Default.BulkCopyTimeOut);

                    endTime = DateTime.Now;

                    //the Signal class has a static methods to insert the table into the DB.  We are using that.
                    MOE.Common.Business.SignalFtp.BulktoDb(elTable, bulkOptions);
                    elapsedTime = endTime - startTime;

                    if (Properties.Settings.Default.DeleteFiles)
                    {
                        try
                        {
                            File.Delete(file);
                            WriteToConsole(String.Format("{0} Deleted", file));
                        }
                        catch (SystemException sysex)
                        {
                            WriteToConsole(String.Format("{0} while Deleting {1}, waiting 100 ms before trying again", sysex, file));
                            Thread.Sleep(100);
                            try
                            {
                                File.Delete(file);
                            }
                            catch (SystemException sysex2)
                            {
                                WriteToConsole(String.Format("{0} while Deleting {1}, giving up", sysex2, file));
                            }
                        }

                        catch (Exception ex)
                        {
                            WriteToConsole(String.Format("{0} while deleting file {1}", ex, file));
                            FilesToDelete.Enqueue(file);
                        }
                    }
                }
                //);
            }
                             );
        }
Exemplo n.º 16
0
 public int GetVolumeForPeriod(DateTime StartDate, DateTime EndDate)
 {
     MOE.Common.Models.Repositories.IControllerEventLogRepository repository =
         MOE.Common.Models.Repositories.ControllerEventLogRepositoryFactory.Create();
     return(repository.GetDetectorActivationCount(this.Approach.SignalID, StartDate, EndDate, this.DetChannel));
 }
Exemplo n.º 17
0
        public void SetProgrammedSplits(string signalID)
        {
            MOE.Common.Models.Repositories.IControllerEventLogRepository cer = MOE.Common.Models.Repositories.ControllerEventLogRepositoryFactory.Create();
            List <MOE.Common.Models.Controller_Event_Log> SplitsDT           = cer.GetSplitEvents(signalID, startTime, endTime);

            Splits.Clear();

            foreach (MOE.Common.Models.Controller_Event_Log row in SplitsDT)
            {
                if (row.EventCode == 132)
                {
                    this.CycleLength = row.EventParam;
                }

                if (row.EventCode == 133)
                {
                    this.OffsetLength = row.EventParam;
                }

                if (row.EventCode == 134 && !Splits.ContainsKey(1))
                {
                    this.Splits.Add(1, row.EventParam);
                }
                else if (row.EventCode == 134 && row.EventParam > 0)
                {
                    this.Splits[1] = row.EventParam;
                }

                if (row.EventCode == 135 && !Splits.ContainsKey(2))
                {
                    this.Splits.Add(2, row.EventParam);
                }
                else if (row.EventCode == 135 && row.EventParam > 0)
                {
                    this.Splits[2] = row.EventParam;
                }

                if (row.EventCode == 136 && !Splits.ContainsKey(3))
                {
                    this.Splits.Add(3, row.EventParam);
                }
                else if (row.EventCode == 136 && row.EventParam > 0)
                {
                    this.Splits[3] = row.EventParam;
                }

                if (row.EventCode == 137 && !Splits.ContainsKey(4))
                {
                    this.Splits.Add(4, row.EventParam);
                }
                else if (row.EventCode == 137 && row.EventParam > 0)
                {
                    this.Splits[4] = row.EventParam;
                }

                if (row.EventCode == 138 && !Splits.ContainsKey(5))
                {
                    this.Splits.Add(5, row.EventParam);
                }
                else if (row.EventCode == 138 && row.EventParam > 0)
                {
                    this.Splits[5] = row.EventParam;
                }

                if (row.EventCode == 139 && !Splits.ContainsKey(6))
                {
                    this.Splits.Add(6, row.EventParam);
                }
                else if (row.EventCode == 139 && row.EventParam > 0)
                {
                    this.Splits[6] = row.EventParam;
                }

                if (row.EventCode == 140 && !Splits.ContainsKey(7))
                {
                    this.Splits.Add(7, row.EventParam);
                }
                else if (row.EventCode == 140 && row.EventParam > 0)
                {
                    this.Splits[7] = row.EventParam;
                }

                if (row.EventCode == 141 && !Splits.ContainsKey(8))
                {
                    this.Splits.Add(8, row.EventParam);
                }
                else if (row.EventCode == 141 && row.EventParam > 0)
                {
                    this.Splits[8] = row.EventParam;
                }

                if (row.EventCode == 142 && !Splits.ContainsKey(9))
                {
                    this.Splits.Add(9, row.EventParam);
                }
                else if (row.EventCode == 142 && row.EventParam > 0)
                {
                    this.Splits[9] = row.EventParam;
                }

                if (row.EventCode == 143 && !Splits.ContainsKey(10))
                {
                    this.Splits.Add(10, row.EventParam);
                }
                else if (row.EventCode == 143 && row.EventParam > 0)
                {
                    this.Splits[10] = row.EventParam;
                }

                if (row.EventCode == 144 && !Splits.ContainsKey(11))
                {
                    this.Splits.Add(11, row.EventParam);
                }
                else if (row.EventCode == 144 && row.EventParam > 0)
                {
                    this.Splits[11] = row.EventParam;
                }

                if (row.EventCode == 145 && !Splits.ContainsKey(12))
                {
                    this.Splits.Add(12, row.EventParam);
                }
                else if (row.EventCode == 145 && row.EventParam > 0)
                {
                    this.Splits[12] = row.EventParam;
                }

                if (row.EventCode == 146 && !Splits.ContainsKey(13))
                {
                    this.Splits.Add(13, row.EventParam);
                }
                else if (row.EventCode == 146 && row.EventParam > 0)
                {
                    this.Splits[13] = row.EventParam;
                }

                if (row.EventCode == 147 && !Splits.ContainsKey(14))
                {
                    this.Splits.Add(14, row.EventParam);
                }
                else if (row.EventCode == 147 && row.EventParam > 0)
                {
                    this.Splits[14] = row.EventParam;
                }

                if (row.EventCode == 148 && !Splits.ContainsKey(15))
                {
                    this.Splits.Add(15, row.EventParam);
                }
                else if (row.EventCode == 148 && row.EventParam > 0)
                {
                    this.Splits[15] = row.EventParam;
                }

                if (row.EventCode == 149 && !Splits.ContainsKey(16))
                {
                    this.Splits.Add(16, row.EventParam);
                }
                else if (row.EventCode == 149 && row.EventParam > 0)
                {
                    this.Splits[16] = row.EventParam;
                }
            }

            if (Splits.Count == 0)
            {
                for (int i = 0; i < 16; i++)
                {
                    this.Splits.Add(i, 0);
                }
            }
        }
Exemplo n.º 18
0
        protected void AddSpeedDataToChart(Chart chart, Models.Detector detector,
                                           DateTime startDate,
                                           DateTime endDate, int binSize)
        {
            decimal totalDetectorHits     = 0;
            decimal totalOnGreenArrivals  = 0;
            decimal percentArrivalOnGreen = 0;

            Models.SPM db = new SPM();

            List <Models.Speed_Events> SpeedHitsForChart = (from r in db.Speed_Events
                                                            where r.timestamp > startDate &&
                                                            r.timestamp < endDate &&
                                                            r.DetectorID == detector.DetectorID
                                                            select r).ToList();

            MOE.Common.Models.Repositories.IControllerEventLogRepository CLR = Models.Repositories.ControllerEventLogRepositoryFactory.Create();



            List <Models.Controller_Event_Log> phaseevents = CLR.GetEventsByEventCodesParam(detector.Approach.SignalID, StartDate, EndDate, new List <int>()
            {
                0, 1, 7, 8, 9, 10, 11
            }, detector.Approach.ProtectedPhaseNumber);
            List <Models.Controller_Event_Log> detEvents     = new List <Controller_Event_Log>();
            List <Models.Controller_Event_Log> preemptEvents = new List <Controller_Event_Log>();

            PlanCollection Plans = new PlanCollection(phaseevents, detEvents, StartDate,
                                                      EndDate, detector.Approach, preemptEvents);



            foreach (MOE.Common.Business.Plan plan in Plans.PlanList)
            {
                foreach (Cycle c in plan.CycleCollection)
                {
                    c.FindSpeedEventsForCycle(SpeedHitsForChart);
                }
                plan.AvgSpeedBucketCollection = new AvgSpeedBucketCollection(plan.StartTime, plan.EndTime, plan.CycleCollection, binSize, detector.MinSpeedFilter ?? 5, detector.MovementDelay ?? 0);

                if (plan.AvgSpeedBucketCollection.Items.Count > 0)
                {
                    foreach (MOE.Common.Business.AvgSpeedBucket bucket in plan.AvgSpeedBucketCollection.Items)
                    {
                        chart.Series["Average MPH"].Points.AddXY(bucket.StartTime, bucket.AvgSpeed);
                        chart.Series["85th Percentile Speed"].Points.AddXY(bucket.StartTime, bucket.EightyFifth);
                        if (ShowPlanStatistics && ShowPostedSpeed)
                        {
                            chart.Series["Posted Speed"].Points.AddXY(bucket.StartTime, detector.Approach.MPH);
                        }
                    }
                }
            }


            //if arrivals on green is selected add the data to the chart
            if (ShowPlanStatistics)
            {
                if (totalDetectorHits > 0)
                {
                    percentArrivalOnGreen = (totalOnGreenArrivals / totalDetectorHits) * 100;
                }
                else
                {
                    percentArrivalOnGreen = 0;
                }
                SetSpeedPlanStrips(Plans, chart, startDate, detector.MinSpeedFilter ?? 0);
            }
        }
Exemplo n.º 19
0
 public void SetPlanEvents(DateTime startTime, DateTime endTime)
 {
     MOE.Common.Models.Repositories.IControllerEventLogRepository repository =
         MOE.Common.Models.Repositories.ControllerEventLogRepositoryFactory.Create();
     PlanEvents = repository.GetSignalEventsByEventCode(SignalID, startTime, endTime, 131);
 }