From 059c92aec92ea2b053b63ba7a361a186c994ad65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Luka=C5=A1=C3=ADk?= Date: Thu, 20 Oct 2016 15:18:15 +0200 Subject: [PATCH] Refactor: Extract method: start_of_report_step --- app/models/chargeback.rb | 18 +----------------- app/models/chargeback/report_options.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/app/models/chargeback.rb b/app/models/chargeback.rb index b2198dbf08c..95db5c47846 100644 --- a/app/models/chargeback.rb +++ b/app/models/chargeback.rb @@ -87,7 +87,7 @@ def self.hours_in_interval(query_start_time, query_end_time, interval) end def self.key_and_fields(metric_rollup_record) - ts_key = get_group_key_ts(metric_rollup_record) + ts_key = @options.start_of_report_step(metric_rollup_record.timestamp) key, extra_fields = if @options[:groupby_tag].present? get_tag_keys_and_fields(metric_rollup_record, ts_key) @@ -178,22 +178,6 @@ def self.reportable_metric_and_cost_fields(rate_name, rate_group, metric, cost) col_hash end - def self.get_group_key_ts(perf) - ts = perf.timestamp.in_time_zone(@options.tz) - case @options.interval - when "daily" - ts = ts.beginning_of_day - when "weekly" - ts = ts.beginning_of_week - when "monthly" - ts = ts.beginning_of_month - else - raise _("interval '%{interval}' is not supported") % {:interval => interval} - end - - ts - end - def self.get_time_range(perf) ts = perf.timestamp.in_time_zone(@options.tz) case @options.interval diff --git a/app/models/chargeback/report_options.rb b/app/models/chargeback/report_options.rb index 105d1d1fc1d..8495cefb0b2 100644 --- a/app/models/chargeback/report_options.rb +++ b/app/models/chargeback/report_options.rb @@ -53,6 +53,20 @@ def report_time_range start_time..end_time end + def start_of_report_step(timestamp) + ts = timestamp.in_time_zone(tz) + case interval + when 'daily' + ts.beginning_of_day + when 'weekly' + ts.beginning_of_week + when 'monthly' + ts.beginning_of_month + else + raise _("interval '%{interval}' is not supported") % {:interval => interval} + end + end + def duration_of_report_step case interval when 'daily' then 1.day