Exemple #1
0
        protected void AddDataToChart(Chart chart, DateTime startDate,
                                      DateTime endDate, MOE.Common.Business.ControllerEventLogs DTTB, string signalid)
        {
            int maxprempt = 0;

            foreach (MOE.Common.Models.Controller_Event_Log row in DTTB.Events)
            {
                if (row.EventCode == 102)
                {
                    chart.Series["Preempt Request"].Points.AddXY(row.Timestamp, row.EventParam);
                    if (row.EventParam > maxprempt)
                    {
                        maxprempt = row.EventParam;
                    }
                }
            }
            if (maxprempt > 10)
            {
                chart.ChartAreas[0].AxisY.Maximum = maxprempt;
            }
            else
            {
                chart.ChartAreas[0].AxisY.Maximum = 10;
            }
        }
Exemple #2
0
        //public MOE.Common.Data.MOE.Controller_Event_LogDataTable RecordsTable = new Data.MOE.Controller_Event_LogDataTable();

        public RecordsExport(String signalId, DateTime startDate, DateTime endDate)
        {
            //MOE.Common.Data.MOETableAdapters.Controller_Event_LogTableAdapter eventlogTA = new Data.MOETableAdapters.Controller_Event_LogTableAdapter();

            RecordsTable = new ControllerEventLogs(signalId, startDate, endDate);
            //eventlogTA.FillbySignalBetweenDates(RecordsTable, signalId, startDate, endDate);
        }
Exemple #3
0
        public PreemptDetailChart(WCFServiceLibrary.PreemptDetailOptions options,
                                  MOE.Common.Business.ControllerEventLogs DTTB)
        {
            Options = options;
            int PreemptNumber = 0;

            if (DTTB.Events.Count > 0)
            {
                var r = (from e in DTTB.Events where e.EventCode != 99 select e).FirstOrDefault();
                PreemptNumber = r.EventParam;
            }
            TimeSpan reportTimespan = Options.EndDate - Options.StartDate;

            AddTitleAndLegend(chart, PreemptNumber);

            AddChartArea(chart, reportTimespan);

            AddSeries(chart);

            AddDataToChart(chart, DTTB, PreemptNumber);
            PlanCollection plans = new PlanCollection(Options.StartDate, Options.EndDate, Options.SignalID);
            // SetSimplePlanStrips(plans, chart, graphStartDate, graphEndDate, DTTB);
        }
Exemple #4
0
        public MOE.Common.Business.ControllerEventLogs CombineDetectorData(DateTime startDate, DateTime endDate, string signalId)
        {
            MOE.Common.Models.SPM db = new MOE.Common.Models.SPM();
            MOE.Common.Business.ControllerEventLogs detectortable =
                new MOE.Common.Business.ControllerEventLogs(signalId, startDate, endDate);
            List <MOE.Common.Business.ControllerEventLogs> Tables = new List <MOE.Common.Business.ControllerEventLogs>();

            foreach (MOE.Common.Business.Detector Detector in DetectorsForRLM)
            {
                MOE.Common.Business.ControllerEventLogs TEMPdetectortable =
                    new MOE.Common.Business.ControllerEventLogs(signalId, startDate, endDate, Detector.Channel,
                                                                new List <int>()
                {
                    82
                });
                Tables.Add(TEMPdetectortable);
            }
            foreach (MOE.Common.Business.ControllerEventLogs Table in Tables)
            {
                detectortable.MergeEvents(Table);
            }
            return(detectortable);
        }
