Skip to content

Commit

Permalink
Refactor: Extract method: start_of_report_step
Browse files Browse the repository at this point in the history
  • Loading branch information
isimluk committed Oct 24, 2016
1 parent 9cb4026 commit 059c92a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
18 changes: 1 addition & 17 deletions app/models/chargeback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions app/models/chargeback/report_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 059c92a

Please sign in to comment.