Class: PostRunner::DailySleepAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/postrunner/DailySleepAnalyzer.rb

Overview

This class extracts the sleep information from a set of monitoring files and determines when and how long the user was awake or had a light or deep sleep.

Defined Under Namespace

Classes: SleepInterval

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(monitoring_files, day) ⇒ DailySleepAnalyzer

Create a new DailySleepAnalyzer object to analyze the given monitoring files.

Parameters:

  • monitoring_files (Array)

    A set of Monitoring_B objects

  • day (String)

    Day to analyze as YY-MM-DD string



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/postrunner/DailySleepAnalyzer.rb', line 33

def initialize(monitoring_files, day)
  @noon_yesterday = @noon_today = @utc_offset = nil
  @sleep_intervals = []

  # Day as Time object. Midnight UTC.
  day_as_time = Time.parse(day + "-00:00:00+00:00").gmtime
  extract_data_from_monitor_files(monitoring_files, day_as_time)
  fill_sleep_activity
  smoothen_sleep_activity
  analyze
  trim_wake_periods_at_ends
  calculate_totals
end

Instance Attribute Details

#deep_sleepObject (readonly)

Returns the value of attribute deep_sleep.



26
27
28
# File 'lib/postrunner/DailySleepAnalyzer.rb', line 26

def deep_sleep
  @deep_sleep
end

#light_sleepObject (readonly)

Returns the value of attribute light_sleep.



26
27
28
# File 'lib/postrunner/DailySleepAnalyzer.rb', line 26

def light_sleep
  @light_sleep
end

#sleep_intervalsObject (readonly)

Returns the value of attribute sleep_intervals.



26
27
28
# File 'lib/postrunner/DailySleepAnalyzer.rb', line 26

def sleep_intervals
  @sleep_intervals
end

#total_sleepObject (readonly)

Returns the value of attribute total_sleep.



26
27
28
# File 'lib/postrunner/DailySleepAnalyzer.rb', line 26

def total_sleep
  @total_sleep
end

#utc_offsetObject (readonly)

Returns the value of attribute utc_offset.



26
27
28
# File 'lib/postrunner/DailySleepAnalyzer.rb', line 26

def utc_offset
  @utc_offset
end