Exemple #5
0
        protected void SetSimplePlanStrips(MOE.Common.Business.PlanCollection planCollection, Chart chart, DateTime graphStartDate, DateTime graphEndDate, MOE.Common.Business.ControllerEventLogs DTTB)
        {
            int backGroundColor = 1;

            foreach (MOE.Common.Business.Plan plan in planCollection.PlanList)
            {
                if (plan.StartTime > graphStartDate && plan.EndTime < graphEndDate)
                {
                    StripLine stripline = new StripLine();
                    //Creates alternating backcolor to distinguish the plans
                    if (backGroundColor % 2 == 0)
                    {
                        stripline.BackColor = Color.FromArgb(120, Color.LightGray);
                    }
                    else
                    {
                        stripline.BackColor = Color.FromArgb(120, Color.LightBlue);
                    }

                    //Set the stripline properties
                    stripline.IntervalOffsetType = DateTimeIntervalType.Hours;
                    stripline.Interval           = 1;
                    stripline.IntervalOffset     = (plan.StartTime - graphStartDate).TotalHours;
                    stripline.StripWidth         = (plan.EndTime - plan.StartTime).TotalHours;
                    stripline.StripWidthType     = DateTimeIntervalType.Hours;

                    chart.ChartAreas["ChartArea1"].AxisX.StripLines.Add(stripline);

                    //Add a corrisponding custom label for each strip
                    CustomLabel Plannumberlabel = new CustomLabel();
                    Plannumberlabel.FromPosition = plan.StartTime.ToOADate();
                    Plannumberlabel.ToPosition   = plan.EndTime.ToOADate();
                    switch (plan.PlanNumber)
                    {
                    case 254:
                        Plannumberlabel.Text = "Free";
                        break;

                    case 255:
                        Plannumberlabel.Text = "Flash";
                        break;

                    case 0:
                        Plannumberlabel.Text = "Unknown";
                        break;

                    default:
                        Plannumberlabel.Text = "Plan " + plan.PlanNumber.ToString();

                        break;
                    }
                    Plannumberlabel.LabelMark = LabelMarkStyle.LineSideMark;
                    Plannumberlabel.ForeColor = Color.Black;
                    Plannumberlabel.RowIndex  = 6;


                    chart.ChartAreas[0].AxisX2.CustomLabels.Add(Plannumberlabel);

                    CustomLabel planPreemptsLabel = new CustomLabel();
                    planPreemptsLabel.FromPosition = plan.StartTime.ToOADate();
                    planPreemptsLabel.ToPosition   = plan.EndTime.ToOADate();

                    var c = from r in DTTB.Events
                            where r.EventCode == 107 && r.Timestamp > plan.StartTime && r.Timestamp < plan.EndTime
                            select r;



                    string preemptCount = c.Count().ToString();
                    planPreemptsLabel.Text      = "Preempts Serviced During Plan: " + preemptCount;
                    planPreemptsLabel.LabelMark = LabelMarkStyle.LineSideMark;
                    planPreemptsLabel.ForeColor = Color.Red;
                    planPreemptsLabel.RowIndex  = 7;

                    chart.ChartAreas[0].AxisX2.CustomLabels.Add(planPreemptsLabel);

                    backGroundColor++;
                }
            }
        }
Exemple #6
0
        protected void AddDataToChart(Chart chart, MOE.Common.Business.ControllerEventLogs DTTB, int preemptNumber)
        {
            PreemptCycleEngine  engine = new PreemptCycleEngine();
            List <PreemptCycle> cycles = engine.CreatePreemptCycle(DTTB);

            int x = 1;

            foreach (PreemptCycle cycle in cycles)
            {
                if (cycle.HasDelay)
                {
                    DataPoint point = new DataPoint();
                    point.SetValueXY(x, cycle.Delay);
                    chart.Series["Delay"].Points.Add(point);
                    chart.Series["Time to Service"].Points.AddXY(x, cycle.TimeToService);
                    point.AxisLabel = cycle.CycleStart.ToShortTimeString();
                }
                else
                {
                    DataPoint point = new DataPoint();
                    point.SetValueXY(x, cycle.TimeToService);
                    chart.Series["Delay"].Points.AddXY(x, 0);
                    chart.Series["Time to Service"].Points.Add(point);
                    point.AxisLabel = cycle.CycleStart.ToShortTimeString();
                }
                chart.Series["Track Clear"].Points.AddXY(x, cycle.TimeToTrackClear);
                chart.Series["Dwell Time"].Points.AddXY(x, cycle.DwellTime);


                if (cycle.TimeToCallMaxOut > 0)
                {
                    chart.Series["Call Max Out"].Points.AddXY(x, cycle.TimeToCallMaxOut);
                }

                if (cycle.TimeToGateDown > 0)
                {
                    chart.Series["Gate Down"].Points.AddXY(x, cycle.TimeToGateDown);
                }



                foreach (DateTime d in cycle.InputOn)
                {
                    if (d >= cycle.CycleStart && d <= cycle.CycleEnd)
                    {
                        chart.Series["Input On"].Points.AddXY(x, (d - cycle.CycleStart).TotalSeconds);
                    }
                }

                foreach (DateTime d in cycle.InputOff)
                {
                    if (d >= cycle.CycleStart && d <= cycle.CycleEnd)
                    {
                        chart.Series["Input Off"].Points.AddXY(x, (d - cycle.CycleStart).TotalSeconds);
                    }
                }

                x++;
            }


            if (x <= 6)
            {
                chart.ChartAreas[0].AxisX.Maximum = 8;
            }
        }
