class SqlReporter::Reporters::Reporter

Constants

EXTENSION

Attributes

disable_console[R]
feature[RW]
fname0[RW]
fname1[RW]
io[RW]
master[RW]
master_max_count[R]
output[RW]

Public Class Methods

new(parser_hsh) click to toggle source
# 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

Public Instance Methods

generate_report() click to toggle source
# 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_file() click to toggle source
# File lib/sql_reporter/reporters/reporter.rb, line 52
def output_file
  (output || 'comparison') + self.class::EXTENSION
end

Protected Instance Methods

after_generate_report() click to toggle source
# File lib/sql_reporter/reporters/reporter.rb, line 96
def after_generate_report
end
before_decreases() click to toggle source
# File lib/sql_reporter/reporters/reporter.rb, line 102
def before_decreases
end
before_generate_report() click to toggle source
# File lib/sql_reporter/reporters/reporter.rb, line 93
def before_generate_report
end
before_gone() click to toggle source
# File lib/sql_reporter/reporters/reporter.rb, line 105
def before_gone
end
before_increases() click to toggle source
# File lib/sql_reporter/reporters/reporter.rb, line 99
def before_increases
end
before_spawned() click to toggle source
# File lib/sql_reporter/reporters/reporter.rb, line 108
def before_spawned
end
before_summary() click to toggle source
# File lib/sql_reporter/reporters/reporter.rb, line 111
def before_summary
end
construct_difference_object(key) click to toggle source
# File lib/sql_reporter/reporters/reporter.rb, line 87
def construct_difference_object(key)
  m = master[key] || SqlReporter::Query.null(key)
  f = feature[key] || SqlReporter::Query.null(key)
  SqlReporter::Difference.new(key, m, f)
end
generate_query_line(diff) click to toggle source
# File lib/sql_reporter/reporters/reporter.rb, line 61
def generate_query_line(diff)
end
generate_summary(totals, **kwargs) click to toggle source
# File lib/sql_reporter/reporters/reporter.rb, line 58
def generate_summary(totals, **kwargs)
end
process_differences(collection) { |key| ... } click to toggle source
# File lib/sql_reporter/reporters/reporter.rb, line 79
def process_differences(collection)
  prefiltered_collection = collection.select { |key| yield(key) }
  differences = prefiltered_collection.map do |key| 
    construct_difference_object(key)
  end
  differences.sort_by {|d| d.sort_score(master_max_count) }.reverse
end
setup_io() click to toggle source
# File lib/sql_reporter/reporters/reporter.rb, line 114
def setup_io
  @io = File.open(output_file, "w")
end
summary_for_selected_differences(collection, &block) click to toggle source
# File lib/sql_reporter/reporters/reporter.rb, line 64
def summary_for_selected_differences(collection, &block)
  duration_diff = 0
  cached_count_diff = 0
  count_diff = 0
  process_differences(collection, &block).each do |diff|
    generate_query_line(diff)
    count_diff += diff.delta_count
    cached_count_diff += diff.delta_cached_count
    duration_diff += diff.delta_time
  end
  totals = SqlReporter::Total.new(count_diff, duration_diff, cached_count_diff)
  generate_summary(totals)
  totals
end

Private Instance Methods

print_success_message() click to toggle source