Class: PigCI::Metric::Historical

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

Defined Under Namespace

Classes: ChangePercentage

Instance Method Summary collapse

Constructor Details

#initialize(historical_log_file:) ⇒ Historical

Returns a new instance of Historical.



2
3
4
# File 'lib/pig_ci/metric/historical.rb', line 2

def initialize(historical_log_file:)
  @historical_log_file = historical_log_file
end

Instance Method Details

#add_change_percentage_and_append!(timestamp:, metric:, data:) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/pig_ci/metric/historical.rb', line 19

def add_change_percentage_and_append!(timestamp:, metric:, data:)
  max_change_percentage_data = {}
  max_change_percentage_data[timestamp] = {}
  max_change_percentage_data[timestamp][metric] = data

  data = PigCI::Metric::Historical::ChangePercentage.new(previous_data: to_h, data: max_change_percentage_data).updated_data
  append!(timestamp: timestamp, metric: metric, data: data[timestamp][metric])
end

#append!(timestamp:, metric:, data:) ⇒ Object

In future this might honour some limit.



11
12
13
14
15
16
17
# File 'lib/pig_ci/metric/historical.rb', line 11

def append!(timestamp:, metric:, data:)
  to_h
  @to_h[timestamp] ||= {}
  @to_h[timestamp][metric] = data
  remove_old_historical_data!
  save!
end

#to_hObject



6
7
8
# File 'lib/pig_ci/metric/historical.rb', line 6

def to_h
  @to_h ||= read_historical_log_file.sort_by { |timestamp, _data| timestamp.to_s.to_i * -1 }.to_h
end