示例#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);
        }
示例#2
0
 private Models.Approach CreateNewApproach(Data.Signals.Graph_DetectorsRow row,
                                           List <Models.DirectionType> directions)
 {
     MOE.Common.Models.Approach newApproach = new Models.Approach();
     newApproach.SignalID             = row.SignalID;
     newApproach.ProtectedPhaseNumber = Convert.ToInt32(row.Phase);
     newApproach.DirectionType        = directions.Where(d => d.Description == row.Direction).First();
     if (Convert.ToInt32(row.Phase) == 0)
     {
         newApproach.Description = newApproach.DirectionType.Description + " (Phase Only)";
     }
     else
     {
         newApproach.Description = newApproach.DirectionType.Description + " Phase " + newApproach.ProtectedPhaseNumber.ToString();
     }
     if (row.MPH > 0)
     {
         newApproach.MPH = row.MPH;
     }
     newApproach.IsProtectedPhaseOverlap = row.Is_Overlap;
     if (Convert.ToInt32(row.Perm_Phase) > 0)
     {
         newApproach.PermissivePhaseNumber = Convert.ToInt32(row.Perm_Phase);
     }
     return(newApproach);
 }
示例#3
0
 /// <summary>
 /// Default Constructor Used for PCDs
 /// </summary>
 /// <param name="cycleEvents"></param>
 /// <param name="detectortable"></param>
 /// <param name="startdate"></param>
 /// <param name="enddate"></param>
 /// <param name="signalId"></param>
 /// <param name="region"></param>
 public RLMPlanCollection(List <MOE.Common.Models.Controller_Event_Log> cycleEvents, DateTime startdate,
                          DateTime enddate, double srlvSeconds, Models.Approach approach)
 {
     this.Approach    = approach;
     this.srlvSeconds = srlvSeconds;
     GetPlanCollection(startdate, enddate, cycleEvents);
 }
示例#4
0
        public Phase(Models.Approach approach,
                     DateTime startDate, DateTime endDate, List <int> eventCodes, int StartofCycleEvent, bool UsePermissivePhase)


        {
            startDate = startDate.AddMinutes(-1);
            endDate   = endDate.AddMinutes(+1);

            Approach = approach;

            StartDate = startDate;
            _EndDate  = endDate;
            if (!UsePermissivePhase)
            {
                PhaseNumber = Approach.ProtectedPhaseNumber;
            }
            else
            {
                PhaseNumber = Approach.PermissivePhaseNumber ?? 0;
            }
            IsOverlap = false;
            SignalID  = Approach.Signal.SignalID;


            MOE.Common.Models.Repositories.IControllerEventLogRepository cer = MOE.Common.Models.Repositories.ControllerEventLogRepositoryFactory.Create();

            Events = cer.GetEventsByEventCodesParam(SignalID, startDate, endDate,
                                                    eventCodes, PhaseNumber);

            GetCycles(StartofCycleEvent);
        }
示例#5
0
文件: Approach.cs 项目: gmonk/ATSPM
 public Approach(Models.Approach approach)
 {
     SignalID       = approach.SignalID;
     Direction      = approach.DirectionType.Description;
     ApproachModel  = approach;
     Detectors      = new DetectorCollection(approach);
     DetectorEvents = null;
 }
示例#6
0
 public PlanCollection(List <Models.Controller_Event_Log> cycleEvents,
                       List <Models.Controller_Event_Log> detectorEvents, DateTime startdate,
                       DateTime enddate, Models.Approach approach, List <Models.Controller_Event_Log> preemptEvents)
 {
     this.approach = approach;
     GetPlanCollection(startdate, enddate,
                       cycleEvents, detectorEvents, preemptEvents);
 }
示例#7
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);
 }
