/// <summary> /// 检测操作提前多少秒 /// </summary> /// <param name="filter">操作</param> /// <param name="historyTime">历史时刻到现在</param> /// <param name="seconds">提前多少秒</param> /// <returns></returns> public bool CheckOperationAheadSeconds(Func <CarSignalInfo, bool> filter, DateTime historyTime, double seconds) { ///当设置小于等于0时直接验证成功。 if (seconds <= 0) { return(true); } var items = CarSignalSet.Query(historyTime); var firstItem = items.FirstOrDefault(filter); if (firstItem == null) { return(false); } var lastItem = items.LastOrDefault(filter); if (lastItem == null) { return(false); } if (firstItem == lastItem) { return(false); } var isOk = (firstItem.RecordTime - lastItem.RecordTime).TotalSeconds >= seconds; return(isOk); }
public IEnumerable <TimeSpan> GetPeriods(Func <CarSignalInfo, bool> filter, DateTime historyTime) { DateTime?lastRecordTime = null; foreach (var carSensorInfo in CarSignalSet.TakeWhile(x => x.RecordTime >= historyTime)) { var result = filter(carSensorInfo); if (result) { if (!lastRecordTime.HasValue) { lastRecordTime = DateTime.Now; } continue; } if (lastRecordTime.HasValue) { var period = (lastRecordTime.Value - carSensorInfo.RecordTime); lastRecordTime = null; yield return(period); } } }
/// <summary> /// 在规定的时间内两次挂档不进 /// </summary> /// <param name="historyTime">规定的时间时间</param> /// <returns></returns> public bool CheckDoubleChangingGearFailed(DateTime historyTime) { var carSensors = CarSignalSet.Query(historyTime); var carSensorsSections = ParseNotNeutralItems(carSensors).Take(2).ToArray(); if (carSensorsSections.Length < 2) { return(false); } //如果在2次空挡之间检测到没有档位,则评定挂档不进 var result = carSensorsSections.SelectMany(x => x).All(x => x.Sensor.Gear == Gear.Neutral); return(result); }
/// <summary> /// 查询远光变换的次数 /// </summary> /// <param name="historyTime">历史时刻</param> /// <returns></returns> private IEnumerable <int> QueryHighBeamChangedNumbers(DateTime historyTime) { var items = CarSignalSet.Query(historyTime); if (items.Length == 0) { return(Enumerable.Empty <int>()); } var highBeamCounts = ParseHighBeamCounts(items).ToArray(); //Logger.DebugFormat("时间段:{0:HH:mm:ss.ff}-{1:HH:mm:ss.ff},远光变换次数:{2}, {3}", // DateTime.Now, historyTime, // highBeamCounts.Length, highBeamCounts); return(highBeamCounts); }
public bool GetSafetyBeltChanged(int minCount) { if (CarSignalSet.Count <= 1) { return(false); } var currentSafetyBelt = CarSignalSet.Current.Sensor.SafetyBelt; var currentCount = CarSignalSet.TakeWhile(x => x.Sensor.SafetyBelt == currentSafetyBelt).Count(); if (currentCount < minCount) { return(false); } var previousCount = CarSignalSet.Skip(currentCount).TakeWhile(x => x.Sensor.SafetyBelt == !currentSafetyBelt).Count(); return(previousCount >= minCount); }
public void Execute(CarSignalInfo signalInfo) { //加入队列 try { CarSignalProcessors.Execute(signalInfo); } catch (Exception exp) { Logger.ErrorFormat("执行任务 {0} 发生异常,原因: {1}", "CarSignalProcessors", exp.Message); } try { CarSignalMonitor.Execute(signalInfo); } catch (Exception exp) { Logger.ErrorFormat("处理任务 {0} 发生异常,原因: {1}", "CarSignalMonitor", exp.Message); } //加入队列 CarSignalSet.Enqueue(signalInfo); }
public IEnumerable <GearChangedState> GetGearChangedStates(DateTime historyTime) { Gear? g = null; DateTime?lastGearTime = null; DateTime?firstGearTime = null; foreach (var carSensorInfo in CarSignalSet.Query(historyTime)) { if (!g.HasValue) { g = carSensorInfo.Sensor.Gear; lastGearTime = carSensorInfo.RecordTime; continue; } if (g == carSensorInfo.Sensor.Gear) { firstGearTime = carSensorInfo.RecordTime; } else { //档位超过规定值 var gearState = new GearChangedState(g.Value, firstGearTime.GetValueOrDefault(lastGearTime.Value), lastGearTime.Value); yield return(gearState); //启动新的值; g = carSensorInfo.Sensor.Gear; lastGearTime = carSensorInfo.RecordTime; firstGearTime = null; } } if (g.HasValue) { var gearState = new GearChangedState(g.Value, firstGearTime.GetValueOrDefault(lastGearTime.Value), lastGearTime.Value); yield return(gearState); } }