public ConfigurationRecord(Models.Detector gd) { var gdr = DetectorRepositoryFactory.Create(); var dcr = DetectorCommentRepositoryFactory.Create(); var comment = ""; var c = dcr.GetMostRecentDetectorCommentByDetectorID(gd.ID); if (c != null) { comment = c.CommentText; } Comment = comment; DecisionPoint = gd.DecisionPoint.ToString(); DetectorChannel = gd.DetChannel.ToString(); DetectorID = gd.DetectorID; Direction = gd.Approach.DirectionType.Abbreviation; DistanceFromStopBar = gd.DistanceFromStopBar.ToString(); Enabled = gd.Approach.Signal.Enabled.ToString(); MinSpeedFilter = gd.MinSpeedFilter.ToString(); MovementDelay = gd.MovementDelay.ToString(); MPH = gd.Approach.MPH.ToString(); Overlap = gd.Approach.IsProtectedPhaseOverlap.ToString(); PermissivePhaseNumber = gd.Approach.PermissivePhaseNumber.ToString(); ProtectedPhaseNumber = gd.Approach.ProtectedPhaseNumber.ToString(); DetectionHardware = gd.DetectionHardware.Name; LatencyCorrection = gd.LatencyCorrection.ToString(); if (gd.LaneType != null) { LaneType = gd.LaneType.Description; } if (gd.LaneNumber != null) { LaneNumber = gd.LaneNumber.ToString(); } if (gd.MovementType != null) { MovementType = gd.MovementType.Description; } foreach (var dt in gd.DetectionTypes) { DetectionTypes += dt.Description + "<br/>"; } }
/// <summary> /// Default constructor for the Detector class use in the Turning Movement Count Charts /// </summary> /// <param name="detid"></param> /// <param name="signalid"></param> /// <param name="channelid"></param> /// <param name="laneid"></param> /// <param name="approachdirection"></param> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <param name="binsize"></param> public Detector(Models.Detector detector, DateTime startDate, DateTime endDate, int binsize) { DetID = detector.DetectorID; Channel = detector.DetChannel; Approach = detector.Approach; SignalID = detector.Approach.SignalID; LaneType = detector.LaneType; var celRepository = ControllerEventLogRepositoryFactory.Create(); var detectorEvents = new List <Controller_Event_Log>(); detectorEvents.AddRange(celRepository.GetEventsByEventCodesParam(detector.Approach.SignalID, startDate, endDate, new List <int> { 82 }, Channel)); Volumes = new VolumeCollection(startDate, endDate, detectorEvents, binsize); }
public Models.Detector GetDetectorForSignalByChannel(int detectorChannel) { Models.Detector returnDet = null; List <Models.Lane> laneGroups = GetLaneGroupsForSignal(); foreach (Models.Lane laneGroup in laneGroups) { foreach (Models.Detector det in laneGroup.Detectors) { if (det.DetChannel == detectorChannel) { returnDet = det; } } } return(returnDet); }
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); }
public Models.Detector GetDetectorForSignalByChannel(int detectorChannel) { Models.Detector returnDet = null; foreach (Models.Approach a in Approaches) { if (a.Detectors.Count > 0) { foreach (Models.Detector det in a.Detectors) { if (det.DetChannel == detectorChannel) { returnDet = det; } } } } return(returnDet); }
public static List <CycleSpeed> GetSpeedCycles(DateTime startDate, DateTime endDate, bool getPermissivePhase, Models.Detector detector) { var cycleEvents = GetCycleEvents(getPermissivePhase, startDate, endDate, detector.Approach, null); if (cycleEvents != null && cycleEvents.Count > 0 && GetEventType(cycleEvents.LastOrDefault().EventCode) != RedToRedCycle.EventType.ChangeToRed) { GetEventsToCompleteCycle(getPermissivePhase, endDate, detector.Approach, cycleEvents); } var cycles = new List <CycleSpeed>(); if (cycleEvents != null) { for (var i = 0; i < cycleEvents.Count; i++) { if (i < cycleEvents.Count - 3 && GetEventType(cycleEvents[i].EventCode) == RedToRedCycle.EventType.ChangeToRed && GetEventType(cycleEvents[i + 1].EventCode) == RedToRedCycle.EventType.ChangeToGreen && GetEventType(cycleEvents[i + 2].EventCode) == RedToRedCycle.EventType.ChangeToYellow && GetEventType(cycleEvents[i + 3].EventCode) == RedToRedCycle.EventType.ChangeToRed) { cycles.Add(new CycleSpeed(cycleEvents[i].Timestamp, cycleEvents[i + 1].Timestamp, cycleEvents[i + 2].Timestamp, cycleEvents[i + 3].Timestamp)); } } } if (cycles.Any()) { var speedEventRepository = SpeedEventRepositoryFactory.Create(); var speedEvents = speedEventRepository.GetSpeedEventsByDetector(startDate, cycles.LastOrDefault().EndTime, detector, detector.MinSpeedFilter ?? 5); foreach (var cycle in cycles) { cycle.FindSpeedEventsForCycle(speedEvents); } } return(cycles); }
public void Update(Models.Detector detector) { Models.Detector g = (from r in db.Detectors where r.ID == detector.ID select r).FirstOrDefault(); if (g != null) { foreach (int i in detector.DetectionTypeIDs) { Models.DetectionType t = (from r in db.DetectionTypes where r.DetectionTypeID == i select r).FirstOrDefault(); detector.DetectionTypes.Add(t); } try { db.Entry(g).CurrentValues.SetValues(detector); db.SaveChanges(); } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository repository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); MOE.Common.Models.ApplicationEvent error = new ApplicationEvent(); error.ApplicationName = "MOE.Common"; error.Class = "Models.Repository.DetectorRepository"; error.Function = "Update"; error.Description = ex.Message; error.SeverityLevel = ApplicationEvent.SeverityLevels.High; error.Timestamp = DateTime.Now; repository.Add(error); throw; } } }
//Método que valida si los mínimos y máximos detectados son puntos de quiebre //bajo tres criterios y calcular estadísticos public List <Models.Salida> ValidadordeSalida(List <Models.Detector> serieorgininalquiebres, List <Models.Detector> seriecorregidaquiebres, List <Models.DataSerie> resultado) { //CRITERIO 1 - AMPLITUD DEL CICLO DEBE SER MAYOR QUE MAS MENOS 15 PERIODOS // SUMA LOS VALORES DEL DETECTOR DE PUNTOS MÁXIMOS SU LA SUMA ES "1"/"-1" ENTONCES SE MARCA 1 (PICO/VALLE) // SI LA SUMA ES CUALQUIER NUMERO DIFERENTE DE "1"/"-1" ENTONCES MARCA 2 foreach (Models.Detector det in serieorgininalquiebres.Where(n => n.detectormax == 1)) { int indice = det.indice; if (indice >= 16) { int total = serieorgininalquiebres.Where(n => n.indice >= (indice - 15) && n.indice <= (indice + 15)).Sum(m => m.detectormax); if (total == 1) { det.criterioMax1 = 1; det.fase = "Pico"; } else { det.criterioMax1 = 2; det.fase = "Pico"; } } } foreach (Models.Detector det in serieorgininalquiebres.Where(n => n.detectormin == -1)) { int indice = det.indice; if (indice >= 16) { int total = serieorgininalquiebres.Where(n => n.indice >= (indice - 15) && n.indice <= (indice + 15)).Sum(m => m.detectormin); if (total == -1) { det.criterioMin1 = 1; det.fase = "Valle"; } else { det.criterioMin1 = 2; det.fase = "Valle"; } } } //foreach (Models.Detector d in seriecorregidaquiebres) //{ // d.indice = d.indice + 3; //} //for (int w = 0; w < 16; w++) //{ // Models.Detector detectorIni = new Models.Detector(); // detectorIni.mediamovil = null; // detectorIni.indice = w; // detectorIni.detectormax = 0; // detectorIni.detectormin = 0; // seriecorregidaquiebres.Insert(w, detectorIni); //} //CRITERIO 2 // SIMILITUD ENTRE LA CORREGIDA Y LA ORIGINAL // SE COMPARAN LOS QUIEBRES DE LA SERIE ORIGINAL CON LA SERIE CORREGIDA, SI SE ENCUENTRA UN QUIEBRE EN LA // CORREGIDA EN MENOS DE 5 PERIODOS DE LA ORIGINAL ENTONCES MARCA EL CRITERIO COMO 1 SI NO COMO 2 foreach (Models.Detector det in serieorgininalquiebres.Where(n => n.detectormax == 1 && n.criterioMax1 >= 1)) { int indice = det.indice; if (indice >= 6) { var criterio2 = seriecorregidaquiebres.Where(n => (n.indice >= (indice - 5) && n.indice <= (indice + 5)) && n.detectormax == 1).ToList(); if (criterio2.Count > 0) { det.criterio2 = 1; } else { det.criterio2 = 0; } } } foreach (Models.Detector det in serieorgininalquiebres.Where(n => n.detectormin == -1 && n.criterioMin1 >= 1)) { int indice = det.indice; if (indice >= 6) { var criterio2 = seriecorregidaquiebres.Where(n => (n.indice >= (indice - 5) && n.indice <= (indice + 5)) && n.detectormin == -1).ToList(); if (criterio2.Count > 0) { det.criterio2 = 1; } else { det.criterio2 = 0; } } } //CRITERIO 3 var listaCriterio3 = serieorgininalquiebres.Where(n => (n.detectormax == 1 && n.criterioMax1 >= 1 && n.criterio2 == 1) || (n.detectormin == -1 && n.criterioMin1 >= 1 && n.criterio2 == 1)).ToList(); bool primerElemento = true; Models.Detector tipoAnt = new Models.Detector(); Models.Detector tipo = new Models.Detector(); List <Models.Salida> salida = new List <Models.Salida>(); foreach (Models.Detector det3 in listaCriterio3) { Models.Salida osalida = new Models.Salida(); double?resCriterio3 = 0; double?crecMensual = 0; tipo = det3; if (primerElemento) { tipoAnt = det3; primerElemento = false; resCriterio3 = (tipo.mediamovil / serieorgininalquiebres[0].mediamovil) - 1; crecMensual = (((tipo.mediamovil / serieorgininalquiebres[0].mediamovil) - 1) / (tipo.indice - serieorgininalquiebres[0].indice)) * 100; if (resCriterio3 > (Algoritmo.desviaciontGlobal)) { det3.criterio3 = 1; } else { det3.criterio3 = 0; } osalida.cambioTotal = resCriterio3 * 100; osalida.cambioMensual = crecMensual; osalida.indice = det3.indice; osalida.fecha = det3.fecha; osalida.fase = det3.fase; salida.Add(osalida); } else { if (det3.detectormax == 1) { tipo = det3; if (tipoAnt.detectormin == -1) { resCriterio3 = (tipo.mediamovil / tipoAnt.mediamovil) - 1; crecMensual = (((tipo.mediamovil / tipoAnt.mediamovil) - 1) / (tipo.indice - tipoAnt.indice)) * 100; if (resCriterio3 > (Algoritmo.desviaciontGlobal)) { det3.criterio3 = 1; } else { det3.criterio3 = 0; } } osalida.cambioTotal = resCriterio3 * 100; osalida.cambioMensual = crecMensual; osalida.indice = det3.indice; osalida.fecha = det3.fecha; osalida.fase = det3.fase; salida.Add(osalida); tipoAnt = det3; } else if (det3.detectormin == -1) { tipo = det3; if (tipoAnt.detectormax == 1) { resCriterio3 = (tipo.mediamovil / tipoAnt.mediamovil) - 1; crecMensual = (((tipo.mediamovil / tipoAnt.mediamovil) - 1) / (tipo.indice - tipoAnt.indice)) * 100; if (resCriterio3 < (Algoritmo.desviaciontGlobal * -1)) { det3.criterio3 = 2; } else { det3.criterio3 = 0; } } osalida.cambioTotal = resCriterio3; osalida.cambioMensual = crecMensual; osalida.indice = det3.indice; osalida.fecha = det3.fecha; osalida.fase = det3.fase; salida.Add(osalida); tipoAnt = det3; } } } //CALCULAMOS LAS ESTADÍSTICAS PATRA IMPRIMIR EN LA TABLA //CALCULAMOS LA VARIANZA Y DURACIÓN DE LA FASE List <Models.Salida> salidavar = new List <Models.Salida>(); for (int k = 0; k < listaCriterio3.Count; k++) { if (k == 0) { Models.Detector finalv = listaCriterio3[k]; Models.Detector actualv = new Models.Detector(); actualv.indice = 0; Models.Salida var = new Models.Salida(); double?sumavar = 0; int observaciones = 0; double?media = 0; double?varianza = 0; double?ovarianza = 0; for (int l = actualv.indice; l < finalv.indice; l++) { sumavar += Convert.ToDouble(resultado[l].Data); observaciones = (finalv.indice - actualv.indice); media = sumavar / observaciones; } for (int l = actualv.indice; l < finalv.indice; l++) { ovarianza += (Convert.ToDouble(resultado[l].Data) - media) * (Convert.ToDouble(resultado[l].Data) - media); varianza = ovarianza / (observaciones - 1); } var.varianza = varianza; var.duracion = observaciones; var.fecha = listaCriterio3[k].fecha; salidavar.Add(var); } else { Models.Detector finalv = listaCriterio3[k]; Models.Detector actualv = listaCriterio3[k - 1]; Models.Salida var = new Models.Salida(); double?sumavar = 0; int observaciones = 0; double?media = 0; double?varianza = 0; double?ovarianza = 0; for (int l = actualv.indice; l < finalv.indice; l++) { sumavar += Convert.ToDouble(resultado[l].Data); observaciones = (finalv.indice - actualv.indice); media = sumavar / observaciones; } for (int l = actualv.indice; l < finalv.indice; l++) { ovarianza += (Convert.ToDouble(resultado[l].Data) - media) * (Convert.ToDouble(resultado[l].Data) - media); varianza = ovarianza / (observaciones - 1); } var.varianza = varianza; var.duracion = observaciones; var.fecha = listaCriterio3[k].fecha; salidavar.Add(var); } } List <Models.Salida> resumen = new List <Models.Salida>(); for (int i = 0; i < salidavar.Count; i++) { Models.Salida r = new Models.Salida(); r.cambioMensual = salida[i].cambioMensual; r.cambioTotal = salida[i].cambioTotal; r.duracion = salidavar[i].duracion; r.fecha = salida[i].fecha; r.varianza = salidavar[i].varianza; r.fase = salida[i].fase; r.indice = salida[i].indice; resumen.Add(r); } return(resumen); }
//Método que valida si los mínimos y máximos detectados son puntos de quiebre //bajo tres criterios y calcular estadísticos public List <Models.Salida> ValidadordeSalidaTrimestral(List <Models.Detector> serieorgininalquiebres, List <Models.Detector> seriecorregidaquiebres, List <Models.DataSerie> resultado) { //CRITERIO 1 foreach (Models.Detector det in serieorgininalquiebres.Where(n => n.detectormax == 1)) { int indice = det.indice; if (indice >= 6) { int total = serieorgininalquiebres.Where(n => n.indice >= (indice - 5) && n.indice <= (indice + 5)).Sum(m => m.detectormax); if (total == 1) { det.criterioMax1 = 1; det.fase = "Pico"; } else { det.criterioMax1 = 2; det.fase = "Pico"; } } } foreach (Models.Detector det in serieorgininalquiebres.Where(n => n.detectormin == -1)) { int indice = det.indice; if (indice >= 6) { int total = serieorgininalquiebres.Where(n => n.indice >= (indice - 5) && n.indice <= (indice + 5)).Sum(m => m.detectormin); if (total == -1) { det.criterioMin1 = 1; det.fase = "Valle"; } else { det.criterioMin1 = 2; det.fase = "Valle"; } } } //CRITERIO 2 //foreach (Models.Detector d in seriecorregidaquiebres) //{ // d.indice = d.indice + 3; //} //for (int w = 0; w < 6; w++) //{ // Models.Detector detectorIni = new Models.Detector(); // detectorIni.mediamovil = null; // detectorIni.indice = w; // detectorIni.detectormax = 0; // detectorIni.detectormin = 0; // seriecorregidaquiebres.Insert(w, detectorIni); //} foreach (Models.Detector det in serieorgininalquiebres.Where(n => n.detectormax == 1 && n.criterioMax1 >= 1)) { int indice = det.indice; if (indice >= 3) { var criterio2 = seriecorregidaquiebres.Where(n => (n.indice >= (indice - 2) && n.indice <= (indice + 2)) && n.detectormax == 1).ToList(); if (criterio2.Count > 0) { det.criterio2 = 1; } else { det.criterio2 = 0; } } } foreach (Models.Detector det in serieorgininalquiebres.Where(n => n.detectormin == -1 && n.criterioMin1 >= 1)) { int indice = det.indice; if (indice >= 3) { var criterio2 = seriecorregidaquiebres.Where(n => (n.indice >= (indice - 2) && n.indice <= (indice + 2)) && n.detectormin == -1).ToList(); if (criterio2.Count > 0) { det.criterio2 = 1; } else { det.criterio2 = 0; } } } //CRITERIO 3 var listaCriterio3 = serieorgininalquiebres.Where(n => (n.detectormax == 1 && n.criterioMax1 >= 1 && n.criterio2 == 1) || (n.detectormin == -1 && n.criterioMin1 >= 1 && n.criterio2 == 1)).ToList(); bool primerElemento = true; Models.Detector tipoAnt = new Models.Detector(); Models.Detector tipo = new Models.Detector(); List <Models.Salida> salida = new List <Models.Salida>(); foreach (Models.Detector det3 in listaCriterio3) { Models.Salida osalida = new Models.Salida(); double?resCriterio3 = 0; double?crecMensual = 0; tipo = det3; if (primerElemento) { tipoAnt = det3; primerElemento = false; resCriterio3 = (tipo.mediamovil / serieorgininalquiebres[0].mediamovil) - 1; crecMensual = (((tipo.mediamovil / serieorgininalquiebres[0].mediamovil) - 1) / (tipo.indice - serieorgininalquiebres[0].indice)) * 100; if (resCriterio3 > (Algoritmo.desviaciontGlobal)) { det3.criterio3 = 1; } else { det3.criterio3 = 0; } osalida.cambioTotal = resCriterio3 * 100; osalida.cambioMensual = crecMensual; osalida.indice = det3.indice; osalida.fecha = det3.fecha; osalida.fase = det3.fase; salida.Add(osalida); } else { if (det3.detectormax == 1) { tipo = det3; if (tipoAnt.detectormin == -1) { resCriterio3 = (tipo.mediamovil / tipoAnt.mediamovil) - 1; crecMensual = (((tipo.mediamovil / tipoAnt.mediamovil) - 1) / (tipo.indice - tipoAnt.indice)) * 100; if (resCriterio3 > (Algoritmo.desviaciontGlobal)) { det3.criterio3 = 1; } else { det3.criterio3 = 0; } } osalida.cambioTotal = resCriterio3 * 100; osalida.cambioMensual = crecMensual; osalida.indice = det3.indice; osalida.fecha = det3.fecha; osalida.fase = det3.fase; salida.Add(osalida); tipoAnt = det3; } else if (det3.detectormin == -1) { tipo = det3; if (tipoAnt.detectormax == 1) { resCriterio3 = (tipo.mediamovil / tipoAnt.mediamovil) - 1; crecMensual = (((tipo.mediamovil / tipoAnt.mediamovil) - 1) / (tipo.indice - tipoAnt.indice)) * 100; if (resCriterio3 < (Algoritmo.desviaciontGlobal * -1)) { det3.criterio3 = 2; } else { det3.criterio3 = 0; } } osalida.cambioTotal = resCriterio3; osalida.cambioMensual = crecMensual; osalida.indice = det3.indice; osalida.fecha = det3.fecha; osalida.fase = det3.fase; salida.Add(osalida); tipoAnt = det3; } } } //CALCULAMOS LAS ESTADÍSTICAS PATRA IMPRIMIR EN LA TABLA //CALCULAMOS LA VARIANZA Y DURACIÓN DE LA FASE List <Models.Salida> salidavar = new List <Models.Salida>(); for (int k = 0; k < listaCriterio3.Count; k++) { if (k == 0) { Models.Detector finalv = listaCriterio3[k]; Models.Detector actualv = new Models.Detector(); actualv.indice = 0; Models.Salida var = new Models.Salida(); double?sumavar = 0; int observaciones = 0; double?media = 0; double?varianza = 0; double?ovarianza = 0; for (int l = actualv.indice; l < finalv.indice; l++) { sumavar += Convert.ToDouble(resultado[l].Data); observaciones = (finalv.indice - actualv.indice); media = sumavar / observaciones; } for (int l = actualv.indice; l < finalv.indice; l++) { ovarianza += (Convert.ToDouble(resultado[l].Data) - media) * (Convert.ToDouble(resultado[l].Data) - media); varianza = ovarianza / (observaciones - 1); } var.varianza = varianza; var.duracion = observaciones; var.fecha = listaCriterio3[k].fecha; salidavar.Add(var); } else { Models.Detector finalv = listaCriterio3[k]; Models.Detector actualv = listaCriterio3[k - 1]; Models.Salida var = new Models.Salida(); double?sumavar = 0; int observaciones = 0; double?media = 0; double?varianza = 0; double?ovarianza = 0; for (int l = actualv.indice; l < finalv.indice; l++) { sumavar += Convert.ToDouble(resultado[l].Data); observaciones = (finalv.indice - actualv.indice); media = sumavar / observaciones; } for (int l = actualv.indice; l < finalv.indice; l++) { ovarianza += (Convert.ToDouble(resultado[l].Data) - media) * (Convert.ToDouble(resultado[l].Data) - media); varianza = ovarianza / (observaciones - 1); } var.varianza = varianza; var.duracion = observaciones; var.fecha = listaCriterio3[k].fecha; salidavar.Add(var); } } List <Models.Salida> resumen = new List <Models.Salida>(); for (int i = 0; i < salidavar.Count; i++) { Models.Salida r = new Models.Salida(); r.cambioMensual = salida[i].cambioMensual; r.cambioTotal = salida[i].cambioTotal; r.duracion = salidavar[i].duracion; r.fecha = salida[i].fecha; r.varianza = salidavar[i].varianza; r.fase = salida[i].fase; r.indice = salida[i].indice; resumen.Add(r); } return(resumen); }
public List <Models.Detector> DetectordeQuiebresTrimestral(List <Models.DataSerie> resultado) { //PROCESO PARA DETECTAR LOS PUNTOS DE QUIEBRE EN List <Models.Detector> seriemediamovilminmax = new List <Models.Detector>(); List <Models.Detector> seriemediamovilminmaxtot = new List <Models.Detector>(); for (int i = 4; i < ((resultado.Count) - 4); i++) { seriemediamovilminmax = new List <Models.Detector>(); Models.Detector detector = new Models.Detector(); for (int x = 4; x > 0; x--) { detector = new Models.Detector(); detector.mediamovil = Convert.ToDouble(resultado[i - x].Data); detector.fecha = Convert.ToDateTime(resultado[i - x].Date); detector.indice = i - x; seriemediamovilminmax.Add(detector); } detector = new Models.Detector(); detector.mediamovil = Convert.ToDouble(resultado[i].Data); detector.fecha = Convert.ToDateTime(resultado[i].Date); detector.indice = i; seriemediamovilminmax.Add(detector); seriemediamovilminmaxtot.Add(detector); for (int x = 1; x < 5; x++) { detector = new Models.Detector(); detector.mediamovil = Convert.ToDouble(resultado[i + x].Data); detector.fecha = Convert.ToDateTime(resultado[i + x].Date); detector.indice = i + x; seriemediamovilminmax.Add(detector); } double?maximo = seriemediamovilminmax.Max(z => z.mediamovil).Value; if (maximo != null) { if (Convert.ToDouble(resultado[i].Data) == maximo) { seriemediamovilminmaxtot.Last().detectormax = 1; } } double?minimo = seriemediamovilminmax.Min(z => z.mediamovil).Value; if (minimo != null) { if (Convert.ToDouble(resultado[i].Data) == minimo) { seriemediamovilminmaxtot.Last().detectormin = -1; } } } return(seriemediamovilminmaxtot); }
/// <summary> /// 设置检测器,在哪个位置都有不同的定义 /// 1、路口最外面的是 战略 /// 2、路口外到内 第二个是感应 /// 3、路口外到内 第三个是战术 /// 4、路口 外到内第四个是请求 /// </summary> /// <param name="i"></param> /// <param name="direc"></param> /// <param name="type"></param> public void SetDetector(int i ,byte direc,int type) { tscui.Models.Detector d = new Models.Detector(); t = Utils.Utils.GetTscDataByApplicationCurrentProperties(); bool newDetector = true; List<Models.Detector> ld = t.ListDetector; foreach (Models.Detector det in ld) { if (det.ucDetectorId == i) { det.ucDetectorId = Convert.ToByte(i); //det.ucDetFlag = GetDetFlag(type,direc); det.ucDirect = GetDirecByte(direc); //det.ucOptionFlag = GetOptionByCheckbox(); det.ucPhaseId = GetPhaseIdByDirec(direc); // det.ucSaturationOccupy = d.ucSaturationOccupy; //det.ucValidTime = Convert.ToByte(tbkVaildTime.Text); //det.usSaturationFlow = d.usSaturationFlow; newDetector = false; break; } } if (newDetector == true) { d.ucDetectorId = Convert.ToByte(i); d.ucPhaseId = GetPhaseIdByDirec(direc); d.ucDetFlag = GetDetFlag(type,direc); d.ucDirect = GetDirecByte(direc); d.ucValidTime = Convert.ToByte(tbkVaildTime.Text); d.ucOptionFlag = GetOptionByCheckbox(); d.usSaturationFlow = 0; d.ucSaturationOccupy = 0; newDetector = true; ld.Add(d); } }
protected List <DetectorEventCountAggregation> GetdetectorEventCountAggregations(DetectorAggregationMetricOptions options, Models.Detector detector) { var detectorEventCountAggregationRepository = MOE.Common.Models.Repositories.DetectorEventCountAggregationRepositoryFactory.Create(); return (detectorEventCountAggregationRepository.GetDetectorEventCountAggregationByDetectorIdAndDateRange( Detector.ID, options.StartDate, options.EndDate)); }
protected void AddSpeedDataToChart(Chart chart, Models.Detector detector, DateTime startDate, DateTime endDate, int binSize) { decimal totalDetectorHits = 0; decimal totalOnGreenArrivals = 0; decimal percentArrivalOnGreen = 0; Models.SPM db = new SPM(); List <Models.Speed_Events> SpeedHitsForChart = (from r in db.Speed_Events where r.timestamp > startDate && r.timestamp < endDate && r.DetectorID == detector.DetectorID select r).ToList(); MOE.Common.Models.Repositories.IControllerEventLogRepository CLR = Models.Repositories.ControllerEventLogRepositoryFactory.Create(); List <Models.Controller_Event_Log> phaseevents = CLR.GetEventsByEventCodesParam(detector.Approach.SignalID, StartDate, EndDate, new List <int>() { 0, 1, 7, 8, 9, 10, 11 }, detector.Approach.ProtectedPhaseNumber); List <Models.Controller_Event_Log> detEvents = new List <Controller_Event_Log>(); List <Models.Controller_Event_Log> preemptEvents = new List <Controller_Event_Log>(); PlanCollection Plans = new PlanCollection(phaseevents, detEvents, StartDate, EndDate, detector.Approach, preemptEvents); foreach (MOE.Common.Business.Plan plan in Plans.PlanList) { foreach (Cycle c in plan.CycleCollection) { c.FindSpeedEventsForCycle(SpeedHitsForChart); } plan.AvgSpeedBucketCollection = new AvgSpeedBucketCollection(plan.StartTime, plan.EndTime, plan.CycleCollection, binSize, detector.MinSpeedFilter ?? 5, detector.MovementDelay ?? 0); if (plan.AvgSpeedBucketCollection.Items.Count > 0) { foreach (MOE.Common.Business.AvgSpeedBucket bucket in plan.AvgSpeedBucketCollection.Items) { chart.Series["Average MPH"].Points.AddXY(bucket.StartTime, bucket.AvgSpeed); chart.Series["85th Percentile Speed"].Points.AddXY(bucket.StartTime, bucket.EightyFifth); if (ShowPlanStatistics && ShowPostedSpeed) { chart.Series["Posted Speed"].Points.AddXY(bucket.StartTime, detector.Approach.MPH); } } } } //if arrivals on green is selected add the data to the chart if (ShowPlanStatistics) { if (totalDetectorHits > 0) { percentArrivalOnGreen = (totalOnGreenArrivals / totalDetectorHits) * 100; } else { percentArrivalOnGreen = 0; } SetSpeedPlanStrips(Plans, chart, startDate, detector.MinSpeedFilter ?? 0); } }
private static void AddDetectorOnToBeginningIfNecessary(SplitFailOptions options, Models.Detector detector, List <Controller_Event_Log> events) { if (events.FirstOrDefault()?.EventCode == 81) { events.Insert(0, new Controller_Event_Log { Timestamp = options.StartDate, EventCode = 82, EventParam = detector.DetChannel, SignalID = options.SignalID }); } }
protected abstract void LoadBins(Models.Detector detector, DetectorAggregationMetricOptions options);
private Chart GetNewSpeedChart(Models.Detector detector) { var chart = new Chart(); ChartFactory.SetImageProperties(chart); //Set the chart title SetChartTitles(chart, detector); //Create the chart legend var chartLegend = new Legend(); chartLegend.Name = "MainLegend"; chartLegend.Docking = Docking.Left; chart.Legends.Add(chartLegend); //Create the chart area var chartArea = new ChartArea(); chartArea.Name = "ChartArea1"; if (YAxisMax > 0) { chartArea.AxisY.Maximum = YAxisMax.Value; } else { chartArea.AxisY.Maximum = 60; } if (YAxisMin > 0) { chartArea.AxisY.Minimum = YAxisMin; } else { chartArea.AxisY.Minimum = 0; } chartArea.AxisY.Title = "Average Speed"; chartArea.AxisX.Title = "Time (Hour of Day)"; chartArea.AxisX.Interval = 1; chartArea.AxisX.IntervalType = DateTimeIntervalType.Hours; chartArea.AxisX.LabelStyle.Format = "HH"; chartArea.AxisX2.Enabled = AxisEnabled.True; chartArea.AxisX2.MajorTickMark.Enabled = true; chartArea.AxisX2.IntervalType = DateTimeIntervalType.Hours; chartArea.AxisX2.LabelStyle.Format = "HH"; chartArea.AxisX2.LabelAutoFitStyle = LabelAutoFitStyles.None; chartArea.AxisX2.Interval = 1; chartArea.AxisY.Title = "MPH"; chartArea.AxisY.IntervalAutoMode = IntervalAutoMode.FixedCount; chartArea.AxisY.Interval = 5; chartArea.AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dot; chart.ChartAreas.Add(chartArea); if (ShowAverageSpeed) { var averageSeries = new Series(); averageSeries.ChartType = SeriesChartType.Line; averageSeries.Color = Color.Red; averageSeries.Name = "Average MPH"; averageSeries.XValueType = ChartValueType.DateTime; chart.Series.Add(averageSeries); } if (Show85Percentile) { var eightyFifthSeries = new Series(); eightyFifthSeries.ChartType = SeriesChartType.Line; eightyFifthSeries.Color = Color.Blue; eightyFifthSeries.Name = "85th Percentile Speed"; eightyFifthSeries.XValueType = ChartValueType.DateTime; chart.Series.Add(eightyFifthSeries); } if (Show15Percentile) { var fifteenthSeries = new Series(); fifteenthSeries.ChartType = SeriesChartType.Line; fifteenthSeries.Color = Color.Black; fifteenthSeries.Name = "15th Percentile Speed"; fifteenthSeries.XValueType = ChartValueType.DateTime; chart.Series.Add(fifteenthSeries); } if (ShowPostedSpeed) { var postedspeedSeries = new Series(); postedspeedSeries.ChartType = SeriesChartType.Line; postedspeedSeries.Color = Color.DarkGreen; postedspeedSeries.Name = "Posted Speed"; postedspeedSeries.BorderWidth = 2; chart.Series.Add(postedspeedSeries); } return(chart); }
private Chart GetNewSpeedChart(Models.Detector detector) { var chart = ChartFactory.CreateDefaultChart(this); ChartFactory.SetImageProperties(chart); //Set the chart title SetChartTitles(chart, detector); //Create the chart legend var chartLegend = new Legend(); chartLegend.Name = "MainLegend"; chartLegend.Docking = Docking.Left; chart.Legends.Add(chartLegend); //Create the chart area if (YAxisMax > 0) { chart.ChartAreas[0].AxisY.Maximum = YAxisMax.Value; } else { chart.ChartAreas[0].AxisY.Maximum = 60; } if (YAxisMin > 0) { chart.ChartAreas[0].AxisY.Minimum = YAxisMin; } else { chart.ChartAreas[0].AxisY.Minimum = 0; } chart.ChartAreas[0].AxisY.Title = "Average Speed"; chart.ChartAreas[0].AxisY.Title = "MPH"; chart.ChartAreas[0].AxisY.IntervalAutoMode = IntervalAutoMode.FixedCount; chart.ChartAreas[0].AxisY.Interval = 5; chart.ChartAreas[0].AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dot; if (ShowAverageSpeed) { var averageSeries = new Series(); averageSeries.ChartType = SeriesChartType.Line; averageSeries.Color = Color.Red; averageSeries.Name = "Average MPH"; averageSeries.XValueType = ChartValueType.DateTime; chart.Series.Add(averageSeries); } if (Show85Percentile) { var eightyFifthSeries = new Series(); eightyFifthSeries.ChartType = SeriesChartType.Line; eightyFifthSeries.Color = Color.Blue; eightyFifthSeries.Name = "85th Percentile Speed"; eightyFifthSeries.XValueType = ChartValueType.DateTime; chart.Series.Add(eightyFifthSeries); } if (Show15Percentile) { var fifteenthSeries = new Series(); fifteenthSeries.ChartType = SeriesChartType.Line; fifteenthSeries.Color = Color.Black; fifteenthSeries.Name = "15th Percentile Speed"; fifteenthSeries.XValueType = ChartValueType.DateTime; chart.Series.Add(fifteenthSeries); } if (ShowPostedSpeed) { var postedspeedSeries = new Series(); postedspeedSeries.ChartType = SeriesChartType.Line; postedspeedSeries.Color = Color.DarkGreen; postedspeedSeries.Name = "Posted Speed"; postedspeedSeries.BorderWidth = 2; chart.Series.Add(postedspeedSeries); } return(chart); }
public void GetDetectorList() { Console.WriteLine("Converting Detectors"); DetectorConverters = new List <DetectorConverter>(); foreach (MOE.Common.Data.Signals.Graph_DetectorsRow row in DetectorsTable) { List <MOE.Common.Models.DetectionType> detectionstypeslist = (from r in db.DetectionTypes select r).ToList(); if (!row.IsNull("Phase") || row.Phase != "0" || row.Phase != "" || row.Det_Channel != 0) { DetectorConverter dc = new DetectorConverter(); Models.Detector d = new Models.Detector(); if (!row.IsNull("DateAdded")) { d.DateAdded = row.Date_Added; } else { d.DateAdded = DateTime.Now; } d.DetChannel = row.Det_Channel; d.DetectorID = row.DetectorID; if (!row.IsNull("DistanceFromStopBar")) { d.DistanceFromStopBar = row.DistanceFromStopBar; } else { d.DistanceFromStopBar = 0; } if (!row.IsNull("MinSpeedFilter")) { d.MinSpeedFilter = row.Min_Speed_Filter; } else { d.MinSpeedFilter = 0; } if (d.DetectionTypes == null && d.DetectionTypeIDs == null) { d.DetectionTypeIDs = new List <int>(); d.DetectionTypes = new List <MOE.Common.Models.DetectionType>(); } if (!row.IsNull("Has_PCD") && row.Has_PCD) { MOE.Common.Models.DetectionType dettype = (from r in detectionstypeslist where r.DetectionTypeID == 2 select r).FirstOrDefault(); d.DetectionTypes.Add(dettype); d.DetectionTypeIDs.Add(dettype.DetectionTypeID); } if (!row.IsNull("Has_Speed_Detector") && row.Has_Speed_Detector) { MOE.Common.Models.DetectionType dettype = (from r in detectionstypeslist where r.DetectionTypeID == 3 select r).FirstOrDefault(); d.DetectionTypes.Add(dettype); d.DetectionTypeIDs.Add(dettype.DetectionTypeID); } if (!row.IsNull("Has_SplitFail") && row.Has_SplitFail) { MOE.Common.Models.DetectionType dettype = (from r in detectionstypeslist where r.DetectionTypeID == 4 select r).FirstOrDefault(); d.DetectionTypes.Add(dettype); d.DetectionTypeIDs.Add(dettype.DetectionTypeID); } if (!row.IsNull("Has_RLM") && row.Has_RLM) { MOE.Common.Models.DetectionType dettype = (from r in detectionstypeslist where r.DetectionTypeID == 5 select r).FirstOrDefault(); d.DetectionTypes.Add(dettype); d.DetectionTypeIDs.Add(dettype.DetectionTypeID); } if (!row.IsNull("Has_TMC") && row.Has_TMC) { MOE.Common.Models.DetectionType dettype = (from r in detectionstypeslist where r.DetectionTypeID == 6 select r).FirstOrDefault(); d.DetectionTypes.Add(dettype); d.DetectionTypeIDs.Add(dettype.DetectionTypeID); } if (!row.IsNull("Direction") && row.Direction.ToString() != "") { switch (row.Direction.ToString()) { case "Northbound": dc.DirectionTypeID = 1; break; case "Southbound": dc.DirectionTypeID = 2; break; case "Eastbound": dc.DirectionTypeID = 3; break; case "Westbound": dc.DirectionTypeID = 4; break; } } if (!row.IsNull("MovementDelay")) { dc.MovementDelay = row.Movement_Delay; } else { dc.MovementDelay = 0; } if (!row.IsNull("MPH")) { dc.MPH = row.MPH; } else { dc.MPH = 0; } if (!row.IsNull("TMC_Lane_Type") && row.TMC_Lane_Type != "") { switch (row.TMC_Lane_Type) { case "L1": dc.LaneNumber = 1; dc.LaneTypeID = 1; dc.MovementTypeID = 3; break; case "L2": dc.LaneNumber = 2; dc.LaneTypeID = 1; dc.MovementTypeID = 3; break; case "L3": dc.LaneNumber = 3; dc.LaneTypeID = 1; dc.MovementTypeID = 3; break; case "L4": dc.LaneNumber = 4; dc.LaneTypeID = 1; dc.MovementTypeID = 3; break; case "R1": dc.LaneNumber = 1; dc.LaneTypeID = 1; dc.MovementTypeID = 2; break; case "R2": dc.LaneNumber = 2; dc.LaneTypeID = 1; dc.MovementTypeID = 2; break; case "R3": dc.LaneNumber = 3; dc.LaneTypeID = 1; dc.MovementTypeID = 2; break; case "R4": dc.LaneNumber = 4; dc.LaneTypeID = 1; dc.MovementTypeID = 2; break; case "T1": dc.LaneNumber = 1; dc.LaneTypeID = 1; dc.MovementTypeID = 1; break; case "T2": dc.LaneNumber = 2; dc.LaneTypeID = 1; dc.MovementTypeID = 1; break; case "T3": dc.LaneNumber = 3; dc.LaneTypeID = 1; dc.MovementTypeID = 1; break; case "T4": dc.LaneNumber = 4; dc.LaneTypeID = 1; dc.MovementTypeID = 1; break; case "TL1": dc.LaneNumber = 1; dc.LaneTypeID = 1; dc.MovementTypeID = 5; break; case "TR1": dc.LaneNumber = 1; dc.LaneTypeID = 1; dc.MovementTypeID = 4; break; case "T1E": dc.LaneNumber = 1; dc.LaneTypeID = 4; dc.MovementTypeID = 1; break; case "T2E": dc.LaneNumber = 2; dc.LaneTypeID = 4; dc.MovementTypeID = 1; break; case "T3E": dc.LaneNumber = 3; dc.LaneTypeID = 4; dc.MovementTypeID = 1; break; case "T4E": dc.LaneNumber = 4; dc.LaneTypeID = 4; dc.MovementTypeID = 1; break; case "L1B": dc.LaneNumber = 1; dc.LaneTypeID = 2; dc.MovementTypeID = 3; break; case "T1B": dc.LaneNumber = 1; dc.LaneTypeID = 2; dc.MovementTypeID = 1; break; case "R1B": dc.LaneNumber = 1; dc.LaneTypeID = 2; dc.MovementTypeID = 2; break; case "PED": dc.LaneNumber = 1; dc.LaneTypeID = 3; dc.MovementTypeID = 1; break; } } else { dc.LaneNumber = 1; dc.LaneTypeID = 1; dc.MovementTypeID = 1; } if (dc.LaneNumber == 0) { dc.LaneNumber = 1; } if (dc.LaneTypeID == 0) { dc.LaneTypeID = 1; } if (dc.MovementTypeID == 0) { dc.MovementTypeID = 1; } if (!row.IsNull("Perm_Phase") && row.Perm_Phase != "0" && row.Perm_Phase != "") { dc.PermissivePhase = Convert.ToInt32(row.Phase); } if (!row.IsNull("Is_Overlap") && row.Is_Overlap) { dc.IsOverlap = row.Is_Overlap; } dc.ProtectedPhase = Convert.ToInt32(row.Phase); dc.GraphDetectorModel = d; dc.SignalID = row.SignalID; DetectorConverters.Add(dc); } } }
private void SetLaneInfo(Data.Signals.Graph_DetectorsRow row, Models.Detector detector) { switch (row.TMC_Lane_Type) { case "L1": detector.LaneNumber = 1; detector.LaneTypeID = 1; detector.MovementTypeID = 3; break; case "L2": detector.LaneNumber = 2; detector.LaneTypeID = 1; detector.MovementTypeID = 3; break; case "L3": detector.LaneNumber = 3; detector.LaneTypeID = 1; detector.MovementTypeID = 3; break; case "L4": detector.LaneNumber = 4; detector.LaneTypeID = 1; detector.MovementTypeID = 3; break; case "R1": detector.LaneNumber = 1; detector.LaneTypeID = 1; detector.MovementTypeID = 2; break; case "R2": detector.LaneNumber = 2; detector.LaneTypeID = 1; detector.MovementTypeID = 2; break; case "R3": detector.LaneNumber = 3; detector.LaneTypeID = 1; detector.MovementTypeID = 2; break; case "R4": detector.LaneNumber = 4; detector.LaneTypeID = 1; detector.MovementTypeID = 2; break; case "T1": detector.LaneNumber = 1; detector.LaneTypeID = 1; detector.MovementTypeID = 1; break; case "T2": detector.LaneNumber = 2; detector.LaneTypeID = 1; detector.MovementTypeID = 1; break; case "T3": detector.LaneNumber = 3; detector.LaneTypeID = 1; detector.MovementTypeID = 1; break; case "T4": detector.LaneNumber = 4; detector.LaneTypeID = 1; detector.MovementTypeID = 1; break; case "TL1": detector.LaneNumber = 1; detector.LaneTypeID = 1; detector.MovementTypeID = 5; break; case "TR1": detector.LaneNumber = 1; detector.LaneTypeID = 1; detector.MovementTypeID = 4; break; case "T1E": detector.LaneNumber = 1; detector.LaneTypeID = 4; detector.MovementTypeID = 1; break; case "T2E": detector.LaneNumber = 2; detector.LaneTypeID = 4; detector.MovementTypeID = 1; break; case "T3E": detector.LaneNumber = 3; detector.LaneTypeID = 4; detector.MovementTypeID = 1; break; case "T4E": detector.LaneNumber = 4; detector.LaneTypeID = 4; detector.MovementTypeID = 1; break; case "L1B": detector.LaneNumber = 1; detector.LaneTypeID = 2; detector.MovementTypeID = 3; break; case "T1B": detector.LaneNumber = 1; detector.LaneTypeID = 2; detector.MovementTypeID = 1; break; case "R1B": detector.LaneNumber = 1; detector.LaneTypeID = 2; detector.MovementTypeID = 2; break; case "PED": detector.LaneNumber = 1; detector.LaneTypeID = 3; detector.MovementTypeID = 1; break; } if (detector.LaneNumber == null) { if (!String.IsNullOrEmpty(row.Lane) && (String.Compare(row.Lane.ToUpper(), "NULL") != 0)) { detector.LaneNumber = Convert.ToInt32(row.Lane); detector.LaneTypeID = 1; detector.MovementTypeID = 1; } if (detector.LaneNumber == null) { detector.LaneNumber = 1; detector.LaneTypeID = 1; detector.MovementTypeID = 1; } } }
private bool IsThruDetector(Models.Detector detector) { return(detector.MovementTypeID == 1 || detector.MovementTypeID == 2 || detector.MovementTypeID == 4 || detector.MovementTypeID == 5); }
protected override List <BinsContainer> GetBinsContainersByDetector(Models.Detector detector) { var detectorAggregationByDetector = new DetectorAggregationByDetector(detector, this); return(detectorAggregationByDetector.BinsContainers); }
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); }
public DetectorAggregationByDetector(Models.Detector detector, DetectorVolumeAggregationOptions options) : base( detector, options) { }
protected override void LoadBins(Models.Detector detector, DetectorAggregationMetricOptions options) { var detectorAggregationRepository = DetectorAggregationsRepositoryFactory.Create(); var detectorAggregations = detectorAggregationRepository.GetDetectorAggregationByApproachIdAndDateRange( detector.ID, options.StartDate, options.EndDate); if (detectorAggregations != null) { var concurrentBinContainers = new ConcurrentBag <BinsContainer>(); //foreach (var binsContainer in binsContainers) Parallel.ForEach(BinsContainers, binsContainer => { var tempBinsContainer = new BinsContainer(binsContainer.Start, binsContainer.End); var concurrentBins = new ConcurrentBag <Bin>(); //foreach (var bin in binsContainer.Bins) Parallel.ForEach(binsContainer.Bins, bin => { if (detectorAggregations.Any(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End)) { var volume = 0; switch (options.SelectedAggregatedDataType.DataName) { case "DetectorActivationCount": volume = detectorAggregations.Where(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End) .Sum(s => s.Volume); break; default: throw new Exception("Unknown Aggregate Data Type for Split Failure"); } concurrentBins.Add(new Bin { Start = bin.Start, End = bin.End, Sum = volume, Average = volume }); } else { concurrentBins.Add(new Bin { Start = bin.Start, End = bin.End, Sum = 0, Average = 0 }); } }); tempBinsContainer.Bins = concurrentBins.OrderBy(c => c.Start).ToList(); concurrentBinContainers.Add(tempBinsContainer); }); BinsContainers = concurrentBinContainers.OrderBy(b => b.Start).ToList(); } }
private void CheckForDetectorOnBeforeStart(SplitFailOptions options, IControllerEventLogRepository controllerEventsRepository, Models.Detector detector) { var eventOnBeforeStart = controllerEventsRepository.GetFirstEventBeforeDateByEventCodeAndParameter( options.SignalID, detector.DetChannel, 81, options.StartDate); var eventOffBeforeStart = controllerEventsRepository.GetFirstEventBeforeDateByEventCodeAndParameter( options.SignalID, detector.DetChannel, 82, options.StartDate); if (eventOnBeforeStart != null && eventOffBeforeStart == null) { _detectorActivations.Add(new SplitFailDetectorActivation { DetectorOn = options.StartDate, DetectorOff = options.EndDate }); } }
private Chart GetNewSpeedChart(string location, Models.Detector detector) { Chart chart = new Chart(); //Set the chart properties chart.ImageType = ChartImageType.Jpeg; chart.Height = 550; chart.Width = 1100; chart.ImageStorageMode = ImageStorageMode.UseImageLocation; //Set the chart title SetChartTitles(chart, detector); //Create the chart legend Legend chartLegend = new Legend(); chartLegend.Name = "MainLegend"; chartLegend.Docking = Docking.Left; chart.Legends.Add(chartLegend); //Create the chart area ChartArea chartArea = new ChartArea(); chartArea.Name = "ChartArea1"; if (YAxisMax > 0) { chartArea.AxisY.Maximum = YAxisMax.Value; } else { chartArea.AxisY.Maximum = 60; } if (Y2AxisMax != null && Y2AxisMax > 0) { chartArea.AxisY.Minimum = Y2AxisMax.Value; } else { chartArea.AxisY.Minimum = 20; } chartArea.AxisY.Title = "Average Speed"; chartArea.AxisX.Title = "Time (Hour of Day)"; chartArea.AxisX.Interval = 1; chartArea.AxisX.IntervalType = DateTimeIntervalType.Hours; chartArea.AxisX.LabelStyle.Format = "HH"; chartArea.AxisX2.Enabled = AxisEnabled.True; chartArea.AxisX2.MajorTickMark.Enabled = true; chartArea.AxisX2.IntervalType = DateTimeIntervalType.Hours; chartArea.AxisX2.LabelStyle.Format = "HH"; chartArea.AxisX2.LabelAutoFitStyle = LabelAutoFitStyles.None; chartArea.AxisX2.Interval = 1; chartArea.AxisY.Title = "MPH"; chartArea.AxisY.IntervalAutoMode = IntervalAutoMode.FixedCount; chartArea.AxisY.Interval = 5; chartArea.AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dot; chart.ChartAreas.Add(chartArea); //Add the point series Series pointSeries = new Series(); pointSeries.ChartType = SeriesChartType.Line; pointSeries.Color = Color.Red; pointSeries.Name = "Average MPH"; pointSeries.XValueType = ChartValueType.DateTime; //pointSeries.MarkerSize = Convert.ToInt32(uxDotSizeDropDownList.SelectedValue); Series eightyFifthSeries = new Series(); eightyFifthSeries.ChartType = SeriesChartType.Line; eightyFifthSeries.Color = Color.Blue; eightyFifthSeries.Name = "85th Percentile Speed"; eightyFifthSeries.XValueType = ChartValueType.DateTime; //pointSeries.MarkerSize = Convert.ToInt32(uxDotSizeDropDownList.SelectedValue); //Add the Posted Speed series Series postedspeedSeries = new Series(); postedspeedSeries.ChartType = SeriesChartType.Line; postedspeedSeries.Color = Color.DarkGreen; postedspeedSeries.Name = "Posted Speed"; //greenSeries.XValueType = ChartValueType.DateTime; postedspeedSeries.BorderWidth = 2; chart.Series.Add(postedspeedSeries); chart.Series.Add(eightyFifthSeries); chart.Series.Add(pointSeries); //Add the Posts series to ensure the chart is the size of the selected timespan Series testSeries = new Series(); testSeries.IsVisibleInLegend = false; testSeries.ChartType = SeriesChartType.Point; testSeries.Color = Color.White; testSeries.Name = "Posts"; testSeries.XValueType = ChartValueType.DateTime; pointSeries.MarkerSize = 0; chart.Series.Add(testSeries); //Add points at the start and and of the x axis to ensure //the graph covers the entire period selected by the user //whether there is data or not chart.Series["Posts"].Points.AddXY(StartDate, 0); chart.Series["Posts"].Points.AddXY(EndDate, 0); return(chart); }
protected abstract List <BinsContainer> GetBinsContainersByDetector(Models.Detector detector);
//MÉTODO PARA DETECTAR LOS PUNTOS DE QUIEBRE DE UNA SERIE, ACEPTA DOS SOBRECARGAS //DetectordeQuiebres(List<Models.MediaMovil> parámetro) //DetectordeQuiebres(List<Models.DataSerie> parámetro) //-----SE OBTIENEN LOS PUNTOS MÁXIMOS Y MÍNIMOS DE ENTRE UN GRUPO DE +-12 VALORES----- public List <Models.Detector> DetectordeQuiebres(List <Models.MediaMovil> seriemediamovil) { //PROCESO PARA DETECTAR LOS PUNTOS DE QUIEBRE List <Models.Detector> seriemediamovilminmax = new List <Models.Detector>(); List <Models.Detector> seriemediamovilminmaxtot = new List <Models.Detector>(); for (int i = 12; i < ((seriemediamovil.Count) - 12); i++) { seriemediamovilminmax = new List <Models.Detector>(); Models.Detector detector = new Models.Detector(); for (int x = 12; x > 0; x--) { detector = new Models.Detector(); detector.mediamovil = seriemediamovil[i - x].mediamovil; detector.fecha = seriemediamovil[i - x].fecha; detector.indice = i - x; seriemediamovilminmax.Add(detector); } detector = new Models.Detector(); detector.mediamovil = seriemediamovil[i].mediamovil; detector.fecha = seriemediamovil[i].fecha; detector.indice = i; seriemediamovilminmax.Add(detector); seriemediamovilminmaxtot.Add(detector); for (int x = 1; x < 13; x++) { detector = new Models.Detector(); detector.mediamovil = seriemediamovil[i + x].mediamovil; detector.fecha = seriemediamovil[i + x].fecha; detector.indice = i + x; seriemediamovilminmax.Add(detector); } double?maximo = seriemediamovilminmax.Max(z => z.mediamovil).Value; if (maximo != null) { if (seriemediamovil[i].mediamovil == maximo) { seriemediamovilminmaxtot.Last().detectormax = 1; } } double?minimo = seriemediamovilminmax.Min(z => z.mediamovil).Value; if (minimo != null) { if (seriemediamovil[i].mediamovil == minimo) { seriemediamovilminmaxtot.Last().detectormin = -1; } } } return(seriemediamovilminmaxtot); }