示例#8
0
文件: RLMPlan.cs 项目: zfx1982/ATSPM
        public RLMPlan(DateTime start, DateTime end, int planNumber,
                       List <MOE.Common.Models.Controller_Event_Log> cycleEvents,
                       double srlvSeconds, Models.Approach approach)
        {
            Approach        = approach;
            startTime       = start;
            endTime         = end;
            this.planNumber = planNumber;
            bool usePermissivePhase = false;

            MOE.Common.Models.SPM db = new MOE.Common.Models.SPM();
            List <int>            l  = new List <int> {
                1, 8, 9, 10, 11
            };
            List <MOE.Common.Models.Controller_Event_Log> permEvents = null;

            if (Approach.PermissivePhaseNumber != null)
            {
                usePermissivePhase = true;
                MOE.Common.Models.Repositories.IControllerEventLogRepository cveRepository =
                    MOE.Common.Models.Repositories.ControllerEventLogRepositoryFactory.Create();
                permEvents = cveRepository.GetEventsByEventCodesParam(Approach.SignalID,
                                                                      start, end, l, Approach.ProtectedPhaseNumber);
                foreach (Models.Controller_Event_Log row in cycleEvents)
                {
                    if (row.Timestamp >= start && row.Timestamp <= end && GetEventType(row.EventCode) == RLMCycle.EventType.BeginYellowClearance)
                    {
                        foreach (MOE.Common.Models.Controller_Event_Log permRow in permEvents)
                        {
                            if (GetEventType(permRow.EventCode) == RLMCycle.EventType.BeginYellowClearance)
                            {
                                if (row.Timestamp == permRow.Timestamp)
                                {
                                    usePermissivePhase = false;
                                }
                            }
                        }
                    }
                }
            }
            this.srlvSeconds = srlvSeconds;
            startTime        = start;
            endTime          = end;
            if (usePermissivePhase)
            {
                GetRedCycle(start, end, permEvents);
            }
            else
            {
                GetRedCycle(start, end, cycleEvents);
            }
        }
示例#9
0
文件: Plan.cs 项目: zfx1982/ATSPM
 /// <summary>
 /// Constructor that sets the start time, end time and plan, and creates the the lower level objects and statistics
 /// </summary>
 /// <param name="start"></param>
 /// <param name="end"></param>
 /// <param name="plan"></param>
 /// <param name="signaltable"></param>
 /// <param name="detectortable"></param>
 public Plan(DateTime start, DateTime end, int planNumber, List <Models.Controller_Event_Log> signaltable,
             List <Models.Controller_Event_Log> detectortable, List <Models.Controller_Event_Log> preempttable,
             Models.Approach approach)
 {
     this.SignalID    = approach.SignalID;
     this.PhaseNumber = approach.ProtectedPhaseNumber;
     startTime        = start;
     endTime          = end;
     PlanNumber       = planNumber;
     GetGreenYellowRedCycle(start, end, signaltable, detectortable, preempttable);
     //pcdCollection = new PCDDataPointCollection(start, end, signaltable, detectortable, preempttable, signalid, phase);
     //setstatistics();
 }
示例#10
0
 public static Approach CopyApproachCommonProperties(Approach approachToCopy)
 {
     Models.Approach newApproach = new Models.Approach();
     newApproach.SignalID                = approachToCopy.SignalID;
     newApproach.DirectionTypeID         = approachToCopy.DirectionTypeID;
     newApproach.Description             = approachToCopy.Description + " Copy";
     newApproach.MPH                     = approachToCopy.MPH;
     newApproach.ProtectedPhaseNumber    = approachToCopy.ProtectedPhaseNumber;
     newApproach.IsProtectedPhaseOverlap = approachToCopy.IsProtectedPhaseOverlap;
     newApproach.PermissivePhaseNumber   = approachToCopy.PermissivePhaseNumber;
     newApproach.Detectors               = new List <MOE.Common.Models.Detector>();
     return(newApproach);
 }
示例#11
0
        private Models.Approach GetApproachToAnalyze(Models.Signal signal, string direction)
        {
            Models.Approach approachToAnalyze = null;
            var             approaches        = signal.Approaches.Where(a => a.DirectionType.Description == direction).ToList();

            foreach (var approach in approaches)
            {
                if (approach.GetDetectorsForMetricType(6).Count > 0)
                {
                    approachToAnalyze = approach;
                }
            }
            return(approachToAnalyze);
        }
