Skip to content

Commit

Permalink
Do not pass interval variable along, use @options
Browse files Browse the repository at this point in the history
  • Loading branch information
isimluk committed Oct 24, 2016
1 parent edb6431 commit 9cb4026
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions app/models/chargeback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def self.build_results_for_report_chargeback(options)
# key contains resource_id and timestamp (query_start_time...query_end_time)
# extra_fields there some extra field like resource name and
# some of them are related to specific chargeback (ChargebackVm, ChargebackContainer,...)
key, extra_fields = key_and_fields(metric_rollup_record, options.interval)
key, extra_fields = key_and_fields(metric_rollup_record)
data[key] ||= extra_fields

chargeback_rates = data[key]["chargeback_rates"].split(', ') + rates_to_apply.collect(&:description)
Expand All @@ -86,26 +86,26 @@ def self.hours_in_interval(query_start_time, query_end_time, interval)
(query_end_time - query_start_time) / 1.hour
end

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

key, extra_fields = if @options[:groupby_tag].present?
get_tag_keys_and_fields(metric_rollup_record, ts_key)
else
get_keys_and_extra_fields(metric_rollup_record, ts_key)
end

[key, date_fields(metric_rollup_record, interval).merge(extra_fields)]
[key, date_fields(metric_rollup_record).merge(extra_fields)]
end

def self.date_fields(metric_rollup_record, interval)
start_ts, end_ts, display_range = get_time_range(metric_rollup_record, interval)
def self.date_fields(metric_rollup_record)
start_ts, end_ts, display_range = get_time_range(metric_rollup_record)

{
'start_date' => start_ts,
'end_date' => end_ts,
'display_range' => display_range,
'interval_name' => interval,
'interval_name' => @options.interval,
'chargeback_rates' => '',
'entity' => metric_rollup_record.resource
}
Expand Down Expand Up @@ -178,9 +178,9 @@ def self.reportable_metric_and_cost_fields(rate_name, rate_group, metric, cost)
col_hash
end

def self.get_group_key_ts(perf, interval)
def self.get_group_key_ts(perf)
ts = perf.timestamp.in_time_zone(@options.tz)
case interval
case @options.interval
when "daily"
ts = ts.beginning_of_day
when "weekly"
Expand All @@ -194,9 +194,9 @@ def self.get_group_key_ts(perf, interval)
ts
end

def self.get_time_range(perf, interval)
def self.get_time_range(perf)
ts = perf.timestamp.in_time_zone(@options.tz)
case interval
case @options.interval
when "daily"
[ts.beginning_of_day, ts.end_of_day, ts.strftime("%m/%d/%Y")]
when "weekly"
Expand Down

0 comments on commit 9cb4026

Please sign in to comment.