From d3cb77246773ad0494965ac6697468c0deb91c3d Mon Sep 17 00:00:00 2001 From: Chris Schlaeger Date: Thu, 19 May 2016 20:49:09 +0200 Subject: Fix intensity minutes computation. --- lib/postrunner/MonitoringStatistics.rb | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'lib') 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] -- cgit v1.2.3