コード例 #1
0
        public static IEnumerable <GenericInterval> EnumerateIntervals(IList <MonitorRow> data, TimeSpan intervalLength)
        {
            MonitorRow start = null;
            int        i0    = -1;
            MonitorRow end   = null;

            for (int i = 0; i < data.Count; i++)
            {
                MonitorRow row = data[i];
                end = row;
                if (start == null)
                {
                    start = row;
                    i0    = i;
                }
                else if (row.TimeStamp - start.TimeStamp >= intervalLength)
                {
                    yield return(new GenericInterval(i0, start.Id, start.TimeStamp, i, end.Id, end.TimeStamp));

                    start = row;
                    i0    = i;
                    //start = null;
                }
            }

            // TODO last interval falls short.. what to do?
            // if (start != null && start.Id < end.Id)
            // {
            //     yield return new GenericInterval(startIndex, start.Id, monitor.Data.Count - 1, end.Id);
            // }
        }
コード例 #2
0
 public DroSleepCycle(MonitorRow cycleStart, int beamCrossingsBeforeSleep, MonitorRow sleepStart, MonitorRow cycleEnd, MonitorRow lightSwitch)
 {
     this.CycleStart = cycleStart ?? throw new ArgumentNullException(nameof(cycleStart));
     this.BeamCrossingsBeforeSleep = beamCrossingsBeforeSleep;
     this.SleepStart  = sleepStart ?? throw new ArgumentNullException(nameof(sleepStart));
     this.CycleEnd    = cycleEnd ?? throw new ArgumentNullException(nameof(cycleEnd));
     this.LightSwitch = lightSwitch; // can be null typically
 }
コード例 #3
0
 public Monitor(string filename)
 {
     if (!File.Exists(filename))
     {
         throw new FileNotFoundException(filename);
     }
     this.Data           = new List <MonitorRow>();
     this.LightIntervals = new List <LightInterval>();
     using (var r = new StreamReader(filename))
     {
         string        line;
         LightInterval interval = null;
         int           index    = 0;
         while ((line = r.ReadLine()) != null)
         {
             if (string.IsNullOrWhiteSpace(line))
             {
                 continue;
             }
             MonitorRow row = new MonitorRow(line); // might throw
             if (interval == null)
             {
                 interval = new LightInterval(row.IsLightOn, index, row.Id, row.TimeStamp, -1, -1L, default(DateTimeOffset));
             }
             else if (interval.IsLightOn != row.IsLightOn)
             {
                 // finish the interval
                 int        prevIndex = this.Data.Count - 1;
                 MonitorRow prevRow   = this.Data[prevIndex];
                 this.LightIntervals.Add(new LightInterval(interval.IsLightOn,
                                                           interval.StartIndex, interval.StartId, interval.StartTime,
                                                           prevIndex, prevRow.Id, prevRow.TimeStamp));
                 // and start next
                 interval = new LightInterval(row.IsLightOn, index, row.Id, row.TimeStamp, -1, -1L, default(DateTimeOffset));
             }
             this.Data.Add(row);
             index++;
         }
         if (this.Data.Count > 1)
         {
             this.DataColumns = this.Data[0].BeamCrossings.Length;
             // finish the last interval
             int        endIndex = this.Data.Count - 1;
             MonitorRow endRow   = this.Data[endIndex];
             this.LightIntervals.Add(new LightInterval(interval.IsLightOn,
                                                       interval.StartIndex, interval.StartId, interval.StartTime,
                                                       endIndex, endRow.Id, endRow.TimeStamp));
         }
     }
 }
コード例 #4
0
        public static IEnumerable <DroSleepCycle> Enumerate(IEnumerable <MonitorRow> rows, int index, TimeSpan inactivityThreshold)
        {
            MonitorRow cycleStart = null;
            int        beamCrossingsBeforeSleep = 0;
            MonitorRow sleepStart  = null;
            MonitorRow lightSwitch = null;

            foreach (MonitorRow row in rows)
            {
                int activity = row.BeamCrossings[index];
                if (lightSwitch == null && sleepStart != null && sleepStart.IsLightOn != row.IsLightOn)
                {
                    lightSwitch = row;
                }
                // 1) check for completion
                if (sleepStart != null && row.TimeStamp - sleepStart.TimeStamp >= inactivityThreshold && activity > 0)
                {
                    // end of interval!
                    yield return(new DroSleepCycle(cycleStart, beamCrossingsBeforeSleep, sleepStart, row, lightSwitch));

                    // start next interval
                    cycleStart = null;
                    beamCrossingsBeforeSleep = 0;
                    sleepStart = null;
                }
                else if (sleepStart != null && activity > 0)
                {
                    sleepStart = null; // reset, not really sleep according to threshold
                }

                // 2) update
                if (cycleStart == null)
                {
                    cycleStart = row;
                }
                beamCrossingsBeforeSleep += activity;
                if (sleepStart == null && activity == 0) // eventually the start of a sleep cycle
                {
                    sleepStart = row;
                }
            } // end-for
        }
コード例 #5
0
 public bool Contains(MonitorRow row)
 {
     return(this.StartId <= row.Id && row.Id < this.EndId);
 }