示例#12
0
        internal static Title GetPhaseAndPhaseDescriptions(Models.Approach approach, bool getPermissivePhase)
        {
            Title title;
            int   phaseNumber = getPermissivePhase ? approach.PermissivePhaseNumber.Value : approach.ProtectedPhaseNumber;

            if (approach.IsProtectedPhaseOverlap)
            {
                title = new Title("Overlap " + phaseNumber + ": " + approach.Description);
            }
            else
            {
                title = new Title("Phase " + phaseNumber + ": " + approach.Description);
            }

            title.Font = new Font(title.Font.FontFamily, title.Font.Size, FontStyle.Bold);
            return(title);
        }
示例#13
0
        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;
            }
        }
示例#14
0
        /// <summary>
        /// Constructor for Signal phase
        /// </summary>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <param name="signalId"></param>
        /// <param name="phaseNumber"></param>
        /// <param name="region"></param>
        /// <param name="detChannel"></param>
        public SignalPhase(DateTime startDate, DateTime endDate, Models.Approach approach,
                           bool showVolume, int binSize, int metricTypeID)
        {
            this.approach   = approach;
            this.startDate  = startDate;
            this.endDate    = endDate;
            this.direction  = approach.DirectionType.Description;
            this.showVolume = showVolume;
            this.binSize    = binSize;


            if (!approach.IsProtectedPhaseOverlap)
            {
                GetSignalPhaseData(startDate, endDate, showVolume, binSize, metricTypeID);
            }
            else
            {
                GetSignalOverlapData(startDate, endDate, showVolume, binSize);
            }
        }
示例#15
0
        public static void AddDefaultObjectsToApproach(Models.Approach appr, MOE.Common.Models.SPM db)
        {
            Models.Detector D = new Models.Detector();

            Models.DetectionType basic = (from r in db.DetectionTypes
                                          where r.DetectionTypeID == 1
                                          select r).FirstOrDefault();

            D.LaneTypeID     = 1;
            D.MovementTypeID = 1;
            //D.Description = appr.Description + "Thru (Phase Only)";
            appr.Detectors.Add(D);

            //LeftTurn
            Models.Detector D2 = new Models.Detector();
            D2.LaneTypeID     = 1;
            D2.MovementTypeID = 3;
            //LG2.Description = appr.Description + "Left (Phase Only)";
            appr.Detectors.Add(D2);
        }
示例#16
0
        /// <summary>
        /// Constructor Used for Split monitor
        /// </summary>
        /// <param name="phasenumber"></param>
        /// <param name="signalID"></param>
        /// <param name="CycleEventsTable"></param>
        public AnalysisPhase(int phasenumber, string signalID, List <Models.Controller_Event_Log> CycleEventsTable)
        {
            MOE.Common.Models.Repositories.ISignalsRepository repository =
                MOE.Common.Models.Repositories.SignalsRepositoryFactory.Create();
            var signal = repository.GetSignalBySignalID(signalID);

            this.phaseNumber = phasenumber;
            this.signalId    = signalID;
            this.IsOverlap   = false;
            List <Models.Controller_Event_Log> PedEvents   = FindPedEvents(CycleEventsTable, phasenumber);
            List <Models.Controller_Event_Log> PhaseEvents = FindPhaseEvents(CycleEventsTable, phasenumber);

            Cycles = new AnalysisPhaseCycleCollection(phasenumber, signalId, PhaseEvents, PedEvents);
            Models.Approach approach = signal.Approaches.Where(a => a.ProtectedPhaseNumber == phasenumber).FirstOrDefault();
            if (approach != null)
            {
                this.Direction = approach.DirectionType.Description;
            }
            else
            {
                this.Direction = "Unknown";
            }
        }
