class PigCI::Report
Attributes
historical_log_file[RW]
i18n_key[RW]
Public Class Methods
format_row(row)
click to toggle source
# File lib/pig_ci/report.rb, line 63 def self.format_row(row) row = row.dup row[:max_change_percentage] = "#{row[:max_change_percentage]}%" row end
new(historical_log_file: nil, i18n_key: nil, timestamp: nil)
click to toggle source
# File lib/pig_ci/report.rb, line 4 def initialize(historical_log_file: nil, i18n_key: nil, timestamp: nil) @i18n_key = i18n_key || self.class.name.underscore.split("/").last @historical_log_file = historical_log_file || PigCI.tmp_directory.join("#{@i18n_key}.json") @timestamp = timestamp || PigCI.run_timestamp end
Public Instance Methods
column_keys()
click to toggle source
# File lib/pig_ci/report.rb, line 55 def column_keys %i[key max min mean number_of_requests max_change_percentage] end
headings()
click to toggle source
# File lib/pig_ci/report.rb, line 10 def headings column_keys.collect { |key| I18n.t(".attributes.#{key}", scope: i18n_scope, locale: PigCI.locale) } end
historical_data()
click to toggle source
# File lib/pig_ci/report.rb, line 47 def historical_data @historical_data ||= PigCI::Metric::Historical.new(historical_log_file: @historical_log_file).to_h end
i18n_name()
click to toggle source
# File lib/pig_ci/report.rb, line 14 def i18n_name I18n.t(".name", scope: i18n_scope, locale: PigCI.locale) end
i18n_scope()
click to toggle source
# File lib/pig_ci/report.rb, line 59 def i18n_scope @i18n_scope ||= "pig_ci.report.#{i18n_key}" end
max_for(timestamp)
click to toggle source
# File lib/pig_ci/report.rb, line 18 def max_for(timestamp) sorted_and_formatted_data_for(timestamp).collect { |row| row[:max] }.max end
over_threshold_for?(timestamp)
click to toggle source
# File lib/pig_ci/report.rb, line 26 def over_threshold_for?(timestamp) return false unless threshold.present? && max_for(timestamp).present? max_for(timestamp) > threshold end
sorted_and_formatted_data_for(timestamp)
click to toggle source
# File lib/pig_ci/report.rb, line 32 def sorted_and_formatted_data_for(timestamp) data_for(timestamp)[@i18n_key.to_sym].sort_by { |data| PigCI.report_row_sort_by(data) }.collect do |data| self.class.format_row(data) end end
threshold()
click to toggle source
# File lib/pig_ci/report.rb, line 22 def threshold PigCI.thresholds.dig(@i18n_key.to_sym) end
timestamps()
click to toggle source
# File lib/pig_ci/report.rb, line 51 def timestamps historical_data.keys end
to_payload_for(timestamp)
click to toggle source
# File lib/pig_ci/report.rb, line 40 def to_payload_for(timestamp) { profiler: @i18n_key.to_sym, data: data_for(timestamp)[@i18n_key.to_sym] } end
Private Instance Methods
data_for(timestamp)
click to toggle source
# File lib/pig_ci/report.rb, line 71 def data_for(timestamp) historical_data[timestamp.to_sym] end