Esempio n. 1
0
        public void CreateApproach(List <DetectorConverter> CDetectorsForADirection, Models.Signal signal, int directiontypeID)
        {
            Models.DirectionType dir = (from r in db.DirectionTypes
                                        where r.DirectionTypeID == directiontypeID
                                        select r).FirstOrDefault();

            Models.Approach app = Models.Approach.CreateNewApproachWithDefaultValues(signal, dir, db);



            foreach (DetectorConverter dc in CDetectorsForADirection)
            {
                if (dc.DecisionPoint > app.Decision_Point)
                {
                    app.Decision_Point = dc.DecisionPoint;
                }

                if (dc.MPH > app.MPH)
                {
                    app.MPH = dc.MPH;
                }

                if (app.Movement_Delay < dc.MovementDelay)
                {
                    app.Movement_Delay = dc.MovementDelay;
                }
            }
            if (signal.Approaches == null)
            {
                signal.Approaches = new List <MOE.Common.Models.Approach>();
            }
            signal.Approaches.Add(app);

            CreateLaneGroupsAndLanes(CDetectorsForADirection, app);
        }
Esempio n. 2
0
 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"));
 }
Esempio n. 3
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);
        }
Esempio n. 4
0
 public ApproachVolumeChart(ApproachVolumeOptions options, ApproachVolume approachVolume, Models.DirectionType direction1, Models.DirectionType direction2)
 {
     MetricInfo = new MetricInfo();
     Options    = options;
     Chart      = ChartFactory.CreateApproachVolumeChart(options, approachVolume);
     AddDataToChart(approachVolume, options);
 }
Esempio n. 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);
        }
Esempio n. 6
0
 public static Models.Approach CreateNewApproachWithDefaultValues(Models.Signal signal, Models.DirectionType dir, MOE.Common.Models.SPM db)
 {
     Models.Approach appr = new Models.Approach();
     appr.Description     = signal.SignalID + dir.Abbreviation;
     appr.DirectionTypeID = dir.DirectionTypeID;
     appr.SignalID        = signal.SignalID;
     appr.MPH             = 0;
     return(appr);
 }