Class: PigCI::Metric::Historical
- Inherits:
-
Object
- Object
- PigCI::Metric::Historical
- Defined in:
- lib/pig_ci/metric/historical.rb
Defined Under Namespace
Classes: ChangePercentage
Instance Method Summary collapse
- #add_change_percentage_and_append!(timestamp:, metric:, data:) ⇒ Object
-
#append!(timestamp:, metric:, data:) ⇒ Object
In future this might honour some limit.
-
#initialize(historical_log_file:) ⇒ Historical
constructor
A new instance of Historical.
- #to_h ⇒ Object
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[] = {} max_change_percentage_data[][metric] = data data = PigCI::Metric::Historical::ChangePercentage.new(previous_data: to_h, data: max_change_percentage_data).updated_data append!(timestamp: , metric: metric, data: data[][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[] ||= {} @to_h[][metric] = data remove_old_historical_data! save! end |
#to_h ⇒ Object
6 7 8 |
# File 'lib/pig_ci/metric/historical.rb', line 6 def to_h @to_h ||= read_historical_log_file.sort_by { |, _data| .to_s.to_i * -1 }.to_h end |