public TMCMetric(DateTime graphStartDate, DateTime graphEndDate, Models.Signal signal, DirectionType direction, List <Models.Detector> detectorsByDirection, LaneType laneType, MovementType movementType, TMCOptions options, TMCInfo tmcInfo) { Options = options; var extendedDirection = string.Empty; var reportTimespan = graphEndDate - graphStartDate; SetChartProperties(); SetChartTitle(laneType, direction, movementType); var 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 AddDataToChart(DateTime startDate, DateTime endDate, DirectionType direction, List <Models.Detector> detectorsByDirection, LaneType laneType, MovementType movementType, TMCOptions options, TMCInfo tmcInfo) { var MovementTotals = new SortedDictionary <DateTime, int>(); var laneTotals = new SortedDictionary <string, int>(); var binSizeMultiplier = 60 / options.SelectedBinSize; var totalVolume = 0; var tmcDetectors = new List <Models.Detector>(); FindLaneDetectors(tmcDetectors, movementType, detectorsByDirection, laneType); var laneCount = tmcDetectors.Count(); for (var ln = 1; ln < 5; ln++) { var detector = (from r in tmcDetectors where r.LaneNumber == ln select r).FirstOrDefault(); if (detector != null) { if (laneCount > 0 && detector.MovementTypeID != 4 && detector.MovementTypeID != 5) { var d = new Detector(detector, startDate, endDate, options.SelectedBinSize); foreach (var volume in d.Volumes.Items) { if (options.ShowDataTable) { var tmcd = new 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].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) { var thruTurnLanes = (from r in detectorsByDirection where r.MovementTypeID == 4 || r.MovementTypeID == 5 select r).ToList(); foreach (var detector in thruTurnLanes) { var d = new Detector(detector, startDate, endDate, options.SelectedBinSize); foreach (var volume in d.Volumes.Items) { if (detector.MovementType.Abbreviation == "TL") { { if (options.ShowLaneVolumes) { if (options.ShowDataTable) { var tmcd = new 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) { var tmcd = new 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); } } } } var binMultiplier = 60 / options.SelectedBinSize; //get the total volume for the approach foreach (var totals in MovementTotals) { if (options.ShowTotalVolumes) { chart.Series["Total Volume"].Points.AddXY(totals.Key, totals.Value); } totalVolume += totals.Value; } var highLaneVolume = 0; if (laneTotals.Values.Count > 0) { highLaneVolume = laneTotals.Values.Max(); } var peakHourValue = findPeakHour(MovementTotals, binMultiplier); var PHV = peakHourValue.Value; var peakHour = peakHourValue.Key; var PeakHourMAXVolume = 0; var fluPlaceholder = ""; if (laneCount > 0 && highLaneVolume > 0) { var fLU = Convert.ToDouble(totalVolume) / (Convert.ToDouble(laneCount) * Convert.ToDouble(highLaneVolume)); fluPlaceholder = SetSigFigs(fLU, 2).ToString(); } else { fluPlaceholder = "Not Available"; } for (var 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)]; } } } var PHFPlaceholder = FindPHF(PHV, PeakHourMAXVolume, binMultiplier); var peakHourString = peakHour.ToShortTimeString() + " - " + peakHour.AddHours(1).ToShortTimeString(); var statistics = new Dictionary <string, string>(); statistics.Add("Total Volume", (totalVolume / binMultiplier).ToString()); statistics.Add("Peak Hour", peakHourString); statistics.Add("Peak Hour Volume", PHV / binMultiplier + " VPH"); statistics.Add("PHF", PHFPlaceholder); statistics.Add("fLU", fluPlaceholder); chart.Titles.Add(ChartTitleFactory.GetStatistics(statistics)); SetSeriesVisibility(laneCount, options.ShowLaneVolumes); }