diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/postrunner/FitFileStore.rb | 20 | ||||
-rw-r--r-- | lib/postrunner/Main.rb | 11 | ||||
-rw-r--r-- | lib/postrunner/MonitoringStatistics.rb | 24 |
3 files changed, 52 insertions, 3 deletions
diff --git a/lib/postrunner/FitFileStore.rb b/lib/postrunner/FitFileStore.rb index fb86d76..9093925 100644 --- a/lib/postrunner/FitFileStore.rb +++ b/lib/postrunner/FitFileStore.rb @@ -17,6 +17,7 @@ require 'postrunner/Log' require 'postrunner/DirUtils' require 'postrunner/FFS_Device' require 'postrunner/ActivityListView' +require 'postrunner/DailyMonitoringView' require 'postrunner/ViewButtons' require 'postrunner/MonitoringStatistics' @@ -336,7 +337,26 @@ module PostRunner end end + def show_monitoring(day) + # 'day' specifies the current day. But we don't know what timezone the + # watch was set to for a given date. The files are always named after + # the moment of finishing the recording expressed as GMT time. + # Each file contains information about the time zone for the specific + # file. Recording is always flipped to a new file at midnight GMT but + # there are usually multiple files per GMT day. + day_as_time = Time.parse(day).gmtime + # To get weekly intensity minutes we need 7 days of data prior to the + # current date and 1 day after to include the following night. We add + # at least 12 extra hours to accomodate time zone changes. + monitoring_files = monitorings(day_as_time - 8 * 24 * 60 * 60, + day_as_time + 36 * 60 * 60) + + show_in_browser(DailyMonitoringView.new(@store, day, monitoring_files). + file_name) + end + def daily_report(day) + monitoring_files = gather_monitoring_files(day) # 'day' specifies the current day. But we don't know what timezone the # watch was set to for a given date. The files are always named after # the moment of finishing the recording expressed as GMT time. diff --git a/lib/postrunner/Main.rb b/lib/postrunner/Main.rb index 8bc1aa3..d1b36fd 100644 --- a/lib/postrunner/Main.rb +++ b/lib/postrunner/Main.rb @@ -223,9 +223,10 @@ set <attribute> <value> <ref> type: The type of the activity subtype: The subtype of the activity -show [ <ref> ] - Show the referenced FIT activity in a web browser. If no reference - is provided show the list of activities in the database. +show [ <ref> | <YYYY-MM-DD> ] + Show the referenced FIT activity or monitoring data for the given + date in a web browser. If no argument is provided show the list of + activities in the database. sources [ <ref> ] Show the data sources for the various measurements and how they @@ -368,6 +369,10 @@ EOT when 'show' if args.empty? @ffs.show_list_in_browser + elsif args[0] =~ /\A2\d{3}-\d{2}-\d{2}\z/ + # Likely a valid YYYY-MM-DD date. Show the monitoring data for the + # given day in a browser. + @ffs.show_monitoring(args[0]) else process_activities(args, :show) end diff --git a/lib/postrunner/MonitoringStatistics.rb b/lib/postrunner/MonitoringStatistics.rb index 867d55c..d3b2c1d 100644 --- a/lib/postrunner/MonitoringStatistics.rb +++ b/lib/postrunner/MonitoringStatistics.rb @@ -55,6 +55,30 @@ module PostRunner str end + # Generate a report for a certain day. + # @param day [String] Date of the day as YYYY-MM-DD string. + def daily_html(day, doc) + sleep_analyzer = DailySleepAnalyzer.new(@monitoring_files, day, + +12 * 60 * 60) + monitoring_analyzer = DailyMonitoringAnalyzer.new(@monitoring_files, day) + + doc.div { + doc.h2("Daily Monitoring Report for #{day}") + daily_goals_table(monitoring_analyzer).to_html(doc) + doc.br + daily_stats_table(monitoring_analyzer, sleep_analyzer).to_html(doc) + + if sleep_analyzer.sleep_cycles.empty? + doc.h3('No sleep data available for this day') + else + doc.h2("Sleep Statistics for " + + "#{sleep_analyzer.window_start_time.strftime('%Y-%m-%d')} - " + + "#{sleep_analyzer.window_end_time.strftime('%Y-%m-%d')}") + daily_sleep_cycle_table(sleep_analyzer).to_html(doc) + end + } + end + # Generate a report for a certain week. # @param day [String] Date of a day in that week as YYYY-MM-DD string. def weekly(start_day) |