private void CopyApproaches(Signal signalFromDb, Signal newSignal) { List <Approach> approaches = (from r in _db.Approaches where r.VersionID == signalFromDb.VersionID select r).ToList(); foreach (var apprFromDb in approaches) { Approach newApp = new Approach(); newApp.SignalID = newSignal.SignalID; newApp.Description = apprFromDb.Description; newApp.DirectionTypeID = apprFromDb.DirectionTypeID; newApp.ProtectedPhaseNumber = apprFromDb.ProtectedPhaseNumber; newApp.DirectionTypeID = apprFromDb.DirectionTypeID; newApp.IsProtectedPhaseOverlap = apprFromDb.IsProtectedPhaseOverlap; newApp.MPH = apprFromDb.MPH; newApp.PermissivePhaseNumber = apprFromDb.PermissivePhaseNumber; newApp.VersionID = newSignal.VersionID; _db.Approaches.Add(newApp); //_db.SaveChanges(); CopyDetectors(apprFromDb, newApp); } }
private static FilterSignal GetFilterSignal(MOE.Common.Models.Signal signal) { var filterSignal = new FilterSignal { Exclude = false, SignalId = signal.SignalID, VersionId = signal.VersionID, Description = signal.SignalDescription }; foreach (var approach in signal.Approaches) { var filterApproach = new FilterApproach { ApproachId = approach.ApproachID, Exclude = false, Description = approach.Description }; foreach (var detector in approach.Detectors) { var filterDetector = new FilterDetector { Id = detector.ID, Exclude = false, Description = detector.Description }; filterApproach.FilterDetectors.Add(filterDetector); } filterSignal.FilterApproaches.Add(filterApproach); } return(filterSignal); }
public ActionResult Copy(string id, string newId) { MOE.Common.Models.Signal newSignal = new MOE.Common.Models.Signal(); if (id == null) { return(Content("<h1>A signal ID is required</h1>")); } Signal signal = signalsRepository.GetSignalBySignalID(id); if (signal != null) { newSignal = MOE.Common.Models.Signal.CopySignal(signal, newId); } try { signalsRepository.AddOrUpdate(newSignal); } catch (Exception ex) { return(Content("<h1>" + ex.Message + "</h1>")); } finally { AddSelectListsToViewBag(newSignal); } return(PartialView("Edit", newSignal)); }
public override List <string> CreateMetric() { base.CreateMetric(); MOE.Common.Models.Repositories.ISignalsRepository signalRepository = MOE.Common.Models.Repositories.SignalsRepositoryFactory.Create(); Signal = signalRepository.GetSignalBySignalID(SignalID); this.MetricTypeID = 6; Chart chart = new Chart(); string location = GetSignalLocation(); //SignalPhaseCollection signalphasecollection = new SignalPhaseCollection( // StartDate, // EndDate, // SignalID, // ShowVolumes, // SelectedBinSize, // MetricTypeID); //If there are phases in the database add the charts //if (signalphasecollection.SignalPhaseList.Count > 0) //{ // foreach (MOE.Common.Business.SignalPhase signalPhase in signalphasecollection.SignalPhaseList) // { // if (signalPhase.Plans.PlanList.Count > 0) // { // chart = GetNewChart(signalPhase.Approach); // AddDataToChart(chart, signalPhase); // string chartName = CreateFileName(); // chart.ImageLocation = MetricFileLocation + chartName; // chart.SaveImage(MetricFileLocation + chartName, System.Web.UI.DataVisualization.Charting.ChartImageFormat.Jpeg); // ReturnList.Add(MetricWebPath + chartName); // } //} List <Approach> metricApproaches = Signal.GetApproachesForSignalThatSupportMetric(this.MetricTypeID); if (metricApproaches.Count > 0) { foreach (Approach approach in metricApproaches) { MOE.Common.Business.SignalPhase signalPhase = new SignalPhase(StartDate, EndDate, approach, ShowVolumes, SelectedBinSize, MetricTypeID); chart = GetNewChart(approach); AddDataToChart(chart, signalPhase); string chartName = CreateFileName(); chart.ImageLocation = MetricFileLocation + chartName; chart.SaveImage(MetricFileLocation + chartName, System.Web.UI.DataVisualization.Charting.ChartImageFormat.Jpeg); ReturnList.Add(MetricWebPath + chartName); } } return(ReturnList); }
public override List <string> CreateMetric() { base.CreateMetric(); List <string> returnString = new List <string>(); MOE.Common.Models.Repositories.ISignalsRepository sr = MOE.Common.Models.Repositories.SignalsRepositoryFactory.Create(); MOE.Common.Models.Signal signal = sr.GetSignalBySignalID(SignalID); //for (int x = 1; x < maxPhase + 1; x++) List <Approach> metricApproaches = signal.GetApproachesForSignalThatSupportMetric(this.MetricTypeID); if (metricApproaches.Count > 0) { foreach (Approach approach in metricApproaches) { //MOE.Common.Business.CustomReport.Phase phase = new MOE.Common.Business.CustomReport.Phase(detectors, x, SignalID, StartDate, EndDate, new List<int> { 1, 4, 5, 6, 7, 8, 9, 10, 61, 63, 64 }, 1); MOE.Common.Business.CustomReport.Phase phase = new MOE.Common.Business.CustomReport.Phase(approach, StartDate, EndDate, new List <int> { 1, 4, 5, 6, 7, 8, 9, 10, 61, 63, 64 }, 1, false); phase.ApproachDirection = approach.DirectionType.Description; string location = GetSignalLocation(); string chartName = CreateFileName(); if (phase.PhaseNumber > 0) { GetChart(StartDate, EndDate, phase, location, FirstSecondsOfRed, ShowFailLines, ShowAvgLines, ShowPercentFailLines, YAxisMax, chartName, returnString, false); } if (approach.PermissivePhaseNumber != null && approach.PermissivePhaseNumber > 0) { string permChartName = CreateFileName(); MOE.Common.Business.CustomReport.Phase permPhase = new MOE.Common.Business.CustomReport.Phase(approach, StartDate, EndDate, new List <int> { 1, 4, 5, 6, 7, 8, 9, 10, 61, 63, 64 }, 1, true); permPhase.ApproachDirection = approach.DirectionType.Description; GetChart(StartDate, EndDate, permPhase, location, FirstSecondsOfRed, ShowFailLines, ShowAvgLines, ShowPercentFailLines, YAxisMax, permChartName, returnString, true); } } } return(returnString); }
private void CheckForLowDetectorHits(MOE.Common.Models.Signal signal) { List <MOE.Common.Models.Detector> detectors = signal.GetDetectorsForSignalThatSupportAMetric(6); //Parallel.ForEach(detectors, options, detector => foreach (MOE.Common.Models.Detector detector in detectors) { try { int channel = detector.DetChannel; string direction = detector.Approach.DirectionType.Description; DateTime start = new DateTime(); DateTime end = new DateTime(); if (Settings.WeekdayOnly && ScanDate.DayOfWeek == DayOfWeek.Monday) { start = ScanDate.AddDays(-3).Date.AddHours(Settings.PreviousDayPMPeakStart); end = ScanDate.AddDays(-3).Date.AddHours(Settings.PreviousDayPMPeakEnd); } else { start = ScanDate.AddDays(-1).Date.AddHours(Settings.PreviousDayPMPeakStart); end = ScanDate.AddDays(-1).Date.AddHours(Settings.PreviousDayPMPeakEnd); } int currentVolume = detector.GetVolumeForPeriod(start, end); //Compare collected hits to low hit threshold, if (currentVolume < Convert.ToInt32(Settings.LowHitThreshold)) { MOE.Common.Models.SPMWatchDogErrorEvent error = new MOE.Common.Models.SPMWatchDogErrorEvent(); error.SignalID = signal.SignalID; error.DetectorID = detector.DetectorID; error.Phase = detector.Approach.ProtectedPhaseNumber; error.TimeStamp = ScanDate; error.Direction = detector.Approach.DirectionType.Description; error.Message = "CH: " + channel.ToString() + " - Count: " + currentVolume.ToString(); error.ErrorCode = 2; if (!LowHitCountErrors.Contains(error)) { LowHitCountErrors.Add(error); } } } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository er = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); er.QuickAdd("SPMWatchDog", "Program", "CheckForLowDetectorHits", MOE.Common.Models.ApplicationEvent.SeverityLevels.Medium, detector.DetectorID + "-" + ex.Message); } } //); }
private static bool TestIPAddress(MOE.Common.Models.Signal Signal) { IPAddress ip; bool hasValidIP = true; hasValidIP = IPAddress.TryParse(Signal.IPAddress, out ip); if (Signal.IPAddress == "0") { hasValidIP = false; } //test to see if the address is reachable if (hasValidIP) { Ping pingSender = new Ping(); PingOptions pingOptions = new PingOptions(); // Use the default Ttl value which is 128, // but change the fragmentation behavior. pingOptions.DontFragment = true; // Create a buffer of 32 bytes of data to be transmitted. string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; byte[] buffer = Encoding.ASCII.GetBytes(data); int timeout = 120; PingReply reply = null; try { reply = pingSender.Send(Signal.IPAddress, timeout, buffer, pingOptions); if (reply.Status != IPStatus.Success) { var errorLog = ApplicationEventRepositoryFactory.Create(); errorLog.QuickAdd(System.Reflection.Assembly.GetExecutingAssembly().GetName().ToString(), "GetMaxTimeRecords", "TestIPAddress", ApplicationEvent.SeverityLevels.High, "Signal - " + Signal.SignalID + " IP Address - " + Signal.IPAddress + " - Invalid IP Address"); hasValidIP = false; } } catch (Exception e) { if (reply == null || reply.Status != IPStatus.Success) { var errorLog = ApplicationEventRepositoryFactory.Create(); errorLog.QuickAdd(System.Reflection.Assembly.GetExecutingAssembly().GetName().ToString(), "GetMaxTimeRecords", e.TargetSite.ToString(), ApplicationEvent.SeverityLevels.High, "Signal - " + Signal.SignalID + " IP Address - " + Signal.IPAddress + " - " + e.Message); hasValidIP = false; } } } return(hasValidIP); }
static private int FindChannel(string SignalID, int Phase) { MOE.Common.Models.Repositories.ISignalsRepository smh = MOE.Common.Models.Repositories.SignalsRepositoryFactory.Create(); MOE.Common.Models.Signal sig = smh.GetSignalBySignalID(SignalID); var dets = sig.GetDetectorsForSignalByPhaseNumber(Phase); if (dets.Count() > 0) { return(dets.FirstOrDefault().DetChannel); } else { return(0); } }
private void CheckForForceOff(MOE.Common.Business.AnalysisPhase phase, MOE.Common.Models.Signal signal) { if (phase.PercentForceOffs > Settings.PercentThreshold && phase.TerminationEvents.Where(t => t.EventCode != 7).Count() > Settings.MinPhaseTerminations) { MOE.Common.Models.SPMWatchDogErrorEvent error = new MOE.Common.Models.SPMWatchDogErrorEvent(); error.SignalID = signal.SignalID; error.Phase = phase.PhaseNumber; error.TimeStamp = ScanDate; error.Direction = phase.Direction ?? ""; error.Message = "Force Offs " + Math.Round(phase.PercentForceOffs * 100, 1).ToString() + "%"; error.ErrorCode = 4; if (!ForceOffErrors.Contains(error)) { ForceOffErrors.Add(error); } } }
static private string FindDetector(MOE.Common.Models.Signal Signal, int Channel) { try { MOE.Common.Models.Detector gd = Signal.GetDetectorForSignalByChannel(Channel); if (gd != null) { return(gd.DetectorID); } else { return("0"); } } catch { return("0"); } }
private void CheckForMaxOut(MOE.Common.Business.AnalysisPhase phase, MOE.Common.Models.Signal signal) { if (phase.PercentMaxOuts > Settings.PercentThreshold && phase.TotalPhaseTerminations > Settings.MinPhaseTerminations) { MOE.Common.Models.SPMWatchDogErrorEvent error = new MOE.Common.Models.SPMWatchDogErrorEvent(); error.SignalID = signal.SignalID; error.Phase = phase.PhaseNumber; error.TimeStamp = ScanDate; error.Direction = phase.Direction ?? ""; error.Message = "Max Outs " + Math.Round(phase.PercentMaxOuts * 100, 1).ToString() + "%"; error.ErrorCode = 5; if (MaxOutErrors.Count == 0 || !MaxOutErrors.Contains(error)) { Console.WriteLine("Signal " + signal.SignalID + "Has MaxOut Errors"); MaxOutErrors.Add(error); } } }
private void CheckForStuckPed(MOE.Common.Business.AnalysisPhase phase, MOE.Common.Models.Signal signal) { if (phase.PedestrianEvents.Count > Settings.MaximumPedestrianEvents) { MOE.Common.Models.SPMWatchDogErrorEvent error = new MOE.Common.Models.SPMWatchDogErrorEvent(); error.SignalID = signal.SignalID; error.Phase = phase.PhaseNumber; error.TimeStamp = ScanDate; error.Direction = phase.Direction ?? ""; error.Message = phase.PedestrianEvents.Count.ToString() + " Pedestrian Activations"; error.ErrorCode = 3; if (!StuckPedErrors.Contains(error)) { Console.WriteLine("Signal " + signal.SignalID + phase.PedestrianEvents.Count.ToString() + " Pedestrian Activations"); StuckPedErrors.Add(error); } } }
private void AddSelectListsToViewBag(MOE.Common.Models.Signal signal) { MOE.Common.Models.Repositories.IControllerTypeRepository controllerTypeRepository = MOE.Common.Models.Repositories.ControllerTypeRepositoryFactory.Create(); MOE.Common.Models.Repositories.IRegionsRepository regionRepository = MOE.Common.Models.Repositories.RegionsRepositoryFactory.Create(); MOE.Common.Models.Repositories.IDirectionTypeRepository directionTypeRepository = MOE.Common.Models.Repositories.DirectionTypeRepositoryFactory.Create(); MOE.Common.Models.Repositories.IMovementTypeRepository movementTypeRepository = MOE.Common.Models.Repositories.MovementTypeRepositoryFactory.Create(); MOE.Common.Models.Repositories.ILaneTypeRepository laneTypeRepository = MOE.Common.Models.Repositories.LaneTypeRepositoryFactory.Create(); MOE.Common.Models.Repositories.IDetectionHardwareRepository DetectionHardwareRepository = MOE.Common.Models.Repositories.DetectionHardwareRepositoryFactory.Create(); ViewBag.ControllerType = new SelectList(controllerTypeRepository.GetControllerTypes(), "ControllerTypeID", "Description", signal.ControllerTypeID); ViewBag.Region = new SelectList(regionRepository.GetAllRegions(), "ID", "Description", signal.RegionID); ViewBag.DirectionType = new SelectList(directionTypeRepository.GetAllDirections(), "DirectionTypeID", "Abbreviation"); ViewBag.MovementType = new SelectList(movementTypeRepository.GetAllMovementTypes(), "MovementTypeID", "Description"); ViewBag.LaneType = new SelectList(laneTypeRepository.GetAllLaneTypes(), "LaneTypeID", "Description"); ViewBag.DetectionHardware = new SelectList(DetectionHardwareRepository.GetAllDetectionHardwares(), "ID", "Name"); }
public Signal CopySignalToNewVersion(Signal originalVersion) { Common.Models.Signal newVersion = new Signal(); originalVersion.VersionAction = (from r in _db.VersionActions where r.ID == 4 select r).FirstOrDefault(); newVersion.VersionAction = (from r in _db.VersionActions where r.ID == 5 select r).FirstOrDefault(); newVersion.SignalID = originalVersion.SignalID; originalVersion.Start = DateTime.Today; newVersion.Start = DateTime.MaxValue; newVersion.Note = originalVersion.Note; newVersion.PrimaryName = originalVersion.PrimaryName; newVersion.SecondaryName = originalVersion.SecondaryName; newVersion.IPAddress = originalVersion.IPAddress; newVersion.ControllerTypeID = originalVersion.ControllerTypeID; newVersion.RegionID = originalVersion.RegionID; newVersion.Enabled = originalVersion.Enabled; newVersion.Latitude = originalVersion.Latitude; newVersion.Longitude = originalVersion.Longitude; newVersion.VersionID = (from r in _db.Signals select r.VersionID).Max() + 1; _db.Signals.Add(newVersion); //_db.SaveChanges(); CopyApproaches(originalVersion, newVersion); return(newVersion); }
public bool Equals(Signal signalToCompare) { return(CompareSignalProperties(signalToCompare)); }