Exemple #7
0
        public List <PreemptCycle> CreatePreemptCycle(MOE.Common.Business.ControllerEventLogs DTTB)
        {
            List <PreemptCycle> CycleCollection = new List <PreemptCycle>();
            PreemptCycle        cycle           = null;


            //foreach (MOE.Common.Models.Controller_Event_Log row in DTTB.Events)
            for (int x = 0; x < DTTB.Events.Count; x++)
            {
                //It can happen that there is no defined terminaiton event.
                if (x + 1 < DTTB.Events.Count)
                {
                    TimeSpan t = (DTTB.Events[x + 1].Timestamp - DTTB.Events[x].Timestamp);
                    if (cycle != null && t.TotalMinutes > 20 && DTTB.Events[x].EventCode != 111 && DTTB.Events[x].EventCode != 105)
                    {
                        EndCycle(cycle, DTTB.Events[x], CycleCollection);
                        cycle = null;
                        continue;
                    }
                }

                switch (DTTB.Events[x].EventCode)
                {
                case (102):

                    if (cycle != null)
                    {
                        cycle.InputOn.Add(DTTB.Events[x].Timestamp);
                    }

                    if (cycle == null && (DTTB.Events[x].Timestamp != DTTB.Events[x + 1].Timestamp) && DTTB.Events[x + 1].EventCode == 105)
                    {
                        cycle = StartCycle(DTTB.Events[x]);
                    }

                    break;

                case (103):

                    if (cycle != null && cycle.GateDown == DateTime.MinValue)
                    {
                        cycle.GateDown = DTTB.Events[x].Timestamp;
                    }


                    break;

                case (104):

                    if (cycle != null)
                    {
                        cycle.InputOff.Add(DTTB.Events[x].Timestamp);
                    }

                    break;

                case (105):


                    ////If we run into an entry start after cycle start (event 102)
                    if (cycle != null && cycle.HasDelay)
                    {
                        cycle.EntryStarted = DTTB.Events[x].Timestamp;
                        break;
                    }

                    if (cycle != null)
                    {
                        EndCycle(cycle, DTTB.Events[x], CycleCollection);
                        cycle = null;
                        cycle = StartCycle(DTTB.Events[x]);
                        break;
                    }

                    if (cycle == null)
                    {
                        cycle = StartCycle(DTTB.Events[x]);
                    }
                    break;

                case (106):
                    if (cycle != null)
                    {
                        cycle.BeginTrackClearance = DTTB.Events[x].Timestamp;

                        if (x + 1 < DTTB.Events.Count)
                        {
                            if (!DoesTrackClearEndNormal(DTTB, x))
                            {
                                cycle.BeginDwellService = FindNext111Event(DTTB, x);
                            }
                        }
                    }
                    break;

                case (107):

                    if (cycle != null)
                    {
                        cycle.BeginDwellService = DTTB.Events[x].Timestamp;

                        if (x + 1 < DTTB.Events.Count)
                        {
                            if (!DoesTheCycleEndNormal(DTTB, x))
                            {
                                cycle.BeginExitInterval = DTTB.Events[x + 1].Timestamp;

                                EndCycle(cycle, DTTB.Events[x + 1], CycleCollection);

                                cycle = null;
                            }
                        }
                    }


                    break;

                case (108):
                    if (cycle != null)
                    {
                        cycle.LinkActive = DTTB.Events[x].Timestamp;
                    }
                    break;

                case (109):
                    if (cycle != null)
                    {
                        cycle.LinkInactive = DTTB.Events[x].Timestamp;
                    }

                    break;

                case (110):
                    if (cycle != null)
                    {
                        cycle.MaxPresenceExceeded = DTTB.Events[x].Timestamp;
                    }
                    break;

                case (111):
                    // 111 can usually be considered "cycle complete"
                    if (cycle != null)
                    {
                        cycle.BeginExitInterval = DTTB.Events[x].Timestamp;

                        EndCycle(cycle, DTTB.Events[x], CycleCollection);



                        cycle = null;
                    }
                    break;
                }



                if (x + 1 >= DTTB.Events.Count && cycle != null)
                {
                    cycle.BeginExitInterval = DTTB.Events[x].Timestamp;
                    EndCycle(cycle, DTTB.Events[x], CycleCollection);
                    break;
                }
            }

            return(CycleCollection);
        }
