summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Schlaeger <chris@linux.com>2016-05-19 20:49:09 +0200
committerChris Schlaeger <chris@linux.com>2016-05-19 20:49:09 +0200
commitd3cb77246773ad0494965ac6697468c0deb91c3d (patch)
tree65d4edd13f3006c500c7700c4cb127ec093c3d14
parent5d9c1afe3eb8ba95c094406a3d80baae6b44cd34 (diff)
downloadpostrunner-d3cb77246773ad0494965ac6697468c0deb91c3d.zip
Fix intensity minutes computation.
-rw-r--r--lib/postrunner/MonitoringStatistics.rb24
1 files changed, 16 insertions, 8 deletions
diff --git a/lib/postrunner/MonitoringStatistics.rb b/lib/postrunner/MonitoringStatistics.rb
index 41e867b..ab1761c 100644
--- a/lib/postrunner/MonitoringStatistics.rb
+++ b/lib/postrunner/MonitoringStatistics.rb
@@ -340,17 +340,25 @@ module PostRunner
end
def weekly_intensity_minutes(monitoring_analyzer)
- current_date = monitoring_analyzer.window_start_time
+ current_date = monitoring_analyzer.window_start_time.localtime
intensity_minutes = 0
- 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]
+ # Get intensity minutes for previous days of the current week.
+ if current_date.wday != @first_day_of_week
+ 1.upto(5) 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]
+
+ break if current_date.wday == @first_day_of_week
+ end
end
+
+ # Finally add the intensity minutes of the current day.
intensity_minutes +=
monitoring_analyzer.intensity_minutes[:moderate_minutes] +
2 * monitoring_analyzer.intensity_minutes[:vigorous_minutes]