public ActionResult GetTMCMetric(MOE.Common.Business.WCFServiceLibrary.TMCOptions metricOptions) { metricOptions.MetricType = GetMetricType(metricOptions.MetricTypeID); //string[] result = new string[1] { "" }; MOE.Common.Business.TMC.TMCInfo tmcInfo = new MOE.Common.Business.TMC.TMCInfo(); MOE.Common.Business.TMC.TMCViewModel tmcvm = new MOE.Common.Business.TMC.TMCViewModel( metricOptions.ShowLaneVolumes, metricOptions.ShowDataTable); if (ModelState.IsValid) { MetricGeneratorService.MetricGeneratorClient client = new MetricGeneratorService.MetricGeneratorClient(); try { client.Open(); tmcInfo = client.CreateTMCChart(metricOptions); client.Close(); if (metricOptions.ShowDataTable) { tmcvm.PopulateViewModel(tmcInfo.tmcData, metricOptions.SelectedBinSize); } tmcvm.ImageLocations = tmcInfo.ImageLocations; } catch (Exception ex) { client.Close(); return(Content("<h1>" + ex.Message + "</h1>")); } } return(PartialView("GetTMCMetric", tmcvm)); }
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); }
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 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 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); } } } }