Class: SqlReporter::Reporters::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/sql_reporter/reporters/reporter.rb

Direct Known Subclasses

JsonReporter, LogReporter, PdfReporter, PlotReporter

Constant Summary collapse

EXTENSION =
''

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parser_hsh) ⇒ Reporter

Returns a new instance of Reporter.



6
7
8
9
10
11
12
# File 'lib/sql_reporter/reporters/reporter.rb', line 6

def initialize(parser_hsh)
  @fname0, @master = parser_hsh.entries[0]
  @fname1, @feature = parser_hsh.entries[1]
  @master_max_count = @master.values.map(&:count).max
  @output = parser_hsh[:output] if parser_hsh.key?(:output)
  @disable_console = parser_hsh[:disable_console] if parser_hsh.key?(:disable_console)
end

Instance Attribute Details

#disable_consoleObject (readonly)

Returns the value of attribute disable_console.



15
16
17
# File 'lib/sql_reporter/reporters/reporter.rb', line 15

def disable_console
  @disable_console
end

#featureObject

Returns the value of attribute feature.



14
15
16
# File 'lib/sql_reporter/reporters/reporter.rb', line 14

def feature
  @feature
end

#fname0Object

Returns the value of attribute fname0.



14
15
16
# File 'lib/sql_reporter/reporters/reporter.rb', line 14

def fname0
  @fname0
end

#fname1Object

Returns the value of attribute fname1.



14
15
16
# File 'lib/sql_reporter/reporters/reporter.rb', line 14

def fname1
  @fname1
end

#ioObject

Returns the value of attribute io.



14
15
16
# File 'lib/sql_reporter/reporters/reporter.rb', line 14

def io
  @io
end

#masterObject

Returns the value of attribute master.



14
15
16
# File 'lib/sql_reporter/reporters/reporter.rb', line 14

def master
  @master
end

#master_max_countObject (readonly)

Returns the value of attribute master_max_count.



15
16
17
# File 'lib/sql_reporter/reporters/reporter.rb', line 15

def master_max_count
  @master_max_count
end

#outputObject

Returns the value of attribute output.



14
15
16
# File 'lib/sql_reporter/reporters/reporter.rb', line 14

def output
  @output
end

Instance Method Details

#generate_reportObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/sql_reporter/reporters/reporter.rb', line 17

def generate_report
  setup_io
  before_generate_report
  totals = []
  
  before_decreases
  totals << summary_for_selected_differences(master.keys | feature.keys) do |key| 
    master[key] && feature[key] && (
      master[key].count > feature[key].count || (master[key].count == feature[key].count &&  master[key].cached_count > feature[key].cached_count)
    )
  end

  before_increases
  totals << summary_for_selected_differences(master.keys | feature.keys) do |key|
    master[key] && feature[key] && (
      master[key].count < feature[key].count || (master[key].count == feature[key].count && master[key].cached_count < feature[key].cached_count)
    )
  end

  before_spawned
  totals << summary_for_selected_differences(feature.keys - master.keys) { |key| feature[key] }

  before_gone
  totals << summary_for_selected_differences(master.keys - feature.keys) { |key| master[key] }

  before_summary
  totals_sum = totals.reduce(SqlReporter::Total.new(0,0,0)) {|acc, t| acc + t}
  additional_data = {}
  additional_data[:reduced] = totals.reduce(0) {|acc, t| acc + t.query_drop}
  additional_data[:spawned] = totals.reduce(0) {|acc, t| acc + t.query_gain}
  generate_summary(totals_sum, **additional_data)
  after_generate_report
  print_success_message
end

#output_fileObject



52
53
54
# File 'lib/sql_reporter/reporters/reporter.rb', line 52

def output_file
  (output || 'comparison') + self.class::EXTENSION
end