summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Schlaeger <chris@linux.com>2016-05-18 21:01:10 +0200
committerChris Schlaeger <chris@linux.com>2016-05-18 21:01:10 +0200
commit5d9c1afe3eb8ba95c094406a3d80baae6b44cd34 (patch)
tree5cfe10c1127293291b3ea361c49931c931082ad5
parent535f0daf9b18aa73916769664be16104e07219b1 (diff)
downloadpostrunner-5d9c1afe3eb8ba95c094406a3d80baae6b44cd34.zip
Show weekly intensity minutes, not daily.
-rw-r--r--lib/postrunner/FitFileStore.rb9
-rw-r--r--lib/postrunner/MonitoringStatistics.rb44
2 files changed, 30 insertions, 23 deletions
diff --git a/lib/postrunner/FitFileStore.rb b/lib/postrunner/FitFileStore.rb
index 2be40c4..4b71f27 100644
--- a/lib/postrunner/FitFileStore.rb
+++ b/lib/postrunner/FitFileStore.rb
@@ -329,9 +329,10 @@ module PostRunner
# there are usually multiple files per GMT day.
day_as_time = Time.parse(day).gmtime
@store['devices'].each do |id, device|
- # We are looking for all files that potentially overlap with our
- # localtime day.
- monitorings += device.monitorings(day_as_time - 36 * 60 * 60,
+ # 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.
+ monitorings += device.monitorings(day_as_time - 8 * 24 * 60 * 60,
day_as_time + 36 * 60 * 60)
end
monitoring_files = monitorings.reverse.map do |m|
@@ -354,7 +355,7 @@ module PostRunner
@store['devices'].each do |id, device|
# We are looking for all files that potentially overlap with our
# localtime day.
- monitorings += device.monitorings(day_as_time - 36 * 60 * 60,
+ monitorings += device.monitorings(day_as_time - 8 * 24 * 60 * 60,
day_as_time + 33 * 24 * 60 * 60)
end
monitoring_files = monitorings.sort.map do |m|
diff --git a/lib/postrunner/MonitoringStatistics.rb b/lib/postrunner/MonitoringStatistics.rb
index 528629f..41e867b 100644
--- a/lib/postrunner/MonitoringStatistics.rb
+++ b/lib/postrunner/MonitoringStatistics.rb
@@ -29,6 +29,8 @@ module PostRunner
# @param monitoring_files [Array of Fit4Ruby::Monitoring_B] FIT files
def initialize(monitoring_files)
@monitoring_files = monitoring_files
+ # Week starts on Monday
+ @first_day_of_week = 1
end
# Generate a report for a certain day.
@@ -197,17 +199,17 @@ module PostRunner
right = { :halign => :right }
t.set_column_attributes([ left ] + [ right ] * 7)
t.head
- t.row([ 'Date', 'Steps', '%', 'Goal', 'Intensity', '%',
+ t.row([ 'Day', 'Steps', '%', 'Goal', 'Intensity', '%',
'Floors', '% of 10' ])
t.row([ '', '', '', '', 'Minutes', 'Week', '', '' ])
t.body
totals = Hash.new(0)
counted_days = 0
- weekly_intensity_minutes = 0
+ intensity_minutes_sum = 0
1.upto(last_day_of_month).each do |dom|
break if (time = Time.new(year, month, dom)) > Time.now
- day_str = time.strftime('%Y-%m-%d')
+ day_str = time.strftime('%d %a')
t.cell(day_str)
analyzer = DailyMonitoringAnalyzer.new(@monitoring_files, day_str)
@@ -221,14 +223,18 @@ module PostRunner
t.cell(percent(steps, steps_goal))
t.cell(steps_goal)
- weekly_intensity_minutes = 0 if time.wday == 1
- intensity_minutes =
- analyzer.intensity_minutes[:moderate_minutes] +
- 2 * analyzer.intensity_minutes[:vigorous_minutes]
- weekly_intensity_minutes += intensity_minutes
+ if dom == 1
+ intensity_minutes = weekly_intensity_minutes(analyzer)
+ else
+ intensity_minutes_sum = 0 if time.wday == @first_day_of_week
+ intensity_minutes =
+ analyzer.intensity_minutes[:moderate_minutes] +
+ 2 * analyzer.intensity_minutes[:vigorous_minutes]
+ end
+ intensity_minutes_sum += intensity_minutes
totals[:intensity_minutes] += intensity_minutes
- t.cell(weekly_intensity_minutes.to_i)
- t.cell(percent(weekly_intensity_minutes, 150))
+ t.cell(intensity_minutes_sum.to_i)
+ t.cell(percent(intensity_minutes_sum, 150))
floors = analyzer.total_floors
floors_climbed = floors[:floors_climbed]
@@ -280,7 +286,7 @@ module PostRunner
1.upto(last_day_of_month).each do |dom|
break if (time = Time.new(year, month, dom)) > Time.now
- day_str = time.strftime('%Y-%m-%d')
+ day_str = time.strftime('%d %a')
t.cell(day_str)
analyzer = DailySleepAnalyzer.new(@monitoring_files, day_str,
@@ -337,14 +343,14 @@ module PostRunner
current_date = monitoring_analyzer.window_start_time
intensity_minutes = 0
- # Need to find a way to get intensity minutes for previous days.
- #1.upto(current_date.wday) do |i|
- # date = current_date - 24 * 60 * 60 * i
- # ma = DailyMonitoringAnalyzer.new(date.strftime('%Y-%m-%d'))
- # intensity_minutes +=
- # ma.intensity_minutes[:moderate_minutes] +
- # 2 * ma.intensity_minutes[:vigorous_minutes]
- #end
+ 1.upto((7 + current_date.wday - @first_day_of_week) % 7) do |i|
+ date = current_date - 24 * 60 * 60 * i
+ ma = DailyMonitoringAnalyzer.new(@monitoring_files,
+ date.strftime('%Y-%m-%d'))
+ intensity_minutes +=
+ ma.intensity_minutes[:moderate_minutes] +
+ 2 * ma.intensity_minutes[:vigorous_minutes]
+ end
intensity_minutes +=
monitoring_analyzer.intensity_minutes[:moderate_minutes] +
2 * monitoring_analyzer.intensity_minutes[:vigorous_minutes]