Skip to content

Commit

Permalink
Refactor: move and rename method: duration_of_report_step
Browse files Browse the repository at this point in the history
It is only dependent on ReportOptions and shall be part of it.
  • Loading branch information
isimluk committed Oct 24, 2016
1 parent f5df793 commit edb6431
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
13 changes: 1 addition & 12 deletions app/models/chargeback.rb
Expand Up @@ -36,7 +36,7 @@ def self.build_results_for_report_chargeback(options)
timerange = options.report_time_range
data = {}

interval_duration = interval_to_duration(options.interval)
interval_duration = options.duration_of_report_step

timerange.step_value(interval_duration).each_cons(2) do |query_start_time, query_end_time|
records = base_rollup.where(:timestamp => query_start_time...query_end_time, :capture_interval_name => "hourly")
Expand Down Expand Up @@ -86,17 +86,6 @@ def self.hours_in_interval(query_start_time, query_end_time, interval)
(query_end_time - query_start_time) / 1.hour
end

def self.interval_to_duration(interval)
case interval
when "daily"
1.day
when "weekly"
1.week
when "monthly"
1.month
end
end

def self.key_and_fields(metric_rollup_record, interval)
ts_key = get_group_key_ts(metric_rollup_record, interval)

Expand Down
8 changes: 8 additions & 0 deletions app/models/chargeback/report_options.rb
Expand Up @@ -52,5 +52,13 @@ def report_time_range

start_time..end_time
end

def duration_of_report_step
case interval
when 'daily' then 1.day
when 'weekly' then 1.week
when 'monthly' then 1.month
end
end
end
end

0 comments on commit edb6431

Please sign in to comment.