diff --git a/app/models/chargeback/consumption_with_rollups.rb b/app/models/chargeback/consumption_with_rollups.rb index dbe6cacea6a..1ac5eaa40fb 100644 --- a/app/models/chargeback/consumption_with_rollups.rb +++ b/app/models/chargeback/consumption_with_rollups.rb @@ -8,7 +8,11 @@ class ConsumptionWithRollups < Consumption def initialize(metric_rollup_records, start_time, end_time) super(start_time, end_time) - @rollup_array = metric_rollup_records + @rollup_records = metric_rollup_records + end + + def rollup_records + @rollup_records end def hash_features_affecting_rate @@ -21,7 +25,7 @@ def hash_features_affecting_rate end def tag_names - @tag_names ||= @rollup_array.inject([]) do |memo, rollup| + @tag_names ||= rollup_records.inject([]) do |memo, rollup| memo |= all_tag_names(rollup) memo end @@ -67,7 +71,7 @@ def tag_list_with_prefix_for(rollup) end def tag_list_with_prefix - @tag_list_with_prefix ||= @rollup_array.map { |rollup| tag_list_with_prefix_for(rollup) }.flatten.uniq + @tag_list_with_prefix ||= rollup_records.map { |rollup| tag_list_with_prefix_for(rollup) }.flatten.uniq end def sum(metric, sub_metric = nil) @@ -82,7 +86,7 @@ def max(metric, sub_metric = nil) def sum_of_maxes_from_grouped_values(metric, sub_metric = nil) return max(metric, sub_metric) if sub_metric @grouped_values ||= {} - grouped_rollups = @rollup_array.group_by { |x| x[ChargeableField.col_index(:resource_id)] } + grouped_rollups = rollup_records.group_by { |x| x[ChargeableField.col_index(:resource_id)] } @grouped_values[metric] ||= grouped_rollups.map do |_, rollups| rollups.map { |x| rollup_field(x, metric) }.compact.max @@ -108,7 +112,7 @@ def none?(metric, sub_metric) end def chargeback_fields_present - @chargeback_fields_present ||= @rollup_array.count { |rollup| chargeback_fields_present?(rollup) } + @chargeback_fields_present ||= rollup_records.count { |rollup| chargeback_fields_present?(rollup) } end def chargeback_fields_present?(rollup_record) @@ -126,12 +130,12 @@ def metering_used_fields_present?(rollup_record) end def metering_used_fields_present - @metering_used_fields_present ||= @rollup_array.count { |rollup| metering_used_fields_present?(rollup) } + @metering_used_fields_present ||= rollup_records.count { |rollup| metering_used_fields_present?(rollup) } end def metering_allocated_for(metric) @metering_allocated_metric ||= {} - @metering_allocated_metric[metric] ||= @rollup_array.count do |rollup| + @metering_allocated_metric[metric] ||= rollup_records.count do |rollup| rollup_record = rollup_field(rollup, metric) rollup_record.present? && rollup_record.nonzero? end @@ -161,7 +165,7 @@ def sub_metric_rollups(sub_metric) def values(metric, sub_metric = nil) @values ||= {} @values["#{metric}#{sub_metric}"] ||= begin - sub_metric ? sub_metric_rollups(sub_metric) : @rollup_array.collect { |x| rollup_field(x, metric) }.compact + sub_metric ? sub_metric_rollups(sub_metric) : rollup_records.collect { |x| rollup_field(x, metric) }.compact end end @@ -183,7 +187,7 @@ def v_derived_cpu_total_cores_used_for(rollup) end def first_metric_rollup_record - first_rollup_id = @rollup_array.first[ChargeableField.col_index(:id)] + first_rollup_id = rollup_records.first[ChargeableField.col_index(:id)] @fmrr ||= MetricRollup.find(first_rollup_id) if first_rollup_id end end