Exemple #8
0
        public PreemptRequestChart(WCFServiceLibrary.PreemptServiceRequestOptions options,
                                   MOE.Common.Business.ControllerEventLogs DTTB)
        {
            this.Options = options;
            //Set the chart properties
            chart.ImageStorageMode       = ImageStorageMode.UseImageLocation;
            chart.ImageType              = ChartImageType.Jpeg;
            chart.Height                 = 200;
            chart.Width                  = 1100;
            chart.BorderSkin.SkinStyle   = BorderSkinStyle.None;
            chart.BorderSkin.BorderColor = Color.Black;
            chart.BorderSkin.BorderWidth = 1;
            TimeSpan reportTimespan = Options.EndDate - Options.StartDate;

            SetChartTitle();

            //Create the chart legend
            Legend chartLegend = new Legend();

            chartLegend.Name    = "MainLegend";
            chartLegend.Docking = Docking.Left;
            chart.Legends.Add(chartLegend);

            //Create the chart area
            ChartArea chartArea = new ChartArea();

            chartArea.Name = "ChartArea1";
            //if (double.TryParse(yAxisMax, out y))
            //{
            //    chartArea.AxisY.Maximum = y;
            //}
            //else
            //{
            chartArea.AxisY.Maximum = 10;
            //}
            chartArea.AxisY.Minimum           = 0;
            chartArea.AxisY.Title             = "Preempt Number";
            chartArea.AxisY.Interval          = 1;
            chartArea.AxisX.Title             = "Time (Hour of Day)";
            chartArea.AxisX.IntervalType      = DateTimeIntervalType.Hours;
            chartArea.AxisX.LabelStyle.Format = "HH";
            if (reportTimespan.Days < 1)
            {
                if (reportTimespan.Hours > 1)
                {
                    chartArea.AxisX.Interval = 1;
                }
                else
                {
                    chartArea.AxisX.LabelStyle.Format = "HH:mm";
                }
            }

            chart.ChartAreas.Add(chartArea);

            //Add the point series

            Series PreemptSeries = new Series();

            PreemptSeries.ChartType       = SeriesChartType.Point;
            PreemptSeries.BorderDashStyle = ChartDashStyle.Dash;
            PreemptSeries.MarkerStyle     = MarkerStyle.Diamond;
            PreemptSeries.Color           = Color.Black;
            PreemptSeries.Name            = "Preempt Request";
            PreemptSeries.XValueType      = ChartValueType.DateTime;



            //Add the Posts series to ensure the chart is the size of the selected timespan
            Series posts = new Series();

            posts.IsVisibleInLegend = false;
            posts.ChartType         = SeriesChartType.Point;
            posts.Color             = Color.White;
            posts.Name       = "Posts";
            posts.XValueType = ChartValueType.DateTime;

            chart.Series.Add(posts);
            chart.Series.Add(PreemptSeries);

            //Add points at the start and and of the x axis to ensure
            //the graph covers the entire period selected by the user
            //whether there is data or not
            chart.Series["Posts"].Points.AddXY(Options.StartDate, 0);
            chart.Series["Posts"].Points.AddXY(Options.EndDate, 0);

            AddDataToChart(chart, Options.StartDate, Options.EndDate, DTTB, Options.SignalID);
            PlanCollection plans = new PlanCollection(Options.StartDate, Options.EndDate, Options.SignalID);

            SetSimplePlanStrips(plans, chart, Options.StartDate, DTTB);
        }
