コード例 #1
0
        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);
                }
            }
        }
コード例 #2
0
        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);
        }