/// <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); }
/// <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 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); } }