public MOE.Common.Business.TMC.TMCInfo CreateMetric() { base.LogMetricRun(); MOE.Common.Models.Repositories.ISignalsRepository repository = MOE.Common.Models.Repositories.SignalsRepositoryFactory.Create(); Common.Models.Signal signal = repository.GetSignalBySignalID(SignalID); TmcInfo = new MOE.Common.Business.TMC.TMCInfo(); MOE.Common.Business.PlanCollection plans = new MOE.Common.Business.PlanCollection(StartDate, EndDate, SignalID); MOE.Common.Models.Repositories.ILaneTypeRepository ltr = MOE.Common.Models.Repositories.LaneTypeRepositoryFactory.Create(); List <Common.Models.LaneType> laneTypes = ltr.GetAllLaneTypes(); MOE.Common.Models.Repositories.IMovementTypeRepository mtr = MOE.Common.Models.Repositories.MovementTypeRepositoryFactory.Create(); List <Common.Models.MovementType> movementTypes = mtr.GetAllMovementTypes(); MOE.Common.Models.Repositories.IDirectionTypeRepository dtr = MOE.Common.Models.Repositories.DirectionTypeRepositoryFactory.Create(); List <Common.Models.DirectionType> directions = dtr.GetAllDirections(); CreateLaneTypeCharts(signal, "Vehicle", laneTypes, movementTypes, directions, plans, TmcInfo); CreateLaneTypeCharts(signal, "Exit", laneTypes, movementTypes, directions, plans, TmcInfo); CreateLaneTypeCharts(signal, "Bike", laneTypes, movementTypes, directions, plans, TmcInfo); return(TmcInfo); }
private void SetSimplePlanStrips(MOE.Common.Business.PlanCollection planCollection, Chart chart, DateTime graphStartDate) { int backGroundColor = 1; foreach (MOE.Common.Business.Plan plan in planCollection.PlanList) { 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["ChartArea1"].AxisX2.CustomLabels.Add(Plannumberlabel); backGroundColor++; } }
private void AddSplitMonitorDataToChart(Chart chart, DateTime startDate, DateTime endDate, MOE.Common.Business.AnalysisPhase phase, string signalId, MOE.Common.Business.PlanCollection plans) { //Table if (phase.Cycles.Items.Count > 0) { plans.FillMissingSplits(); int MaxSplitLength = 0; foreach (MOE.Common.Business.Plan plan in plans.PlanList) { try { chart.Series["Programed Split"].Points.AddXY(plan.StartTime, plan.Splits[phase.PhaseNumber]); chart.Series["Programed Split"].Points.AddXY(plan.EndTime, plan.Splits[phase.PhaseNumber]); if (plan.Splits[phase.PhaseNumber] > MaxSplitLength) { MaxSplitLength = plan.Splits[phase.PhaseNumber]; } } catch { //System.Windows.MessageBox.Show(ex.ToString()); } } foreach (MOE.Common.Business.AnalysisPhaseCycle Cycle in phase.Cycles.Items) { if (Cycle.TerminationEvent == 4) { chart.Series["GapOut"].Points.AddXY(Cycle.StartTime, Cycle.Duration.TotalSeconds); } if (Cycle.TerminationEvent == 5) { chart.Series["MaxOut"].Points.AddXY(Cycle.StartTime, Cycle.Duration.TotalSeconds); } if (Cycle.TerminationEvent == 6) { chart.Series["ForceOff"].Points.AddXY(Cycle.StartTime, Cycle.Duration.TotalSeconds); } if (Cycle.TerminationEvent == 0) { chart.Series["Unknown"].Points.AddXY(Cycle.StartTime, Cycle.Duration.TotalSeconds); } if (Cycle.HasPed && ShowPedActivity) { if (Cycle.PedDuration == 0) { if (Cycle.PedStartTime == DateTime.MinValue) { Cycle.SetPedStart(Cycle.StartTime); } if (Cycle.PedEndTime == DateTime.MinValue) { Cycle.SetPedEnd(Cycle.YellowEvent ); } } chart.Series["PedActivity"].Points.AddXY(Cycle.PedStartTime, Cycle.PedDuration); } } if (MaxSplitLength > 0) { if (MaxSplitLength >= 50) { chart.ChartAreas[0].AxisY.Maximum = (1.5 * MaxSplitLength); } else { chart.ChartAreas[0].AxisY.Maximum = (2.5 * MaxSplitLength); } } if (YAxisMax != null) { chart.ChartAreas[0].AxisY.Maximum = YAxisMax.Value; } } }
private void SetSplitMonitorStatistics(MOE.Common.Business.PlanCollection plans, MOE.Common.Business.AnalysisPhase phase, Chart chart) { //find the phase Cycles that occure during the plan. foreach (MOE.Common.Business.Plan plan in plans.PlanList) { var Cycles = from cycle in phase.Cycles.Items where cycle.StartTime > plan.StartTime && cycle.EndTime < plan.EndTime orderby cycle.Duration select cycle; // find % Skips if (ShowPercentSkip) { if (plan.CycleCount > 0) { double CycleCount = plan.CycleCount; double SkippedPhases = (plan.CycleCount - Cycles.Count()); double SkipPercent = 0; if (CycleCount > 0) { SkipPercent = SkippedPhases / CycleCount; } CustomLabel skipLabel = new CustomLabel(); skipLabel.FromPosition = plan.StartTime.ToOADate(); skipLabel.ToPosition = plan.EndTime.ToOADate(); skipLabel.Text = string.Format("{0:0.0%} Skips", SkipPercent); skipLabel.LabelMark = LabelMarkStyle.LineSideMark; skipLabel.ForeColor = Color.Black; skipLabel.RowIndex = 1; chart.ChartAreas[0].AxisX2.CustomLabels.Add(skipLabel); } } // find % GapOuts if (ShowPercentGapOuts) { var GapOuts = from cycle in Cycles where cycle.TerminationEvent == 4 select cycle; double CycleCount = plan.CycleCount; double gapouts = GapOuts.Count(); double GapPercent = 0; if (CycleCount > 0) { GapPercent = gapouts / CycleCount; } CustomLabel gapLabel = new CustomLabel(); gapLabel.FromPosition = plan.StartTime.ToOADate(); gapLabel.ToPosition = plan.EndTime.ToOADate(); gapLabel.Text = string.Format("{0:0.0%} GapOuts", GapPercent); gapLabel.LabelMark = LabelMarkStyle.LineSideMark; gapLabel.ForeColor = Color.OliveDrab; gapLabel.RowIndex = 2; chart.ChartAreas[0].AxisX2.CustomLabels.Add(gapLabel); } //Set Max Out if (ShowPercentMaxOutForceOff && plan.PlanNumber == 254) { var MaxOuts = from cycle in Cycles where cycle.TerminationEvent == 5 select cycle; double CycleCount = plan.CycleCount; double maxouts = MaxOuts.Count(); double MaxPercent = 0; if (CycleCount > 0) { MaxPercent = maxouts / CycleCount; } CustomLabel maxLabel = new CustomLabel(); maxLabel.FromPosition = plan.StartTime.ToOADate(); maxLabel.ToPosition = plan.EndTime.ToOADate(); maxLabel.Text = string.Format("{0:0.0%} MaxOuts", MaxPercent); maxLabel.LabelMark = LabelMarkStyle.LineSideMark; maxLabel.ForeColor = Color.Red; maxLabel.RowIndex = 3; chart.ChartAreas[0].AxisX2.CustomLabels.Add(maxLabel); } // Set Force Off if (ShowPercentMaxOutForceOff && plan.PlanNumber != 254 ) { var ForceOffs = from cycle in Cycles where cycle.TerminationEvent == 6 select cycle; double CycleCount = plan.CycleCount; double forceoffs = ForceOffs.Count(); double ForcePercent = 0; if (CycleCount > 0) { ForcePercent = forceoffs / CycleCount; } CustomLabel forceLabel = new CustomLabel(); forceLabel.FromPosition = plan.StartTime.ToOADate(); forceLabel.ToPosition = plan.EndTime.ToOADate(); forceLabel.Text = string.Format("{0:0.0%} ForceOffs", ForcePercent); forceLabel.LabelMark = LabelMarkStyle.LineSideMark; forceLabel.ForeColor = Color.MediumBlue; forceLabel.RowIndex = 3; chart.ChartAreas[0].AxisX2.CustomLabels.Add(forceLabel); } //Average Split if (ShowAverageSplit) { double runningTotal = 0; double averageSplits = 0; foreach (MOE.Common.Business.AnalysisPhaseCycle Cycle in Cycles) { runningTotal = runningTotal + Cycle.Duration.TotalSeconds; } if (Cycles.Count() > 0) { averageSplits = runningTotal / Cycles.Count(); } CustomLabel avgLabel = new CustomLabel(); avgLabel.FromPosition = plan.StartTime.ToOADate(); avgLabel.ToPosition = plan.EndTime.ToOADate(); avgLabel.Text = string.Format("{0: 0.0} Avg. Split", averageSplits); avgLabel.LabelMark = LabelMarkStyle.LineSideMark; avgLabel.ForeColor = Color.Black; avgLabel.RowIndex = 4; chart.ChartAreas[0].AxisX2.CustomLabels.Add(avgLabel); //Percentile Split if (SelectedPercentileSplit != null && (Cycles.Count() > 2)) { Double percentileResult = 0; Double Percentile = (Convert.ToDouble(SelectedPercentileSplit) / 100); int setCount = Cycles.Count(); Double PercentilIndex = Percentile * setCount; if (PercentilIndex % 1 == 0) { percentileResult = Cycles.ElementAt((Convert.ToInt16(PercentilIndex) - 1)).Duration.TotalSeconds; } else { double indexMod = (PercentilIndex % 1); //subtracting .5 leaves just the integer after the convert. //There was probably another way to do that, but this is easy. int indexInt = Convert.ToInt16(PercentilIndex - .5); Double step1 = Cycles.ElementAt((Convert.ToInt16(indexInt) - 1)).Duration.TotalSeconds; Double step2 = Cycles.ElementAt((Convert.ToInt16(indexInt))).Duration.TotalSeconds; Double stepDiff = (step2 - step1); Double step3 = (stepDiff * indexMod); percentileResult = (step1 + step3); } CustomLabel percentileLabel = new CustomLabel(); percentileLabel.FromPosition = plan.StartTime.ToOADate(); percentileLabel.ToPosition = plan.EndTime.ToOADate(); percentileLabel.Text = string.Format("{0: 0.0} - {1} Percentile Split", percentileResult, Convert.ToDouble(SelectedPercentileSplit)); percentileLabel.LabelMark = LabelMarkStyle.LineSideMark; percentileLabel.ForeColor = Color.Purple; percentileLabel.RowIndex = 5; chart.ChartAreas[0].AxisX2.CustomLabels.Add(percentileLabel); } } } }
protected void SetSpeedPlanStrips(MOE.Common.Business.PlanCollection planCollection, Chart chart, DateTime graphStartDate, int minSpeedFilter) { int backGroundColor = 1; foreach (MOE.Common.Business.Plan plan in planCollection.PlanList) { plan.SetSpeedStatistics(minSpeedFilter); StripLine stripline = new StripLine(); float currentSize; currentSize = 3; stripline.Font = new Font(stripline.Font.Name, currentSize, stripline.Font.Style, stripline.Font.Unit); //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 = 3; CustomLabel avgLabel = new CustomLabel(); avgLabel.FromPosition = plan.StartTime.ToOADate(); avgLabel.ToPosition = plan.EndTime.ToOADate(); avgLabel.Text = "Ave Sp " + plan.AvgSpeed.ToString() + "\n" + "Std Dev " + plan.StdDevAvgSpeed.ToString(); avgLabel.LabelMark = LabelMarkStyle.LineSideMark; avgLabel.ForeColor = Color.Red; avgLabel.RowIndex = 1; CustomLabel eightyfifthLabel = new CustomLabel(); eightyfifthLabel.FromPosition = plan.StartTime.ToOADate(); eightyfifthLabel.ToPosition = plan.EndTime.ToOADate(); eightyfifthLabel.Text = "85% Sp " + plan.EightyFifth.ToString() + "\n"; eightyfifthLabel.LabelMark = LabelMarkStyle.LineSideMark; eightyfifthLabel.ForeColor = Color.Blue; eightyfifthLabel.RowIndex = 2; if (ShowPlanStatistics) { chart.ChartAreas["ChartArea1"].AxisX2.CustomLabels.Add(Plannumberlabel); if (ShowAverageSpeed) { chart.ChartAreas["ChartArea1"].AxisX2.CustomLabels.Add(avgLabel); } if (Show85Percentile) { chart.ChartAreas["ChartArea1"].AxisX2.CustomLabels.Add(eightyfifthLabel); } } backGroundColor++; } }
public static void SetSimplePlanStrips(PlanCollection PlanCollection, Chart Chart, DateTime StartDate, ControllerEventLogs EventLog) { int backGroundColor = 1; foreach (MOE.Common.Business.Plan plan in PlanCollection.PlanList) { 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 - StartDate).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 MOE.Common.Models.Controller_Event_Log r in EventLog.Events where r.EventCode == 107 && r.Timestamp > plan.StartTime && r.Timestamp < plan.EndTime select r; string premptCount = c.Count().ToString(); planPreemptsLabel.Text = "Preempts Serviced During Plan: " + premptCount; planPreemptsLabel.LabelMark = LabelMarkStyle.LineSideMark; planPreemptsLabel.ForeColor = Color.Red; planPreemptsLabel.RowIndex = 7; Chart.ChartAreas[0].AxisX2.CustomLabels.Add(planPreemptsLabel); backGroundColor++; } }
private void SetSimplePlanStrips(MOE.Common.Business.PlanCollection plans, Chart chart, DateTime StartDate) { PlanCollection.SetSimplePlanStrips(plans, chart, StartDate); }
private void CreateLaneTypeCharts(Common.Models.Signal signal, string laneTypeDescription, List <Common.Models.LaneType> laneTypes, List <Common.Models.MovementType> movementTypes, List <Common.Models.DirectionType> directions, MOE.Common.Business.PlanCollection plans, MOE.Common.Business.TMC.TMCInfo tmcInfo) { foreach (Common.Models.DirectionType direction in directions) { List <Models.Approach> approaches = (from r in signal.Approaches where r.DirectionType.DirectionTypeID == direction.DirectionTypeID select r).ToList(); List <Models.Detector> DetectorsByDirection = new List <Models.Detector>(); foreach (Models.Approach a in approaches) { foreach (Models.Detector d in a.Detectors) { if (d.DetectorSupportsThisMetric(5)) { DetectorsByDirection.Add(d); } } } //Loop through the major movement types List <int> movementTypeIdsSorted = new List <int> { 3, 1, 2 }; foreach (int x in movementTypeIdsSorted) { Common.Models.LaneType lanetype = (from r in laneTypes where r.Description == laneTypeDescription select r).FirstOrDefault(); Common.Models.MovementType movementType = (from r in movementTypes where r.MovementTypeID == x select r).FirstOrDefault(); List <Models.Detector> DetectorsForChart = (from r in DetectorsByDirection where r.MovementType.MovementTypeID == movementType.MovementTypeID && r.LaneType.LaneTypeID == lanetype.LaneTypeID select r).ToList(); //movement type 1 is the thru movement. We have to add the thru/turn lanes to the thru movment count. if (x == 1) { List <Models.Detector> turnthrudetectors = (from r in DetectorsByDirection where (r.MovementType.MovementTypeID == 4 || r.MovementType.MovementTypeID == 5) && r.LaneType.LaneTypeID == lanetype.LaneTypeID select r).ToList(); if (turnthrudetectors != null && turnthrudetectors.Count > 0) { DetectorsForChart.AddRange(turnthrudetectors); } } if (DetectorsForChart.Count > 0) { MOE.Common.Business.TMC.TMCMetric TMCchart = new MOE.Common.Business.TMC.TMCMetric(StartDate, EndDate, signal, direction, DetectorsForChart, lanetype, movementType, this, tmcInfo); Chart chart = TMCchart.chart; SetSimplePlanStrips(plans, chart, StartDate); //Create the File Name string chartName = CreateFileName(); //Save an image of the chart chart.SaveImage(MetricFileLocation + chartName, System.Web.UI.DataVisualization.Charting.ChartImageFormat.Jpeg); //ReturnList.Add(MetricWebPath + chartName); tmcInfo.ImageLocations.Add(MetricWebPath + chartName); } } } }