Class: MostFrequentQueriesReport

Inherits:
GenericReport show all
Defined in:
lib/pqa.rb

Instance Method Summary collapse

Methods inherited from GenericReport

#applicable, #colorize, #pctg_of, #round

Constructor Details

#initialize(log, top = DEFAULT_TOP) ⇒ MostFrequentQueriesReport

Returns a new instance of MostFrequentQueriesReport.



947
948
949
950
# File 'lib/pqa.rb', line 947

def initialize(log, top=DEFAULT_TOP)
  super(log)
  @top = top
end

Instance Method Details

#create_reportObject



975
976
977
978
979
980
981
982
# File 'lib/pqa.rb', line 975

def create_report
  h = {}
  @log.queries.each {|q|
    h[q.text] = 0 if !h.has_key?(q.text)
    h[q.text] += 1
  }
  h.sort {|a,b| b[1] <=> a[1] }
end

#htmlObject



956
957
958
959
960
961
962
963
964
# File 'lib/pqa.rb', line 956

def html
  list = create_report
  rpt = "<h3>#{title}</h3>\n"
  rpt << "<table><tr><th>Rank</th><th>Times executed</th><th>Query text</th>\n"
  (list.size < @top ? list.size : @top).times {|x| 
      rpt << "<tr><td>#{x+1}</td><td>#{list[x][1]}</td><td>#{colorize(list[x][0])}</td></tr>\n" 
  }
  rpt << "</table>\n"
end

#textObject



966
967
968
969
970
971
972
973
# File 'lib/pqa.rb', line 966

def text
  list = create_report
  rpt = "######## #{title}\n"
  (list.size < @top ? list.size : @top).times {|x| 
      rpt << list[x][1].to_s + " times: " + list[x][0].to_s + "\n" 
  }
  rpt
end

#titleObject



952
953
954
# File 'lib/pqa.rb', line 952

def title  
  "Most frequent queries"
end