Class: HTTPLogAnalyzer::Stats
- Inherits:
-
Object
- Object
- HTTPLogAnalyzer::Stats
- Defined in:
- lib/http-log-analyzer/stats.rb
Defined Under Namespace
Classes: BarGraphItem
Constant Summary collapse
- Sections =
{ via: %q{Top 20 sites people came from (aka 'referers')}, searches: %q{Searches}, source_country: %q{Top 20 countries visitors came from}, source_region: %q{Top 20 regions visitors came from}, source_city: %q{Top 20 cities visitors came from}, wv_source_city: %q{Top 20 WV cities visitors came from}, browsers: %q{Top 20 browsers of visitors}, systems: %q{Top 20 operating systems of visitors}, pages: %q{Top 20 pages visited at our site}, informational_statuses: %q{Informational: request received, continuing process}, success_statuses: %q{Success: action successfully received, understood, accepted}, redirection_statuses: %q{Redirection: further action must be taken in order to complete the request}, client_error_statuses: %q{Client error: request contains bad syntax or cannot be fulfilled}, server_error_statuses: %q{Server error: server failed to fulfill an apparently valid request}, dates: %q{Visitors per week}, }
Instance Method Summary collapse
- #add(key, value) ⇒ Object
-
#initialize ⇒ Stats
constructor
A new instance of Stats.
- #report ⇒ Object
Constructor Details
Instance Method Details
#add(key, value) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/http-log-analyzer/stats.rb', line 27 def add(key, value) if value table = @stats[key] or raise "No stats for key #{key.inspect}" table[value] ||= 0 table[value] += 1 end end |
#report ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/http-log-analyzer/stats.rb', line 35 def report @stats.each do |field, counts| next if counts.empty? puts; puts "#{Sections[field]}:" total = counts.values.sum if field == :dates counts = counts.sort_by { |k, v| k } else counts = counts.sort_by { |k, v| v }.reverse[0..19] end counts.each do |label, count| puts ' %s' % BarGraphItem.new(label: label, count: count, total: total) end end end |