Exemple #9
0
        public List <Cycle> CreateCycles(String signalid, int phase, DateTime startTime, DateTime endTime,
                                         MOE.Common.Business.ControllerEventLogs eventstable)
        {
            List <Cycle> cycleCollection = new List <Cycle>();

            Cycle cycle = null;
            //use a counter to help determine when we are on the last row
            int counter = 0;

            foreach (MOE.Common.Models.Controller_Event_Log row in eventstable.Events)
            {
                //use a counter to help determine when we are on the last row
                counter++;
                if (row.Timestamp >= startTime && row.Timestamp <= endTime)
                {
                    //If this is the first cycle we need to handle a special case
                    //where the pcd starts at the start of the requested period to
                    //make sure we include all data
                    if (cycleCollection.Count == 0 && cycle == null)
                    {
                        //Make the first cycle start on at the exact start of the requested period
                        cycle = new Cycle(startTime);
                        //Add a green event if the first event is yellow
                        if (GetEventType(row.EventCode) == Cycle.EventType.ChangeToYellow)
                        {
                            cycle.NextEvent(Cycle.EventType.ChangeToGreen, startTime.AddMilliseconds(1));
                        }
                        //Add a green and yellow event if first event is red
                        else if (GetEventType(row.EventCode) == Cycle.EventType.ChangeToRed)
                        {
                            cycle.NextEvent(Cycle.EventType.ChangeToGreen, startTime.AddMilliseconds(1));
                            cycle.NextEvent(Cycle.EventType.ChangeToYellow, startTime.AddMilliseconds(2));
                        }
                    }

                    //Check to see if the event is a change to red
                    //The 64 event is for overlaps.
                    if (row.EventCode == 10 || row.EventCode == 64)
                    {
                        //If it is red and the pcd group is empy create a new one
                        if (cycle == null)
                        {
                            cycle = new Cycle(row.Timestamp);
                        }
                        //If the group is not empty than it is the end of the group and the start
                        //of the next group
                        else
                        {
                            cycle.NextEvent(GetEventType(row.EventCode), row.Timestamp);
                            //if the nextevent response is complete add it and start the next group
                            if (cycle.Status == Cycle.NextEventResponse.GroupComplete)
                            {
                                //pcd.setdetectorcollection(detectortable);
                                cycleCollection.Add(cycle);
                                cycle = new Cycle(row.Timestamp);
                            }
                        }
                    }
                    //If the event is not red and the group is not empty
                    //add the event and set the next event
                    else if (cycle != null)
                    {
                        cycle.NextEvent(GetEventType(row.EventCode), row.Timestamp);
                        if (cycle.Status == Cycle.NextEventResponse.GroupComplete)
                        {
                            cycleCollection.Add(cycle);
                            cycle = new Cycle(row.Timestamp);
                        }
                    }
                    if (cycle != null && cycle.Status == Cycle.NextEventResponse.GroupMissingData)
                    {
                        cycle = null;
                    }

                    //If this is the last PCD Group we need to handle a special case
                    //where the pcd starts at the start of the requested period to
                    //make sure we include all data
                    else if (counter == eventstable.Events.Count && cycle != null)
                    {
                        //if the last event is red create a new group to consume the remaining
                        //time in the period

                        if (GetEventType(row.EventCode) == Cycle.EventType.ChangeToRed)
                        {
                            cycle.NextEvent(Cycle.EventType.ChangeToGreen, endTime.AddMilliseconds(-2));
                            cycle.NextEvent(Cycle.EventType.ChangeToYellow, endTime.AddMilliseconds(-1));
                            cycle.NextEvent(Cycle.EventType.ChangeToRed, endTime);
                        }
                        else if (GetEventType(row.EventCode) == Cycle.EventType.ChangeToGreen)
                        {
                            cycle.NextEvent(Cycle.EventType.ChangeToYellow, endTime.AddMilliseconds(-1));
                            cycle.NextEvent(Cycle.EventType.ChangeToRed, endTime);
                        }
                        else if (GetEventType(row.EventCode) == Cycle.EventType.ChangeToYellow)
                        {
                            cycle.NextEvent(Cycle.EventType.ChangeToRed, endTime);
                        }

                        if (cycle.Status != Cycle.NextEventResponse.GroupMissingData)
                        {
                            cycleCollection.Add(cycle);
                        }
                    }
                }
            }
            //if there are no records at all for the selected time, then the line
            //and counts don't show.  This next bit fixes that.
            if (cycleCollection.Count == 0 && (startTime != endTime))
            {
                //then we need to make a dummy PDC group
                //the pcd assumes it starts on red.
                cycle = new Cycle(startTime);

                //and find out what phase state the controller was in by looking for the next phase event
                //after the end of the plan.



                MOE.Common.Models.Controller_Event_Log eventBeforePattern = MOE.Common.Business.ControllerEventLogs.GetEventBeforeEvent(signalid, phase, startTime);



                if (eventBeforePattern != null)
                {
                    if (GetEventType(eventBeforePattern.EventCode) == Cycle.EventType.ChangeToRed)
                    {
                        //let it dwell in red (we don't have to add anything).



                        //then add a green phase, a yellow phase and a red phase at the end to complete the cycle
                        cycle.NextEvent(Cycle.EventType.ChangeToGreen, endTime.AddMilliseconds(-2));
                        cycle.NextEvent(Cycle.EventType.ChangeToYellow, endTime.AddMilliseconds(-1));
                        cycle.NextEvent(Cycle.EventType.ChangeToRed, endTime);
                    }

                    else if (GetEventType(eventBeforePattern.EventCode) == Cycle.EventType.ChangeToYellow)
                    {
                        //we were in yellow, though this will probably never happen
                        //We have to add a green to our dummy phase.

                        cycle.NextEvent(Cycle.EventType.ChangeToGreen, startTime.AddMilliseconds(1));
                        //then make it dwell in yellow
                        cycle.NextEvent(Cycle.EventType.ChangeToYellow, startTime.AddMilliseconds(2));
                        //then add a red phase at the end to complete the cycle
                        cycle.NextEvent(Cycle.EventType.ChangeToRed, endTime);
                    }

                    else if (GetEventType(eventBeforePattern.EventCode) == Cycle.EventType.ChangeToGreen)
                    {
                        // make it dwell in green
                        cycle.NextEvent(Cycle.EventType.ChangeToGreen, startTime.AddMilliseconds(1));

                        //then add a yellow phase and a red phase at the end to complete the cycle
                        cycle.NextEvent(Cycle.EventType.ChangeToYellow, endTime.AddMilliseconds(-1));
                        cycle.NextEvent(Cycle.EventType.ChangeToRed, endTime);
                    }
                }
                if (cycle.Status == Cycle.NextEventResponse.GroupComplete)
                {
                    cycleCollection.Add(cycle);
                }
            }



            return(cycleCollection);
        }