private void SetPcds(DateTime endDate, List <DateTime> dates, int cycleTime) { foreach (var dt in dates) { var tempStartDate = dt; var tempEndDate = new DateTime(dt.Year, dt.Month, dt.Day, endDate.Hour, endDate.Minute, endDate.Second); var upstreamPcd = new SignalPhase(tempStartDate, tempEndDate, SignalApproach, false, 15, 13, false, cycleTime); UpstreamPcd.Add(upstreamPcd); AogUpstreamBefore += upstreamPcd.TotalArrivalOnGreen; TotalVolumeUpstream += upstreamPcd.TotalVolume; var downstreamPcd = new SignalPhase( tempStartDate, tempEndDate, DownSignalApproach, false, 15, 13, false, cycleTime); DownstreamPcd.Add(downstreamPcd); AogDownstreamBefore += downstreamPcd.TotalArrivalOnGreen; TotalVolumeDownstream += downstreamPcd.TotalVolume; } PaogUpstreamBefore = Math.Round(AogUpstreamBefore / TotalVolumeUpstream, 2) * 100; //AogUpstreamBefore = UpstreamPcd.TotalArrivalOnGreen; //upstreamBeforePCDPath = CreateChart(upstreamPCD, startDate, endDate, signalLocation, // "before", chartLocation); PaogDownstreamBefore = Math.Round(AogDownstreamBefore / TotalVolumeDownstream, 2) * 100; //aOGDownstreamBefore = downstreamPCD.TotalArrivalOnGreen; //downstreamBeforePCDPath = CreateChart(downstreamPCD, startDate, endDate, downSignalLocation, // "before", chartLocation); }
private void AddDataToChart(Chart chart, MOE.Common.Business.SignalPhase signalPhase) { double totalDetectorHits = 0; double totalOnGreenArrivals = 0; foreach (MOE.Common.Business.Plan plan in signalPhase.Plans.PlanList) { if (plan.CycleCollection.Count > 0) { foreach (MOE.Common.Business.Cycle pcd in plan.CycleCollection) { totalOnGreenArrivals += AddCycleToChart(chart, pcd); totalDetectorHits += pcd.DetectorCollection.Count; } } } if (ShowVolumes) { AddVolumeToChart(chart, signalPhase.Volume); } if (ShowArrivalsOnGreen) { AddArrivalOnGreen(chart, totalOnGreenArrivals, totalDetectorHits, signalPhase.Approach); } if (ShowPlanStatistics) { SetPlanStrips(signalPhase.Plans.PlanList, chart); } }
public SignalPhaseCollection(DateTime startDate, DateTime endDate, string signalID, bool showVolume, int binSize, int metricTypeId) { var repository = SignalsRepositoryFactory.Create(); var signal = repository.GetVersionOfSignalByDate(signalID, startDate); var approaches = signal.GetApproachesForSignalThatSupportMetric(metricTypeId); if (signal.Approaches != null && approaches.Count > 0) { //Parallel.ForEach(approaches, approach => foreach (Models.Approach approach in approaches) { var protectedSignalPhase = new SignalPhase(startDate, endDate, approach, showVolume, binSize, metricTypeId, false); SignalPhaseList.Add(protectedSignalPhase); if (approach.PermissivePhaseNumber.HasValue) { var permissiveSignalPhase = new SignalPhase(startDate, endDate, approach, showVolume, binSize, metricTypeId, true); SignalPhaseList.Add(permissiveSignalPhase); } }//); //TODO: Should we remove phases with no cycles? SignalPhaseList = SignalPhaseList.OrderBy(s => s.Approach.ProtectedPhaseNumber).ToList(); } }
private void SetChartTitles(SignalPhase signalPhase, Dictionary <string, string> statistics) { chart.Titles.Add(ChartTitleFactory.GetChartName(Options.MetricTypeID)); chart.Titles.Add(ChartTitleFactory.GetSignalLocationAndDateRange( Options.SignalID, Options.StartDate, Options.EndDate)); chart.Titles.Add(ChartTitleFactory.GetPhaseAndPhaseDescriptions(signalPhase.Approach, signalPhase.GetPermissivePhase)); chart.Titles.Add(ChartTitleFactory.GetStatistics(statistics)); }
protected void AddDataToChart(Chart chart, SignalPhase signalPhase) { double totalDetectorHits = 0; var yAxisHolder = 0; if (signalPhase.Cycles.Count > 0) { var dt = signalPhase.StartDate; while (dt < signalPhase.EndDate) { double binTotalStops = 0; double binPercentAoR = 0; double binDetectorHits = 0; var cycles = signalPhase.Cycles.Where(c => c.StartTime >= dt && c.EndTime < dt.AddMinutes(Options.SelectedBinSize)); foreach (var cycle in cycles) { totalDetectorHits += cycle.DetectorEvents.Count; binDetectorHits += cycle.DetectorEvents.Count; foreach (var detectorPoint in cycle.DetectorEvents) { if (detectorPoint.YPoint < cycle.GreenLineY) { binTotalStops++; totalAoR++; } } if (binDetectorHits > 0) { binPercentAoR = binTotalStops / binDetectorHits * 100; } } chart.Series["Percent Arrivals on Red"].Points.AddXY(dt, binPercentAoR); chart.Series["Total Vehicles"].Points.AddXY(dt, binDetectorHits * (60 / Options.SelectedBinSize)); chart.Series["Arrivals on Red"].Points.AddXY(dt, binTotalStops * (60 / Options.SelectedBinSize)); dt = dt.AddMinutes(Options.SelectedBinSize); if (yAxisHolder < binTotalStops * (60 / Options.SelectedBinSize) && Options.YAxisMax == null) { yAxisHolder = Convert.ToInt16(binDetectorHits * (60 / Options.SelectedBinSize)); yAxisHolder = RoundToNearest(yAxisHolder, 100); chart.ChartAreas[0].AxisY.Maximum = yAxisHolder + 250; } } } totalCars = totalDetectorHits; if (totalDetectorHits > 0) { totalPercentAoR = totalAoR / totalCars * 100; } var statistics = new Dictionary <string, string>(); statistics.Add("Total Detector Hits", totalCars.ToString()); statistics.Add("Total AoR", totalAoR.ToString()); statistics.Add("Percent AoR for the select period", Math.Round(totalPercentAoR).ToString()); SetChartTitles(signalPhase, statistics); }
private void SetChartTitles(SignalPhase signalPhase, Dictionary <string, string> statistics) { Chart.Titles.Add(ChartTitleFactory.GetChartName(Options.MetricTypeID)); Chart.Titles.Add(ChartTitleFactory.GetSignalLocationAndDateRange( Options.SignalID, Options.StartDate, Options.EndDate)); Chart.Titles.Add(ChartTitleFactory.GetPhaseAndPhaseDescriptions( signalPhase.Approach, signalPhase.GetPermissivePhase)); Chart.Titles.Add(ChartTitleFactory.GetStatistics(statistics)); Chart.Titles.Add(ChartTitleFactory.GetTitle( "Simplified Approach Delay. Displays time between approach activation during the red phase and when the phase turns green." + " \n Does NOT account for start up delay, deceleration, or queue length that exceeds the detection zone.")); Chart.Titles.LastOrDefault().Docking = Docking.Bottom; }
private void SetChartTitles(SignalPhase signalPhase, Dictionary <string, string> statistics) { chart.Titles.Add(ChartTitleFactory.GetChartName(Options.MetricTypeID)); chart.Titles.Add(ChartTitleFactory.GetSignalLocationAndDateRange( Options.SignalID, Options.StartDate, Options.EndDate)); if (!signalPhase.Approach.IsProtectedPhaseOverlap) { chart.Titles.Add(ChartTitleFactory.GetPhaseAndPhaseDescriptions(signalPhase.Approach.ProtectedPhaseNumber, signalPhase.Approach.DirectionType.Description)); } else { chart.Titles.Add(ChartTitleFactory.GetPhaseAndPhaseDescriptions(signalPhase.Approach.ProtectedPhaseNumber, " Overlap")); } chart.Titles.Add(ChartTitleFactory.GetStatistics(statistics)); }
protected void AddDataToChart(Chart chart, SignalPhase signalPhase, int binSize, bool showDelayPerHour, bool showDelayPerVehicle) { var dt = signalPhase.StartDate; while (dt < signalPhase.EndDate) { var pcdsInBin = from item in signalPhase.Cycles where item.StartTime >= dt && item.StartTime < dt.AddMinutes(binSize) select item; var binDelay = pcdsInBin.Sum(d => d.TotalDelay); var binVolume = pcdsInBin.Sum(d => d.TotalVolume); double bindDelaypervehicle = 0; double bindDelayperhour = 0; if (binVolume > 0 && pcdsInBin.Any()) { bindDelaypervehicle = binDelay / binVolume; } else { bindDelaypervehicle = 0; } bindDelayperhour = binDelay * (60 / binSize) / 60 / 60; if (showDelayPerVehicle) { chart.Series["Approach Delay Per Vehicle"].Points.AddXY(dt, bindDelaypervehicle); } if (showDelayPerHour) { chart.Series["Approach Delay"].Points.AddXY(dt, bindDelayperhour); } dt = dt.AddMinutes(binSize); } var statistics = new Dictionary <string, string>(); statistics.Add("Average Delay Per Vehicle (AD)", Math.Round(signalPhase.AvgDelay) + " seconds"); statistics.Add("Total Delay For Selected Period (TD)", Math.Round(signalPhase.TotalDelay / 60 / 60, 1) + " hours"); SetChartTitles(signalPhase, statistics); }
public SignalPhaseCollection(MetricOptions options, bool showVolume, int binSize) { var repository = SignalsRepositoryFactory.Create(); var signal = repository.GetVersionOfSignalByDate(options.SignalID, options.StartDate); var approaches = signal.GetApproachesForSignalThatSupportMetric(options.MetricTypeID); if (signal.Approaches != null && approaches.Count > 0) { //Parallel.ForEach(approaches, approach => foreach (Models.Approach approach in approaches) { if (approach.ProtectedPhaseNumber != 0) { var protectedSignalPhase = new SignalPhase(options.StartDate, options.EndDate, approach, showVolume, binSize, options.MetricTypeID, false); SignalPhaseList.Add(protectedSignalPhase); } }//); //TODO: Should we remove phases with no cycles? SignalPhaseList = SignalPhaseList.OrderBy(s => s.Approach.ProtectedPhaseNumber).ToList(); } }
/// <summary> /// Creates a pcd chart specific to the Link Pivot /// </summary> /// <param name="sp"></param> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <param name="location"></param> /// <param name="chartNameSuffix"></param> /// <param name="chartLocation"></param> /// <returns></returns> private string CreateChart(SignalPhase sp, DateTime startDate, DateTime endDate, string location, string chartNameSuffix, string chartLocation) { var chart = new Chart(); //Display the PDC chart chart = GetNewChart(startDate, endDate, sp.Approach.SignalID, sp.Approach.ProtectedPhaseNumber, sp.Approach.DirectionType.Description, location, sp.Approach.IsProtectedPhaseOverlap, 150, 2000, false, 2); AddDataToChart(chart, sp, startDate, false, true); //Create the File Name var chartName = "LinkPivot-" + sp.Approach.SignalID + "-" + sp.Approach.ProtectedPhaseNumber + "-" + startDate.Year + startDate.ToString("MM") + startDate.ToString("dd") + startDate.ToString("HH") + startDate.ToString("mm") + "-" + endDate.Year + endDate.ToString("MM") + endDate.ToString("dd") + endDate.ToString("HH") + endDate.ToString("mm-") + chartNameSuffix + ".jpg"; //Save an image of the chart chart.SaveImage(chartLocation + chartName, ChartImageFormat.Jpeg); return(chartName); }
public DelayChart(ApproachDelayOptions options, SignalPhase signalPhase) { Options = options; //Set the chart properties Chart = ChartFactory.CreateDefaultChart(options); ChartFactory.SetImageProperties(Chart); //Create the chart legend var chartLegend = new Legend(); chartLegend.Name = "MainLegend"; chartLegend.Docking = Docking.Left; Chart.Legends.Add(chartLegend); //Primary Y axis (delay per vehicle) if (Options.ShowDelayPerVehicle) { if (Options.YAxisMax != null) { Chart.ChartAreas[0].AxisY.Maximum = Options.YAxisMax.Value; } Chart.ChartAreas[0].AxisY.Minimum = 0; Chart.ChartAreas[0].AxisY.Enabled = AxisEnabled.True; Chart.ChartAreas[0].AxisY.MajorTickMark.Enabled = true; Chart.ChartAreas[0].AxisY.MajorGrid.Enabled = true; Chart.ChartAreas[0].AxisY.Interval = 5; Chart.ChartAreas[0].AxisY.TitleForeColor = Color.Blue; Chart.ChartAreas[0].AxisY.Title = "Delay Per Vehicle (Seconds) "; } //secondary y axis (total delay) if (Options.ShowDelayPerVehicle) { if (Options.Y2AxisMax != null && Options.Y2AxisMax > 0) { Chart.ChartAreas[0].AxisY2.Maximum = Options.Y2AxisMax.Value; } else { Chart.ChartAreas[0].AxisY2.Maximum = 10; } Chart.ChartAreas[0].AxisY2.Minimum = 0; Chart.ChartAreas[0].AxisY2.Enabled = AxisEnabled.True; Chart.ChartAreas[0].AxisY2.MajorTickMark.Enabled = true; Chart.ChartAreas[0].AxisY2.MajorGrid.Enabled = false; Chart.ChartAreas[0].AxisY2.Interval = 5; Chart.ChartAreas[0].AxisY2.Title = "Delay per Hour (hrs) "; Chart.ChartAreas[0].AxisY2.TitleForeColor = Color.Red; } //Add the point series var delayPerVehicleSeries = new Series(); delayPerVehicleSeries.ChartType = SeriesChartType.Line; delayPerVehicleSeries.Color = Color.Blue; delayPerVehicleSeries.Name = "Approach Delay Per Vehicle"; delayPerVehicleSeries.YAxisType = AxisType.Primary; delayPerVehicleSeries.XValueType = ChartValueType.DateTime; var delaySeries = new Series(); delaySeries.ChartType = SeriesChartType.Line; delaySeries.Color = Color.Red; delaySeries.Name = "Approach Delay"; delaySeries.YAxisType = AxisType.Secondary; delaySeries.XValueType = ChartValueType.DateTime; var pointSeries = new Series(); pointSeries.ChartType = SeriesChartType.Point; pointSeries.Color = Color.White; pointSeries.Name = "Posts"; pointSeries.XValueType = ChartValueType.DateTime; pointSeries.IsVisibleInLegend = false; Chart.Series.Add(pointSeries); Chart.Series.Add(delaySeries); Chart.Series.Add(delayPerVehicleSeries); //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, signalPhase, Options.SelectedBinSize, Options.ShowTotalDelayPerHour, Options.ShowDelayPerVehicle); if (Options.ShowPlanStatistics) { SetPlanStrips(signalPhase.Plans, Chart, Options.StartDate, Options.ShowPlanStatistics); } }
private void GeneratePcd(Approach approach, int delta, DateTime startDate, DateTime endDate, bool upstream, int maxYAxis) { var settings = Models.Repositories.ApplicationSettingsRepositoryFactory.Create().GetGeneralSettings(); //Create a location string to show the combined cross strees var location = string.Empty; if (approach.Signal != null) { location = approach.Signal.PrimaryName + " " + approach.Signal.SecondaryName; } var chartName = string.Empty; //find the upstream approach if (!string.IsNullOrEmpty(approach.DirectionType.Description)) { //Find PCD detector for this appraoch var detector = approach.Signal.GetDetectorsForSignalThatSupportAMetricByApproachDirection( 6, approach.DirectionType.Description).FirstOrDefault(); //Check for null value if (detector != null) { //Instantiate a signal phase object var sp = new SignalPhase(startDate, endDate, approach, false, 15, 13, false); //Check the direction of the Link Pivot if (upstream) { //Create a chart for the upstream detector before adjustments UpstreamBeforePCDPath = settings.ImageUrl + CreateChart(sp, startDate, endDate, location, "before", settings.ImagePath, maxYAxis, "UpstreamBefore"); //Add the total arrival on green before adjustments to the running total ExistingTotalAOG += sp.TotalArrivalOnGreen; //Add the volume from the signal phase to the running total ExistingVolume += sp.TotalVolume; //Re run the signal phase by the optimized delta change to get the adjusted pcd sp.LinkPivotAddSeconds(delta * -1); //Create a chart for the upstream detector after adjustments UpstreamAfterPCDPath = settings.ImageUrl + CreateChart(sp, startDate, endDate, location, "after", settings.ImagePath, maxYAxis, "UpstreamAfter"); //Add the total arrival on green after adjustments to the running total PredictedTotalAOG += sp.TotalArrivalOnGreen; //Add the volume from the signal phase to the running total PredictedVolume += sp.TotalVolume; } else { //Create a chart for downstream detector before adjustments DownstreamBeforePCDPath = settings.ImageUrl + CreateChart(sp, startDate, endDate, location, "before", settings.ImagePath, maxYAxis, "DownstreamBefore"); //Add the arrivals on green to the total arrivals on green running total ExistingTotalAOG += sp.TotalArrivalOnGreen; //Add the volume before adjustments to the running total volume ExistingVolume += sp.TotalVolume; //Re run the signal phase by the optimized delta change to get the adjusted pcd sp.LinkPivotAddSeconds(delta); //Create a pcd chart for downstream after adjustments DownstreamAfterPCDPath = settings.ImageUrl + CreateChart(sp, startDate, endDate, location, "after", settings.ImagePath, maxYAxis, "DownstreamAfter"); //Add the total arrivals on green to the running total PredictedTotalAOG += sp.TotalArrivalOnGreen; //Add the total volume to the running total after adjustments PredictedVolume += sp.TotalVolume; } } } }
public ArriveOnRedChart(AoROptions options, SignalPhase signalPhase) { Options = options; Chart = ChartFactory.CreateDefaultChart(options); //Set the chart properties ChartFactory.SetImageProperties(Chart); //Create the chart legend var chartLegend = new Legend(); chartLegend.Name = "MainLegend"; chartLegend.Docking = Docking.Left; Chart.Legends.Add(chartLegend); if (Options.YAxisMax != null) { Chart.ChartAreas[0].AxisY.Maximum = Options.YAxisMax.Value; } Chart.ChartAreas[0].AxisY.Minimum = 0; Chart.ChartAreas[0].AxisY.Title = "Volume (Vehicles Per Hour)"; Chart.ChartAreas[0].AxisY.Interval = 500; Chart.ChartAreas[0].AxisY2.Title = "Percent AoR"; Chart.ChartAreas[0].AxisY2.Maximum = 100; Chart.ChartAreas[0].AxisY2.Interval = 10; Chart.ChartAreas[0].AxisY2.Enabled = AxisEnabled.True; //Add the point series var AoRSeries = new Series(); AoRSeries.ChartType = SeriesChartType.Line; AoRSeries.BorderDashStyle = ChartDashStyle.Dash; AoRSeries.Color = Color.Red; AoRSeries.Name = "Arrivals on Red"; AoRSeries.XValueType = ChartValueType.DateTime; var TVSeries = new Series(); TVSeries.ChartType = SeriesChartType.Line; TVSeries.BorderDashStyle = ChartDashStyle.Dash; TVSeries.Color = Color.Black; TVSeries.Name = "Total Vehicles"; TVSeries.XValueType = ChartValueType.DateTime; var PARSeries = new Series(); PARSeries.ChartType = SeriesChartType.Line; PARSeries.Color = Color.Red; PARSeries.Name = "Percent Arrivals on Red"; PARSeries.BorderWidth = 2; PARSeries.XValueType = ChartValueType.DateTime; PARSeries.YAxisType = AxisType.Secondary; var pointSeries = new Series(); pointSeries.ChartType = SeriesChartType.Point; pointSeries.Color = Color.White; pointSeries.Name = "Posts"; pointSeries.XValueType = ChartValueType.DateTime; pointSeries.IsVisibleInLegend = false; Chart.Series.Add(pointSeries); Chart.Series.Add(AoRSeries); Chart.Series.Add(PARSeries); Chart.Series.Add(TVSeries); //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, signalPhase); SetPlanStrips(signalPhase.Plans, Chart, Options.StartDate, Options.ShowPlanStatistics); }
/// <summary> /// Adds data points to a graph with the series GreenLine, YellowLine, Redline /// and Points already added. /// </summary> /// <param name="chart"></param> /// <param name="signalPhase"></param> /// <param name="startDate"></param> private void AddDataToChart(Chart chart, SignalPhase signalPhase, DateTime startDate, bool showVolume, bool showArrivalOnGreen) { decimal totalDetectorHits = 0; decimal totalOnGreenArrivals = 0; decimal percentArrivalOnGreen = 0; foreach (var cycle in signalPhase.Cycles) { chart.Series["Change to Green"].Points.AddXY( //pcd.StartTime, cycle.GreenEvent, cycle.GreenLineY); chart.Series["Change to Yellow"].Points.AddXY( //pcd.StartTime, cycle.YellowEvent, cycle.YellowLineY); chart.Series["Change to Red"].Points.AddXY( //pcd.StartTime, cycle.EndTime, cycle.RedLineY); totalDetectorHits += cycle.DetectorEvents.Count; foreach (var detectorPoint in cycle.DetectorEvents) { chart.Series["Detector Activation"].Points.AddXY( //pcd.StartTime, detectorPoint.TimeStamp, detectorPoint.YPoint); if (detectorPoint.YPoint > cycle.GreenLineY && detectorPoint.YPoint < cycle.RedLineY) { totalOnGreenArrivals++; } } } if (showVolume) { foreach (var v in signalPhase.Volume.Items) { chart.Series["Volume Per Hour"].Points.AddXY(v.XAxis, v.YAxis); } } //if arrivals on green is selected add the data to the chart if (showArrivalOnGreen) { if (totalDetectorHits > 0) { percentArrivalOnGreen = totalOnGreenArrivals / totalDetectorHits * 100; } else { percentArrivalOnGreen = 0; } var title = new Title(); title.Text = Math.Round(percentArrivalOnGreen) + "% AoG"; title.Font = new Font(FontFamily.GenericSansSerif, 20); chart.Titles.Add(title); SetPlanStrips(signalPhase.Plans, chart, startDate); } }
private void AddDataToChart(Chart chart, SignalPhase signalPhase, DateTime startDate, bool showVolume, bool showArrivalOnGreen) { decimal totalDetectorHits = 0; decimal totalOnGreenArrivals = 0; decimal percentArrivalOnGreen = 0; foreach (var cycle in signalPhase.Cycles) { //add the data for the green line chart.Series["Change to Green"].Points.AddXY( cycle.GreenEvent, cycle.GreenLineY); //add the data for the yellow line chart.Series["Change to Yellow"].Points.AddXY( cycle.YellowEvent, cycle.YellowLineY); //add the data for the red line chart.Series["Change to Red"].Points.AddXY( cycle.EndTime, cycle.RedLineY); //add the detector hits to the running total totalDetectorHits += cycle.DetectorEvents.Count; //add the detector hits to the detector activation series foreach (var detectorPoint in cycle.DetectorEvents) { chart.Series["Detector Activation"].Points.AddXY( detectorPoint.TimeStamp, detectorPoint.YPoint); //if this is an arrival on green add it to the running total if (detectorPoint.YPoint > cycle.GreenLineY && detectorPoint.YPoint < cycle.RedLineY) { totalOnGreenArrivals++; } } } //add the volume data to the volume series if true if (showVolume) { foreach (var v in signalPhase.Volume.Items) { chart.Series["Volume Per Hour"].Points.AddXY(v.XAxis, v.YAxis); } } //if arrivals on green is selected add the data to the chart if (showArrivalOnGreen) { if (totalDetectorHits > 0) { percentArrivalOnGreen = totalOnGreenArrivals / totalDetectorHits * 100; } else { percentArrivalOnGreen = 0; } var title = new Title(); title.Text = Math.Round(percentArrivalOnGreen) + "% AoG"; title.Font = new Font(FontFamily.GenericSansSerif, 20); chart.Titles.Add(title); SetPlanStrips(signalPhase.Plans, chart, startDate); } var mcr = MetricCommentRepositoryFactory.Create(); var comment = mcr.GetLatestCommentForReport(signalPhase.Approach.SignalID, MetricTypeID); if (comment != null) { chart.Titles.Add(comment.CommentText); chart.Titles[1].Docking = Docking.Bottom; chart.Titles[1].ForeColor = Color.Red; } }
public ArriveOnRedChart(AoROptions options, SignalPhase signalPhase) { Options = options; var reportTimespan = Options.EndDate - Options.StartDate; //Set the chart properties ChartFactory.SetImageProperties(chart); //Create the chart legend var chartLegend = new Legend(); chartLegend.Name = "MainLegend"; chartLegend.Docking = Docking.Left; chart.Legends.Add(chartLegend); //Create the chart area var chartArea = new ChartArea(); chartArea.Name = "ChartArea1"; if (Options.YAxisMax != null) { chartArea.AxisY.Maximum = Options.YAxisMax.Value; } chartArea.AxisY.Minimum = 0; chartArea.AxisY.Title = "Volume (Vehicles Per Hour)"; chartArea.AxisY.Interval = 500; chartArea.AxisY2.Title = "Percent AoR"; chartArea.AxisY2.Maximum = 100; chartArea.AxisY2.Interval = 10; chartArea.AxisY2.Enabled = AxisEnabled.True; chartArea.AxisX.Title = "Time (Hour of Day)"; chartArea.AxisX.IntervalType = DateTimeIntervalType.Hours; chartArea.AxisX.LabelStyle.Format = "HH"; chartArea.AxisX2.LabelStyle.Format = "HH"; if (reportTimespan.Days < 1) { if (reportTimespan.Hours > 1) { chartArea.AxisX2.Interval = 1; chartArea.AxisX.Interval = 1; } else { chartArea.AxisX.LabelStyle.Format = "HH:mm"; chartArea.AxisX2.LabelStyle.Format = "HH:mm"; } } chartArea.AxisX2.Enabled = AxisEnabled.True; chartArea.AxisX2.MajorTickMark.Enabled = true; chartArea.AxisX2.IntervalType = DateTimeIntervalType.Hours; chartArea.AxisX2.LabelAutoFitStyle = LabelAutoFitStyles.None; chart.ChartAreas.Add(chartArea); //Add the point series var AoRSeries = new Series(); AoRSeries.ChartType = SeriesChartType.Line; AoRSeries.BorderDashStyle = ChartDashStyle.Dash; AoRSeries.Color = Color.Red; AoRSeries.Name = "Arrivals on Red"; AoRSeries.XValueType = ChartValueType.DateTime; var TVSeries = new Series(); TVSeries.ChartType = SeriesChartType.Line; TVSeries.BorderDashStyle = ChartDashStyle.Dash; TVSeries.Color = Color.Black; TVSeries.Name = "Total Vehicles"; TVSeries.XValueType = ChartValueType.DateTime; var PARSeries = new Series(); PARSeries.ChartType = SeriesChartType.Line; PARSeries.Color = Color.Red; PARSeries.Name = "Percent Arrivals on Red"; PARSeries.BorderWidth = 2; PARSeries.XValueType = ChartValueType.DateTime; PARSeries.YAxisType = AxisType.Secondary; var pointSeries = new Series(); pointSeries.ChartType = SeriesChartType.Point; pointSeries.Color = Color.White; pointSeries.Name = "Posts"; pointSeries.XValueType = ChartValueType.DateTime; pointSeries.IsVisibleInLegend = false; chart.Series.Add(pointSeries); chart.Series.Add(AoRSeries); chart.Series.Add(PARSeries); chart.Series.Add(TVSeries); //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, signalPhase); SetPlanStrips(signalPhase.Plans, chart, Options.StartDate, Options.ShowPlanStatistics); }
/// <summary> /// Creates a pcd chart specific to the Link Pivot /// </summary> /// <param name="sp"></param> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <param name="location"></param> /// <param name="chartNameSuffix"></param> /// <param name="chartLocation"></param> /// <returns>Chart Name</returns> private string CreateChart(SignalPhase sp, DateTime startDate, DateTime endDate, string location, string chartNameSuffix, string chartLocation, int maxYAxis, string directionBeforeAfter) { //Instantiate the chart object Chart chart = new Chart(); //Add formatting to the chart chart = GetNewChart(startDate, endDate, sp.Approach.SignalID, sp.Approach.ProtectedPhaseNumber, sp.Approach.DirectionType.Description, location, sp.Approach.IsProtectedPhaseOverlap, maxYAxis, 2000, false, 2); //Add the data to the chart AddDataToChart(chart, sp, startDate, endDate, false, true); //Add info to the based on direction and before or after adjustments if (directionBeforeAfter == "DownstreamBefore") { DownstreamBeforeTitle = chart.Titles[0].Text + " " + chart.Titles[1].Text; foreach (var l in chart.ChartAreas["ChartArea1"].AxisX2.CustomLabels) { DownstreamBeforeTitle += " " + l.Text; } } else if (directionBeforeAfter == "UpstreamBefore") { UpstreamBeforeTitle = chart.Titles[0].Text + " " + chart.Titles[1].Text; foreach (var l in chart.ChartAreas["ChartArea1"].AxisX2.CustomLabels) { UpstreamBeforeTitle += " " + l.Text; } } else if (directionBeforeAfter == "DownstreamAfter") { DownstreamAfterTitle = chart.Titles[0].Text + " " + chart.Titles[1].Text; foreach (var l in chart.ChartAreas["ChartArea1"].AxisX2.CustomLabels) { DownstreamAfterTitle += " " + l.Text; } } else if (directionBeforeAfter == "UpstreamAfter") { UpstreamAfterTitle = chart.Titles[0].Text + " " + chart.Titles[1].Text; foreach (var l in chart.ChartAreas["ChartArea1"].AxisX2.CustomLabels) { UpstreamAfterTitle += " " + l.Text; } } //Create the File Name string chartName = "LinkPivot-" + sp.Approach.SignalID + "-" + sp.Approach.ProtectedPhaseNumber.ToString() + "-" + startDate.Year.ToString() + startDate.ToString("MM") + startDate.ToString("dd") + startDate.ToString("HH") + startDate.ToString("mm") + "-" + endDate.Year.ToString() + endDate.ToString("MM") + endDate.ToString("dd") + endDate.ToString("HH") + endDate.ToString("mm-") + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + chartNameSuffix + ".jpg"; //Save an image of the chart chart.SaveImage(chartLocation + @"LinkPivot\" + chartName, System.Web.UI.DataVisualization.Charting.ChartImageFormat.Jpeg); return(chartName); }
public DelayChart(ApproachDelayOptions options, SignalPhase signalPhase) { Options = options; var reportTimespan = Options.EndDate - Options.StartDate; var extendedDirection = signalPhase.Approach.DirectionType.Description; //Set the chart properties ChartFactory.SetImageProperties(chart); //Create the chart legend var chartLegend = new Legend(); chartLegend.Name = "MainLegend"; chartLegend.Docking = Docking.Left; chart.Legends.Add(chartLegend); //Create the chart area var chartArea = new ChartArea(); chartArea.Name = "ChartArea1"; //Primary Y axis (delay per vehicle) if (Options.ShowDelayPerVehicle) { if (Options.YAxisMax != null) { chartArea.AxisY.Maximum = Options.YAxisMax.Value; } chartArea.AxisY.Minimum = 0; chartArea.AxisY.Enabled = AxisEnabled.True; chartArea.AxisY.MajorTickMark.Enabled = true; chartArea.AxisY.MajorGrid.Enabled = true; chartArea.AxisY.Interval = 5; chartArea.AxisY.TitleForeColor = Color.Blue; chartArea.AxisY.Title = "Delay Per Vehicle (Seconds) "; } //secondary y axis (total delay) if (Options.ShowDelayPerVehicle) { if (Options.Y2AxisMax != null && Options.Y2AxisMax > 0) { chartArea.AxisY2.Maximum = Options.Y2AxisMax.Value; } else { chartArea.AxisY2.Maximum = 10; } chartArea.AxisY2.Minimum = 0; chartArea.AxisY2.Enabled = AxisEnabled.True; chartArea.AxisY2.MajorTickMark.Enabled = true; chartArea.AxisY2.MajorGrid.Enabled = false; chartArea.AxisY2.Interval = 5; chartArea.AxisY2.Title = "Delay per Hour (hrs) "; chartArea.AxisY2.TitleForeColor = Color.Red; } chartArea.AxisX.Title = "Time (Hour of Day)"; chartArea.AxisX.IntervalType = DateTimeIntervalType.Hours; chartArea.AxisX.LabelStyle.Format = "HH"; chartArea.AxisX2.LabelStyle.Format = "HH"; if (reportTimespan.Days < 1) { if (reportTimespan.Hours > 1) { chartArea.AxisX2.Interval = 1; chartArea.AxisX.Interval = 1; } else { chartArea.AxisX.LabelStyle.Format = "HH:mm"; chartArea.AxisX2.LabelStyle.Format = "HH:mm"; } } chartArea.AxisX2.Enabled = AxisEnabled.True; chartArea.AxisX2.MajorTickMark.Enabled = true; chartArea.AxisX2.IntervalType = DateTimeIntervalType.Hours; chartArea.AxisX2.LabelAutoFitStyle = LabelAutoFitStyles.None; chart.ChartAreas.Add(chartArea); //Add the point series var delayPerVehicleSeries = new Series(); delayPerVehicleSeries.ChartType = SeriesChartType.Line; delayPerVehicleSeries.Color = Color.Blue; delayPerVehicleSeries.Name = "Approach Delay Per Vehicle"; delayPerVehicleSeries.YAxisType = AxisType.Primary; delayPerVehicleSeries.XValueType = ChartValueType.DateTime; var delaySeries = new Series(); delaySeries.ChartType = SeriesChartType.Line; delaySeries.Color = Color.Red; delaySeries.Name = "Approach Delay"; delaySeries.YAxisType = AxisType.Secondary; delaySeries.XValueType = ChartValueType.DateTime; var pointSeries = new Series(); pointSeries.ChartType = SeriesChartType.Point; pointSeries.Color = Color.White; pointSeries.Name = "Posts"; pointSeries.XValueType = ChartValueType.DateTime; pointSeries.IsVisibleInLegend = false; chart.Series.Add(pointSeries); chart.Series.Add(delaySeries); chart.Series.Add(delayPerVehicleSeries); //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, signalPhase, Options.SelectedBinSize, Options.ShowTotalDelayPerHour, Options.ShowDelayPerVehicle); if (Options.ShowPlanStatistics) { SetPlanStrips(signalPhase.Plans, chart, Options.StartDate, Options.ShowPlanStatistics); } }