Beispiel #1
0
 public MOE.Common.Business.TMC.TMCInfo CreateTMCChart(MOE.Common.Business.WCFServiceLibrary.TMCOptions options)
 {
     try
     {
         MOE.Common.Models.Repositories.IMetricTypeRepository metricTypeRepository =
             MOE.Common.Models.Repositories.MetricTypeRepositoryFactory.Create();
         options.MetricType = metricTypeRepository.GetMetricsByID(options.MetricTypeID);
         options.CreateMetric();
         return(options.TmcInfo);
     }
     catch (Exception ex)
     {
         MOE.Common.Models.Repositories.IApplicationEventRepository logRepository =
             MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create();
         MOE.Common.Models.ApplicationEvent e = new MOE.Common.Models.ApplicationEvent();
         e.ApplicationName = "MOEWCFServicLibrary";
         e.Class           = this.GetType().ToString();
         e.Function        = "CreateMetric";
         e.SeverityLevel   = MOE.Common.Models.ApplicationEvent.SeverityLevels.High;
         e.Description     = ex.Message;
         e.Timestamp       = DateTime.Now;
         logRepository.Add(e);
         throw;
     }
     //return options.MetricInfoList;
 }
Beispiel #2
0
        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);
        }
Beispiel #3
0
 public MOE.Common.Business.TMC.TMCInfo CreateTMCChart(MOE.Common.Business.WCFServiceLibrary.TMCOptions options)
 {
     return(base.Channel.CreateTMCChart(options));
 }
Beispiel #4
0
 public System.Threading.Tasks.Task <MOE.Common.Business.TMC.TMCInfo> CreateTMCChartAsync(MOE.Common.Business.WCFServiceLibrary.TMCOptions options)
 {
     return(base.Channel.CreateTMCChartAsync(options));
 }
Beispiel #5
0
        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);
        }