示例#17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="signalId"></param>
        /// <param name="direction"></param>
        /// <param name="delta"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <param name="upstream"></param>
        /// <param name="maxYAxis"></param>
        private void GeneratePCD(Models.Approach approach, int delta,
                                 DateTime startDate, DateTime endDate, bool upstream, int maxYAxis)
        {
            MOE.Common.Models.Repositories.ISignalsRepository repository =
                MOE.Common.Models.Repositories.SignalsRepositoryFactory.Create();
            //var signal = repository.GetSignalBySignalID(approach.SignalId);

            //Create a location string to show the combined cross strees
            string location = string.Empty;

            if (approach.Signal != null)
            {
                location = approach.Signal.PrimaryName + " " + approach.Signal.SecondaryName;
            }
            string chartName = string.Empty;

            //MOE.Common.Data.LinkPivotTableAdapters.Graph_DetectorsTableAdapter gdAdapter =
            //  new Data.LinkPivotTableAdapters.Graph_DetectorsTableAdapter();

            //find the upstream approach
            if (!String.IsNullOrEmpty(approach.DirectionType.Description))
            {
                //Find PCD detector for this appraoch
                MOE.Common.Models.Detector gd =
                    approach.Signal.GetDetectorsForSignalThatSupportAMetricByApproachDirection(
                        6, approach.DirectionType.Description).FirstOrDefault();

                //Check for null value
                if (gd != null)
                {
                    //Instantiate a signal phase object
                    SignalPhase sp = new MOE.Common.Business.SignalPhase(
                        startDate, endDate, approach, false,
                        15, 13);

                    //Check the direction of the Link Pivot
                    if (upstream)
                    {
                        //Create a chart for the upstream detector before adjustments
                        upstreamBeforePCDPath = CreateChart(sp, startDate, endDate, location, "before",
                                                            ConfigurationManager.AppSettings["ImageLocation"], maxYAxis, "UpstreamBefore");

                        //Add the total arrival on green before adjustments to the running total
                        existingTotalAOG += sp.TotalArrivalOnGreen;

                        //Add the volume from the signal phase to the running total
                        existingVolume += sp.TotalVolume;

                        //Re run the signal phase by the optimized delta change to get the adjusted pcd
                        sp.LinkPivotAddSeconds(delta * -1);

                        //Create a chart for the upstream detector after adjustments
                        upstreamAfterPCDPath = CreateChart(sp, startDate, endDate, location, "after",
                                                           ConfigurationManager.AppSettings["ImageLocation"], maxYAxis, "UpstreamAfter");

                        //Add the total arrival on green after adjustments to the running total
                        predictedTotalAOG += sp.TotalArrivalOnGreen;

                        //Add the volume from the signal phase to the running total
                        predictedVolume += sp.TotalVolume;
                    }
                    else
                    {
                        //Create a chart for downstream detector before adjustments
                        downstreamBeforePCDPath = CreateChart(sp, startDate, endDate, location, "before",
                                                              ConfigurationManager.AppSettings["ImageLocation"], maxYAxis, "DownstreamBefore");

                        //Add the arrivals on green to the total arrivals on green running total
                        existingTotalAOG += sp.TotalArrivalOnGreen;

                        //Add the volume before adjustments to the running total volume
                        existingVolume += sp.TotalVolume;

                        //Re run the signal phase by the optimized delta change to get the adjusted pcd
                        sp.LinkPivotAddSeconds(delta);

                        //Create a pcd chart for downstream after adjustments
                        downstreamAfterPCDPath = CreateChart(sp, startDate, endDate, location, "after",
                                                             ConfigurationManager.AppSettings["ImageLocation"], maxYAxis, "DownstreamAfter");

                        //Add the total arrivals on green to the running total
                        predictedTotalAOG += sp.TotalArrivalOnGreen;

                        //Add the total volume to the running total after adjustments
                        predictedVolume += sp.TotalVolume;
                    }
                }
            }
        }
