Ejemplo n.º 1
0
        public int[] GetSleepPeriods()
        {
            var periods = new List <int>();

            Day4.ShiftEvent startSleeping = null;

            foreach (var shiftEvent in this.Events)
            {
                if (shiftEvent.EventType == Day4.ShiftEventTypes.FallAsleep)
                {
                    startSleeping = shiftEvent;
                }

                if (shiftEvent.EventType == Day4.ShiftEventTypes.WakeUp)
                {
                    if (startSleeping == null)
                    {
                        throw new Exception("Wrong sequence!");
                    }

                    for (int i = startSleeping.EventTime.Minute; i < shiftEvent.EventTime.Minute; i++)
                    {
                        periods.Add(i);
                    }
                }
            }

            return(periods.ToArray());
        }
Ejemplo n.º 2
0
        public int GetSleepTime()
        {
            var totalSleepTime = 0;

            Day4.ShiftEvent startSleeping = null;

            foreach (var shiftEvent in this.Events)
            {
                if (shiftEvent.EventType == Day4.ShiftEventTypes.FallAsleep)
                {
                    startSleeping = shiftEvent;
                }

                if (shiftEvent.EventType == Day4.ShiftEventTypes.WakeUp)
                {
                    if (startSleeping == null)
                    {
                        throw new Exception("Wrong sequence!");
                    }

                    var timeSleeping = shiftEvent.EventTime.Subtract(startSleeping.EventTime).Minutes;
                    totalSleepTime += timeSleeping;
                }
            }


            return(totalSleepTime);
        }