Skip to content

Commit

Permalink
Refactor: Extract method: report_step_range
Browse files Browse the repository at this point in the history
  • Loading branch information
isimluk committed Oct 24, 2016
1 parent 473d14c commit 814718d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
20 changes: 1 addition & 19 deletions app/models/chargeback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def self.key_and_fields(metric_rollup_record)
end

def self.date_fields(metric_rollup_record)
start_ts, end_ts, display_range = get_time_range(metric_rollup_record)
start_ts, end_ts, display_range = @options.report_step_range(metric_rollup_record.timestamp)

{
'start_date' => start_ts,
Expand Down Expand Up @@ -174,24 +174,6 @@ def self.reportable_metric_and_cost_fields(rate_name, rate_group, metric, cost)
col_hash
end

def self.get_time_range(perf)
ts = perf.timestamp.in_time_zone(@options.tz)
case @options.interval
when "daily"
[ts.beginning_of_day, ts.end_of_day, ts.strftime("%m/%d/%Y")]
when "weekly"
s_ts = ts.beginning_of_week
e_ts = ts.end_of_week
[s_ts, e_ts, "Week of #{s_ts.strftime("%m/%d/%Y")}"]
when "monthly"
s_ts = ts.beginning_of_month
e_ts = ts.end_of_month
[s_ts, e_ts, s_ts.strftime("%b %Y")]
else
raise _("interval '%{interval}' is not supported") % {:interval => interval}
end
end

def self.report_cb_model(model)
model.gsub(/^Chargeback/, "")
end
Expand Down
18 changes: 18 additions & 0 deletions app/models/chargeback/report_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@ def start_of_report_step(timestamp)
end
end

def report_step_range(timestamp)
ts = timestamp.in_time_zone(tz)
case interval
when 'daily'
[ts.beginning_of_day, ts.end_of_day, ts.strftime('%m/%d/%Y')]
when 'weekly'
s_ts = ts.beginning_of_week
e_ts = ts.end_of_week
[s_ts, e_ts, "Week of #{s_ts.strftime('%m/%d/%Y')}"]
when 'monthly'
s_ts = ts.beginning_of_month
e_ts = ts.end_of_month
[s_ts, e_ts, s_ts.strftime('%b %Y')]
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 814718d

Please sign in to comment.