Class: PigCI::Metric::Historical::ChangePercentage

Inherits:
Object
  • Object
show all
Defined in:
lib/pig_ci/metric/historial/change_percentage.rb

Instance Method Summary collapse

Constructor Details

#initialize(previous_data:, data:) ⇒ ChangePercentage

Returns a new instance of ChangePercentage.


2
3
4
5
6
7
# File 'lib/pig_ci/metric/historial/change_percentage.rb', line 2

def initialize(previous_data:, data:)
  @previous_data = previous_data
  @data = data
  @timestamp = @data.keys.first
  @profiler = @data[@timestamp].keys.first
end

Instance Method Details

#updated_dataObject


9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pig_ci/metric/historial/change_percentage.rb', line 9

def updated_data
  @data[@timestamp][@profiler].collect do |data|
    previous_run_data = previous_run_data_for_key(data[:key]) || data

    data[:max_change_percentage] = (((BigDecimal(data[:max]) - BigDecimal(previous_run_data[:max])) / BigDecimal(previous_run_data[:max])) * 100).round(PigCI.max_change_percentage_precision)
    data[:max_change_percentage] = BigDecimal('0') if data[:max_change_percentage].to_s == 'NaN' || data[:max_change_percentage] == BigDecimal('-0.0')
    data[:max_change_percentage] = data[:max_change_percentage].to_f

    data
  end

  @data
end