Class: PigCI::Report

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

Direct Known Subclasses

DatabaseRequest, Memory, RequestTime

Defined Under Namespace

Classes: DatabaseRequest, Memory, RequestTime

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(historical_log_file: nil, i18n_key: nil, timestamp: nil) ⇒ Report

Returns a new instance of Report.


4
5
6
7
8
# 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

Instance Attribute Details

#historical_log_fileObject

Returns the value of attribute historical_log_file


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

def historical_log_file
  @historical_log_file
end

#i18n_keyObject

Returns the value of attribute i18n_key


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

def i18n_key
  @i18n_key
end

Class Method Details

.format_row(row) ⇒ Object


49
50
51
52
53
# File 'lib/pig_ci/report.rb', line 49

def self.format_row(row)
  row = row.dup
  row[:max_change_percentage] = "#{row[:max_change_percentage]}%"
  row
end

Instance Method Details

#column_keysObject


41
42
43
# File 'lib/pig_ci/report.rb', line 41

def column_keys
  %i[key max min mean number_of_requests max_change_percentage]
end

#headingsObject


10
11
12
# 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_dataObject


33
34
35
# File 'lib/pig_ci/report.rb', line 33

def historical_data
  @historical_data ||= PigCI::Metric::Historical.new(historical_log_file: @historical_log_file).to_h
end

#i18n_nameObject


14
15
16
# File 'lib/pig_ci/report.rb', line 14

def i18n_name
  I18n.t('.name', scope: i18n_scope, locale: PigCI.locale)
end

#i18n_scopeObject


45
46
47
# File 'lib/pig_ci/report.rb', line 45

def i18n_scope
  @i18n_scope ||= "pig_ci.report.#{i18n_key}"
end

#sorted_and_formatted_data_for(timestamp) ⇒ Object


18
19
20
21
22
23
24
# File 'lib/pig_ci/report.rb', line 18

def sorted_and_formatted_data_for(timestamp)
  data_for(timestamp)[@i18n_key.to_sym].sort_by do |data|
    PigCI.report_row_sort_by(data)
  end.collect do |data|
    self.class.format_row(data)
  end
end

#timestampsObject


37
38
39
# File 'lib/pig_ci/report.rb', line 37

def timestamps
  historical_data.keys
end

#to_payload_for(timestamp) ⇒ Object


26
27
28
29
30
31
# File 'lib/pig_ci/report.rb', line 26

def to_payload_for(timestamp)
  {
    profiler: @i18n_key.to_sym,
    data: data_for(timestamp)[@i18n_key.to_sym]
  }
end