示例#18
0
文件: Approach.cs 项目: gmonk/ATSPM
 public void SetDetectorEvents(Models.Approach approach, DateTime startdate, DateTime enddate, bool has_pcd,
                               bool has_tmc)
 {
     DetectorEvents =
         Detectors.CombineDetectorDataByApproachAndType(startdate, enddate, approach, has_pcd, has_tmc);
 }
示例#19
0
        public void CreateLaneGroupsAndLanes(List <DetectorConverter> CDetectorsForADirection, Models.Approach Appr)
        {
            Models.Approach.AddDefaultObjectsToApproach(Appr, db);

            //Update defaults based on values in DB
            for (int lanetypeID = 1; lanetypeID < 8; lanetypeID++)
            {
                var LanesByType = from d in CDetectorsForADirection
                                  where d.LaneTypeID == lanetypeID
                                  select d;

                if (LanesByType.Count() > 0)
                {
                    for (int movementID = 1; movementID < 6; movementID++)
                    {
                        Models.LaneGroup LaneGroupByTypeAndMovement;
                        LaneGroupByTypeAndMovement = (from r in Appr.LaneGroups
                                                      where r.LaneGroupTypeID == lanetypeID &&
                                                      r.MovementTypeID == movementID
                                                      select r).FirstOrDefault();

                        List <DetectorConverter> detectorsforMovement = (from l in LanesByType
                                                                         where l.MovementTypeID == movementID
                                                                         select l).ToList();

                        if (LaneGroupByTypeAndMovement == null && detectorsforMovement.Count > 0)
                        {
                            LaneGroupByTypeAndMovement = new Models.LaneGroup();
                            SetLaneGroupValues(Appr, LaneGroupByTypeAndMovement, detectorsforMovement.FirstOrDefault(), movementID, lanetypeID);


                            Appr.LaneGroups.Add(LaneGroupByTypeAndMovement);
                            LaneGroupByTypeAndMovement = (from r in Appr.LaneGroups
                                                          where r.LaneGroupTypeID == lanetypeID &&
                                                          r.MovementTypeID == movementID
                                                          select r).FirstOrDefault();
                        }
                        else if (LaneGroupByTypeAndMovement != null && detectorsforMovement.Count > 0)
                        {
                            SetLaneGroupValues(Appr, LaneGroupByTypeAndMovement, detectorsforMovement.FirstOrDefault(), movementID, lanetypeID);
                        }
                        else if (LaneGroupByTypeAndMovement == null && detectorsforMovement.Count == 0)
                        {
                            return;
                        }


                        for (int lanenumber = 1; lanenumber < 5; lanenumber++)
                        {
                            List <DetectorConverter> detConvertersByLaneNumber = (from d in detectorsforMovement
                                                                                  where d.LaneNumber == lanenumber
                                                                                  select d).ToList();

                            //Models.Graph_Detectors graphDetector = (from r in LaneGroupByTypeAndMovement.Detectors
                            //                    where r.LaneNumber == lanenumber
                            //                    select r).FirstOrDefault();

                            if (detConvertersByLaneNumber != null)
                            {
                                foreach (DetectorConverter d in detConvertersByLaneNumber)
                                {
                                    //detConverterByLaneNumber.GraphDetectorModel.LaneGroupID = LaneGroupByTypeAndMovement.LaneGroupID;
                                    d.GraphDetectorModel.LaneNumber = lanenumber;
                                    if (LaneGroupByTypeAndMovement.Detectors == null)
                                    {
                                        LaneGroupByTypeAndMovement.Detectors = new List <MOE.Common.Models.Graph_Detectors>();
                                    }
                                    LaneGroupByTypeAndMovement.Detectors.Add(d.GraphDetectorModel);
                                }
                            }
                            //else if (detConverterByLaneNumber != null && lane != null)
                            //{

                            //    lane.Detectors.Add(detConverterByLaneNumber.GraphDetectorModel);
                            //}
                            else if (detConvertersByLaneNumber == null)
                            {
                                return;
                            }
                        }
                    }
                }
            }
        }