private void SetLaneGroupValues(Models.Approach Appr, Models.LaneGroup lg, DetectorConverter dc, int movementID, int lanetypeID) { Models.MovementType mt = (from r in db.MovementTypes where r.MovementTypeID == movementID select r).FirstOrDefault(); lg.Description = Appr.Description + mt.Abbreviation; lg.MovementTypeID = movementID; lg.LaneGroupTypeID = lanetypeID; lg.ProtectedPhaseNumber = dc.ProtectedPhase; lg.IsProtectedPhaseOverlap = dc.IsOverlap; if (dc.PermissivePhase > 0) { lg.PermissivePhaseNumber = dc.PermissivePhase; lg.IsPermissivePhaseOverlap = false; } }
private void FindLaneDetectors(List <Models.Detector> tmcDetectors, Models.MovementType movementType, List <Models.Detector> detectorsByDirection, Models.LaneType laneType) { foreach (MOE.Common.Models.Detector detector in detectorsByDirection) { if (detector.LaneType.LaneTypeID == laneType.LaneTypeID) { if (movementType.MovementTypeID == 1) { if (detector.MovementType.Description == "Thru" || detector.MovementType.Description == "Thru-Right" || detector.MovementType.Description == "Thru-Left") { tmcDetectors.Add(detector); } } else if (detector.MovementType.MovementTypeID == movementType.MovementTypeID) { tmcDetectors.Add(detector); } } } }
public TMCMetric(DateTime graphStartDate, DateTime graphEndDate, Models.Signal signal, Models.DirectionType direction, List <Models.Detector> detectorsByDirection, Models.LaneType laneType, Models.MovementType movementType, MOE.Common.Business.WCFServiceLibrary.TMCOptions options, MOE.Common.Business.TMC.TMCInfo tmcInfo) { Options = options; string extendedDirection = string.Empty; TimeSpan reportTimespan = graphEndDate - graphStartDate; SetChartProperties(); SetChartTitle(laneType, direction, movementType); ChartArea chartArea = new ChartArea(); chartArea.Name = "ChartArea1"; AddXAxis(chartArea, reportTimespan); AddYAxis(chartArea, movementType, options.YAxisMax, options.Y2AxisMax); chart.ChartAreas.Add(chartArea); CreateAndAddSeries(graphStartDate, graphEndDate); CreatAndAddLegend(chart); AddDataToChart(graphStartDate, graphEndDate, direction, detectorsByDirection, laneType, movementType, options, tmcInfo); }
private void AddYAxis(ChartArea chartArea, Models.MovementType movementType, double?thruMax, double?turnMax) { chartArea.AxisY.Title = "Volume (VPH)"; //chartArea.AxisY.IntervalAutoMode = IntervalAutoMode.FixedCount; chartArea.AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dot; if (movementType.Description == "Thru") { if (thruMax != null && thruMax > 0) { chartArea.AxisY.Maximum = thruMax.Value; if (thruMax.Value < 2000) { chartArea.AxisY.Interval = 100; } else { chartArea.AxisY.Interval = 500; } } } else { if (turnMax != null && turnMax > 0) { chartArea.AxisY.Maximum = turnMax.Value; if (turnMax.Value < 2000) { chartArea.AxisY.Interval = 100; } else { chartArea.AxisY.Interval = 500; } } } }
private void AddDataToChart(DateTime startDate, DateTime endDate, Models.DirectionType direction, List <Models.Detector> detectorsByDirection, Models.LaneType laneType, Models.MovementType movementType, MOE.Common.Business.WCFServiceLibrary.TMCOptions options, MOE.Common.Business.TMC.TMCInfo tmcInfo) { SortedDictionary <DateTime, int> MovementTotals = new SortedDictionary <DateTime, int>(); SortedDictionary <string, int> laneTotals = new SortedDictionary <string, int>(); int binSizeMultiplier = 60 / options.SelectedBinSize; int totalVolume = 0; List <MOE.Common.Models.Detector> tmcDetectors = new List <Models.Detector>(); FindLaneDetectors(tmcDetectors, movementType, detectorsByDirection, laneType); int laneCount = tmcDetectors.Count(); for (int ln = 1; ln < 5; ln++) { Models.Detector detector = (from r in tmcDetectors where r.LaneNumber == ln select r).FirstOrDefault(); if (detector != null) { if (laneCount > 0 && detector.MovementTypeID != 4 && detector.MovementTypeID != 5) { MOE.Common.Business.Detector d = new MOE.Common.Business.Detector(detector, startDate, endDate, options.SelectedBinSize); foreach (MOE.Common.Business.Volume volume in d.Volumes.Items) { if (options.ShowDataTable) { MOE.Common.Business.TMC.TMCData tmcd = new TMC.TMCData(); tmcd.Direction = detector.Approach.DirectionType.Description; tmcd.LaneType = detector.LaneType.Description; if (!options.ShowLaneVolumes) { tmcd.MovementType = tmcd.Direction; } else { tmcd.MovementType = detector.MovementType.Abbreviation; } //tmcd.DetectorID = detector.DetectorID; tmcd.Timestamp = volume.XAxis.AddMinutes(options.SelectedBinSize * -1); tmcd.Count = volume.YAxis / binSizeMultiplier; tmcInfo.tmcData.Add(tmcd); } if (options.ShowLaneVolumes) { chart.Series["Lane " + ln.ToString()].Points.AddXY(volume.XAxis, volume.YAxis); } //One of the calculations requires total volume by lane. This if statment keeps a //running total of that volume and stores it in a dictonary with the lane number. if (laneTotals.ContainsKey("L" + ln)) { laneTotals["L" + ln] += volume.YAxis; } else { laneTotals.Add("L" + ln, volume.YAxis); } //we need ot track the total number of cars (volume) for this movement. //this uses a time/int dictionary. The volume record for a given time is contibuted to by each lane. //Then the movement total can be plotted on the graph if (MovementTotals.ContainsKey(volume.XAxis)) { MovementTotals[volume.XAxis] += volume.YAxis; } else { MovementTotals.Add(volume.XAxis, volume.YAxis); } } } } } if (movementType.MovementTypeID == 1) { List <Models.Detector> thruTurnLanes = (from r in detectorsByDirection where r.MovementTypeID == 4 || r.MovementTypeID == 5 select r).ToList(); foreach (Models.Detector detector in thruTurnLanes) { MOE.Common.Business.Detector d = new MOE.Common.Business.Detector(detector, startDate, endDate, options.SelectedBinSize); foreach (MOE.Common.Business.Volume volume in d.Volumes.Items) { if (detector.MovementType.Abbreviation == "TL") { { if (options.ShowLaneVolumes) { if (options.ShowDataTable) { MOE.Common.Business.TMC.TMCData tmcd = new TMC.TMCData(); tmcd.Direction = detector.Approach.DirectionType.Description; tmcd.LaneType = detector.LaneType.Description; if (!options.ShowLaneVolumes) { tmcd.MovementType = tmcd.Direction; } else { tmcd.MovementType = detector.MovementType.Abbreviation; } //tmcd.DetectorID = detector.DetectorID; tmcd.Timestamp = volume.XAxis.AddMinutes(options.SelectedBinSize * -1); tmcd.Count = volume.YAxis / binSizeMultiplier; tmcInfo.tmcData.Add(tmcd); } chart.Series["Thru Left"].Points.AddXY(volume.XAxis, volume.YAxis); } } if (laneTotals.ContainsKey("TL")) { laneTotals["TL"] += volume.YAxis; } else { laneTotals.Add("TL", volume.YAxis); } } if (detector.MovementType.Abbreviation == "TR") { if (options.ShowLaneVolumes) { if (options.ShowDataTable) { MOE.Common.Business.TMC.TMCData tmcd = new TMC.TMCData(); tmcd.Direction = detector.Approach.DirectionType.Description; tmcd.LaneType = detector.LaneType.Description; if (!options.ShowLaneVolumes) { tmcd.MovementType = tmcd.Direction; } else { tmcd.MovementType = detector.MovementType.Abbreviation; } //tmcd.DetectorID = detector.DetectorID; tmcd.Timestamp = volume.XAxis.AddMinutes(options.SelectedBinSize * -1); tmcd.Count = volume.YAxis / binSizeMultiplier; tmcInfo.tmcData.Add(tmcd); } chart.Series["Thru Right"].Points.AddXY(volume.XAxis, volume.YAxis); } } if (laneTotals.ContainsKey("TR")) { laneTotals["TR"] += volume.YAxis; } else { laneTotals.Add("TR", volume.YAxis); } if (MovementTotals.ContainsKey(volume.XAxis)) { MovementTotals[volume.XAxis] += volume.YAxis; } else { MovementTotals.Add(volume.XAxis, volume.YAxis); } } } } int binMultiplier = 60 / options.SelectedBinSize; //get the total volume for the approach foreach (KeyValuePair <DateTime, int> totals in MovementTotals) { if (options.ShowTotalVolumes) { chart.Series["Total Volume"].Points.AddXY(totals.Key, totals.Value); } totalVolume += (totals.Value); } int highLaneVolume = 0; if (laneTotals.Values.Count > 0) { highLaneVolume = laneTotals.Values.Max(); } KeyValuePair <DateTime, int> peakHourValue = findPeakHour(MovementTotals, binMultiplier); int PHV = peakHourValue.Value; DateTime peakHour = peakHourValue.Key; int PeakHourMAXVolume = 0; string fluPlaceholder = ""; if (laneCount > 0 && highLaneVolume > 0) { double fLU = Convert.ToDouble(totalVolume) / (Convert.ToDouble(laneCount) * Convert.ToDouble(highLaneVolume)); fluPlaceholder = SetSigFigs(fLU, 2).ToString(); } else { fluPlaceholder = "Not Available"; } for (int i = 0; i < binMultiplier; i++) { if (MovementTotals.ContainsKey(peakHour.AddMinutes(i * options.SelectedBinSize))) { if (PeakHourMAXVolume < (MovementTotals[peakHour.AddMinutes(i * options.SelectedBinSize)])) { PeakHourMAXVolume = MovementTotals[peakHour.AddMinutes(i * options.SelectedBinSize)]; } } } string PHFPlaceholder = FindPHF(PHV, PeakHourMAXVolume, binMultiplier); string peakHourString = peakHour.ToShortTimeString() + " - " + peakHour.AddHours(1).ToShortTimeString(); Dictionary <string, string> statistics = new Dictionary <string, string>(); statistics.Add("Total Volume", (totalVolume / binMultiplier).ToString()); statistics.Add("Peak Hour", peakHourString); statistics.Add("Peak Hour Volume", (PHV / binMultiplier).ToString() + " VPH"); statistics.Add("PHF", PHFPlaceholder); statistics.Add("fLU", fluPlaceholder); chart.Titles.Add(ChartTitleFactory.GetStatistics(statistics)); SetSeriesVisibility(laneCount, options.ShowLaneVolumes); }
private void SetChartTitle(Models.LaneType laneType, Models.DirectionType direction, Models.MovementType movementType) { chart.Titles.Add(ChartTitleFactory.GetChartName(Options.MetricTypeID)); chart.Titles.Add(ChartTitleFactory.GetSignalLocationAndDateRange( Options.SignalID, Options.StartDate, Options.EndDate)); chart.Titles.Add(ChartTitleFactory.GetBoldTitle(direction.Description + " " + movementType.Description + " " + laneType.Description + " Lanes")); }