Commit 03c9a6134462957817bc7f7a38c98fb63422ab8a

Authored by Bob Lail
1 parent 5e7a9de8
Exists in master and in 1 other branch production

show a breakdown of messages and tenants for

problems as well (as browsers)
app/helpers/application_helper.rb
1 1 module ApplicationHelper
2   -
3   - def user_agent_graph(error)
4   - tallies = tally(error.notices) {|notice| pretty_user_agent(notice.user_agent)}
5   - create_percentage_table(tallies, :total => error.notices.count)
  2 +
  3 +
  4 +
  5 + def message_graph(problem)
  6 + create_percentage_table_for(problem) {|notice| notice.message}
6 7 end
7   -
  8 +
  9 +
  10 +
  11 + def user_agent_graph(problem)
  12 + create_percentage_table_for(problem) {|notice| pretty_user_agent(notice.user_agent)}
  13 + end
  14 +
8 15 def pretty_user_agent(user_agent)
9 16 (user_agent.nil? || user_agent.none?) ? "N/A" : "#{user_agent.browser} #{user_agent.version}"
10 17 end
11   -
  18 +
  19 +
  20 +
  21 + def tenant_graph(problem)
  22 + create_percentage_table_for(problem) {|notice| get_host(notice.request['url'])}
  23 + end
  24 +
  25 + def get_host(url)
  26 + uri = url && URI.parse(url)
  27 + uri.blank? ? "N/A" : uri.host
  28 + end
  29 +
  30 +
  31 +
  32 + def create_percentage_table_for(problem, &block)
  33 + tallies = tally(problem.notices, &block)
  34 + create_percentage_table_from_tallies(tallies, :total => problem.notices.count)
  35 + end
  36 +
12 37 def tally(collection, &block)
13 38 collection.inject({}) do |tallies, item|
14 39 value = yield item
... ... @@ -16,18 +41,21 @@ module ApplicationHelper
16 41 tallies
17 42 end
18 43 end
19   -
20   - def create_percentage_table(tallies, options={})
  44 +
  45 + def create_percentage_table_from_tallies(tallies, options={})
21 46 total = (options[:total] || total_from_tallies(tallies))
22 47 percent = 100.0 / total.to_f
23 48 rows = tallies.map {|value, count| [(count.to_f * percent), value]} \
24 49 .sort {|a, b| a[0] <=> b[0]}
25 50 render :partial => "errs/tally_table", :locals => {:rows => rows}
26 51 end
27   -
  52 +
  53 +
28 54 def total_from_tallies(tallies)
29 55 tallies.values.inject(0) {|sum, n| sum + n}
30 56 end
31 57 private :total_from_tallies
  58 +
  59 +
32 60 end
33 61  
... ...
app/views/notices/_summary.html.haml
... ... @@ -2,7 +2,7 @@
2 2 %table.summary
3 3 %tr
4 4 %th Message
5   - %td.main.nowrap= notice.message
  5 + %td.main.nowrap= message_graph(notice.problem)
6 6 - if notice.request['url'].present?
7 7 %tr
8 8 %th URL
... ... @@ -19,3 +19,6 @@
19 19 %tr
20 20 %th Browser
21 21 %td= user_agent_graph(notice.problem)
  22 + %tr
  23 + %th Tenant
  24 + %td= tenant_graph(notice.problem)
... ...