public static Approach CreateNewApproachWithDefaultValues(Signal signal, DirectionType dir, SPM db) { var appr = new Approach(); appr.Description = signal.SignalID + dir.Abbreviation; appr.DirectionTypeID = dir.DirectionTypeID; appr.SignalID = signal.SignalID; appr.MPH = 0; return(appr); }
public static Approach CopyApproachForSignal(Approach approachToCopy) { var newApproach = CopyApproachCommonProperties(approachToCopy, true); foreach (var d in approachToCopy.Detectors) { var dForNewApproach = Detector.CopyDetector(d.ID, false); newApproach.Detectors.Add(dForNewApproach); } return(newApproach); }
public ActionResult Copy(int approachID) { ViewBag.DirectionType = new SelectList(directionRepository.GetAllDirections(), "DirectionTypeID", "Abbreviation"); MOE.Common.Models.Repositories.IApproachRepository approachRepository = MOE.Common.Models.Repositories.ApproachRepositoryFactory.Create(); MOE.Common.Models.Approach approachToCopy = approachRepository.GetApproachByApproachID(approachID); Approach newApproach = MOE.Common.Models.Approach.CopyApproach(approachID); return(PartialView("Create", newApproach)); }
private static Approach SetDetChannelWhenMultipleDetectorsExist(Approach newApproach) { var detChannel = newApproach.Detectors.ToList()[0].DetChannel + 1; for (var i = 1; i < newApproach.Detectors.Count; i++) { newApproach.Detectors.ToList()[i].DetChannel = detChannel; newApproach.Detectors.ToList()[i].DetectorID = newApproach.SignalID + detChannel; detChannel++; } return(newApproach); }
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); }
public static Approach CopyApproachForSignal(int approachIDToCopy) { MOE.Common.Models.Repositories.IApproachRepository approachRepository = MOE.Common.Models.Repositories.ApproachRepositoryFactory.Create(); Approach approachToCopy = approachRepository.GetApproachByApproachID(approachIDToCopy); Approach newApproach = CopyApproachCommonProperties(approachToCopy); foreach (Detector d in approachToCopy.Detectors) { Detector dForNewApproach = Detector.CopyDetector(d.ID, false); newApproach.Detectors.Add(dForNewApproach); } return(newApproach); }
public static MOE.Common.Models.Signal CopySignal(MOE.Common.Models.Signal incommingSignal, string newSignalID) { Models.SPM db = new SPM(); MOE.Common.Models.Signal newSignal = new Models.Signal(); newSignal.IPAddress = "10.10.10.10"; newSignal.PrimaryName = incommingSignal.PrimaryName; newSignal.SecondaryName = incommingSignal.SecondaryName; newSignal.Longitude = incommingSignal.Longitude; newSignal.Latitude = incommingSignal.Latitude; newSignal.RegionID = incommingSignal.RegionID; newSignal.ControllerTypeID = incommingSignal.ControllerTypeID; newSignal.Enabled = incommingSignal.Enabled; newSignal.Approaches = new List <Models.Approach>(); //Models.Repositories.ISignalsRepository signalRepository = // Models.Repositories.SignalsRepositoryFactory.Create(); //signalRepository.AddOrUpdate(newSignal); //Models.Repositories.IApproachRepository approachRepository = // Models.Repositories.ApproachRepositoryFactory.Create(); foreach (Models.Approach a in incommingSignal.Approaches) { Approach aForNewSignal = Models.Approach.CopyApproachForSignal(a.ApproachID); //this does the db.Save inside. newSignal.Approaches.Add(aForNewSignal); //approachRepository.AddOrUpdate(aForNewSignal); } newSignal.SignalID = newSignalID; //try //{ // db.SaveChanges(); //} //catch (Exception ex) //{ // Models.Repositories.IApplicationEventRepository eventRepository = // Models.Repositories.ApplicationEventRepositoryFactory.Create(); // ApplicationEvent error = new ApplicationEvent(); // error.ApplicationName = "MOE.Common"; // error.Class = "Models.Signal.cs"; // error.Function = "CopySignal"; // error.Description = ex.Message; // error.SeverityLevel = ApplicationEvent.SeverityLevels.Medium; // error.Timestamp = DateTime.Now; // eventRepository.Add(error); // throw; //} return(newSignal); }
private bool CompareApproachProperties(Approach approachToCompare) { if (approachToCompare != null && SignalID == approachToCompare.SignalID && ApproachID == approachToCompare.ApproachID && DirectionTypeID == approachToCompare.DirectionTypeID && Description == approachToCompare.Description && MPH == approachToCompare.MPH && Detectors == approachToCompare.Detectors && ProtectedPhaseNumber == approachToCompare.ProtectedPhaseNumber && IsProtectedPhaseOverlap == approachToCompare.IsProtectedPhaseOverlap && PermissivePhaseNumber == approachToCompare.PermissivePhaseNumber ) { return(true); } return(false); }
public static Approach CopyApproach(int approachIDToCopy) { MOE.Common.Models.Repositories.IApproachRepository approachRepository = MOE.Common.Models.Repositories.ApproachRepositoryFactory.Create(); Approach approachToCopy = approachRepository.GetApproachByApproachID(approachIDToCopy); Approach newApproach = CopyApproachCommonProperties(approachToCopy); foreach (Detector d in approachToCopy.Detectors) { Detector dForNewApproach = Detector.CopyDetector(d.ID, true); //need to increase DetChannel if not copying the whole signal. newApproach.Detectors.Add(dForNewApproach); } if (newApproach.Detectors.Count > 1) { newApproach = SetDetChannelWhenMultipleDetectorsExist(newApproach); } return(newApproach); }
private Chart GetNewChart(MOE.Common.Models.Approach approach) { Chart chart = MOE.Common.Business.ChartFactory.CreateDefaultChart(this); CreateChartLegend(chart); if (ShowVolumes) { CreateVolumeSeries(chart); } else { chart.ChartAreas[0].AxisY2.Enabled = AxisEnabled.False; } CreateDetectorSeries(chart); CreateGreenSeries(chart); CreateYellowSeries(chart); CreateRedSeries(chart); return(chart); }
public static void AddDefaultObjectsToApproach(Approach appr, SPM db) { var D = new Detector(); var 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 var D2 = new Detector(); D2.LaneTypeID = 1; D2.MovementTypeID = 3; //LG2.Description = appr.Description + "Left (Phase Only)"; appr.Detectors.Add(D2); }
private static void CopyCommonSignalSettings(Signal origSignal, Signal newSignal) { newSignal.IPAddress = "10.10.10.10"; newSignal.PrimaryName = origSignal.PrimaryName; newSignal.SecondaryName = origSignal.SecondaryName; newSignal.Longitude = origSignal.Longitude; newSignal.Latitude = origSignal.Latitude; newSignal.RegionID = origSignal.RegionID; newSignal.ControllerTypeID = origSignal.ControllerTypeID; newSignal.Enabled = origSignal.Enabled; newSignal.Approaches = new List <Approach>(); if (origSignal.Approaches != null) { foreach (var a in origSignal.Approaches) { var aForNewSignal = Approach.CopyApproachForSignal(a); //this does the db.Save inside. newSignal.Approaches.Add(aForNewSignal); } } }
public static Approach CopyApproachCommonProperties(Approach approachToCopy, bool isVersionOrSignalCopy) { var newApproach = new Approach(); newApproach.SignalID = approachToCopy.SignalID; newApproach.VersionID = approachToCopy.VersionID; newApproach.DirectionTypeID = approachToCopy.DirectionTypeID; if (!isVersionOrSignalCopy) { newApproach.Description = approachToCopy.Description + " Copy"; } else { newApproach.Description = approachToCopy.Description; } newApproach.MPH = approachToCopy.MPH; newApproach.ProtectedPhaseNumber = approachToCopy.ProtectedPhaseNumber; newApproach.IsProtectedPhaseOverlap = approachToCopy.IsProtectedPhaseOverlap; newApproach.IsPermissivePhaseOverlap = approachToCopy.IsPermissivePhaseOverlap; newApproach.PermissivePhaseNumber = approachToCopy.PermissivePhaseNumber; newApproach.Detectors = new List <Detector>(); return(newApproach); }
public void AddOrUpdate(Approach approach) { MOE.Common.Models.Approach g = (from r in _db.Approaches where r.ApproachID == approach.ApproachID select r).FirstOrDefault(); if (g != null) { _db.Approaches.Remove(g); _db.Approaches.Add(approach); } else { //foreach (Detector d in approach.Detectors) //{ // if (d.DetectionTypes == null && d.DetectionTypeIDs != null) // { // d.DetectionTypes = _db.DetectionTypes // .Where(dt => d.DetectionTypeIDs.Contains(dt.DetectionTypeID)).ToList(); // } //} _db.Approaches.Add(approach); } }
public bool Equals(Approach approachToCompare) { return(CompareApproachProperties(approachToCompare)); }
private void AddArrivalOnGreen(Chart chart, double totalOnGreenArrivals, double totalDetectorHits, MOE.Common.Models.Approach approach) { double percentArrivalOnGreen = 0; if (totalDetectorHits > 0) { percentArrivalOnGreen = (totalOnGreenArrivals / totalDetectorHits) * 100; } Dictionary <string, string> statistics = new Dictionary <string, string>(); statistics.Add("AoG", Math.Round(percentArrivalOnGreen).ToString() + "%"); SetChartTitle(chart, approach, statistics); }