Class: GenericLogReader

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

Constant Summary collapse

DEBUG =
false

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, line_parser_name, accumulator_name) ⇒ GenericLogReader

Returns a new instance of GenericLogReader.



68
69
70
71
72
73
74
# File 'lib/pqa.rb', line 68

def initialize(filename, line_parser_name, accumulator_name)
  @filename = filename
  @line_parser_name = line_parser_name
  @accumulator_name = accumulator_name
  @includes_duration = false
  @queries, @errors , @parse_errors= [], [], []
end

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



65
66
67
# File 'lib/pqa.rb', line 65

def errors
  @errors
end

#includes_durationObject

Returns the value of attribute includes_duration.



65
66
67
# File 'lib/pqa.rb', line 65

def includes_duration
  @includes_duration
end

#parse_errorsObject

Returns the value of attribute parse_errors.



65
66
67
# File 'lib/pqa.rb', line 65

def parse_errors
  @parse_errors
end

#queriesObject

Returns the value of attribute queries.



65
66
67
# File 'lib/pqa.rb', line 65

def queries
  @queries
end

#time_to_parseObject (readonly)

Returns the value of attribute time_to_parse.



66
67
68
# File 'lib/pqa.rb', line 66

def time_to_parse
  @time_to_parse
end

Instance Method Details

#normalizeObject



102
103
104
# File 'lib/pqa.rb', line 102

def normalize
  @queries.each {|q| q.normalize }
end

#parseObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/pqa.rb', line 76

def parse
  start = Time.new
  a = Object.const_get(@accumulator_name).new
  puts "Using #{@accumulator_name}" if DEBUG
  p = Object.const_get(@line_parser_name).new
  puts "Using #{@line_parser_name}" if DEBUG
  File.foreach(@filename) {|text|
    begin 
      line = p.parse(text)
      if line
        a.append(line)
      else
        # text.gsub!(/\n/, '\n').gsub!(/\t/, '\t')
        # $stderr.puts "Unrecognized text: '#{text}'"
      end
    rescue StandardError => e
      @parse_errors << ParseError.new(e,line)
    end
  }
  @time_to_parse = Time.new - start
  a.close_out_all
  @queries = a.queries
  @errors = a.errors
  @includes_duration = a.has_duration_info
end

#unique_queriesObject



106
107
108
109
110
# File 'lib/pqa.rb', line 106

def unique_queries
  uniq = []
  @queries.each {|x| uniq << x.text if !uniq.include?(x.text) }
  uniq.size
end