Commit 03c9a6134462957817bc7f7a38c98fb63422ab8a
1 parent
5e7a9de8
Exists in
master
and in
1 other branch
show a breakdown of messages and tenants for
problems as well (as browsers)
Showing
2 changed files
with
41 additions
and
10 deletions
Show diff stats
app/helpers/application_helper.rb
| 1 | module ApplicationHelper | 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 | end | 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 | def pretty_user_agent(user_agent) | 15 | def pretty_user_agent(user_agent) |
| 9 | (user_agent.nil? || user_agent.none?) ? "N/A" : "#{user_agent.browser} #{user_agent.version}" | 16 | (user_agent.nil? || user_agent.none?) ? "N/A" : "#{user_agent.browser} #{user_agent.version}" |
| 10 | end | 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 | def tally(collection, &block) | 37 | def tally(collection, &block) |
| 13 | collection.inject({}) do |tallies, item| | 38 | collection.inject({}) do |tallies, item| |
| 14 | value = yield item | 39 | value = yield item |
| @@ -16,18 +41,21 @@ module ApplicationHelper | @@ -16,18 +41,21 @@ module ApplicationHelper | ||
| 16 | tallies | 41 | tallies |
| 17 | end | 42 | end |
| 18 | end | 43 | end |
| 19 | - | ||
| 20 | - def create_percentage_table(tallies, options={}) | 44 | + |
| 45 | + def create_percentage_table_from_tallies(tallies, options={}) | ||
| 21 | total = (options[:total] || total_from_tallies(tallies)) | 46 | total = (options[:total] || total_from_tallies(tallies)) |
| 22 | percent = 100.0 / total.to_f | 47 | percent = 100.0 / total.to_f |
| 23 | rows = tallies.map {|value, count| [(count.to_f * percent), value]} \ | 48 | rows = tallies.map {|value, count| [(count.to_f * percent), value]} \ |
| 24 | .sort {|a, b| a[0] <=> b[0]} | 49 | .sort {|a, b| a[0] <=> b[0]} |
| 25 | render :partial => "errs/tally_table", :locals => {:rows => rows} | 50 | render :partial => "errs/tally_table", :locals => {:rows => rows} |
| 26 | end | 51 | end |
| 27 | - | 52 | + |
| 53 | + | ||
| 28 | def total_from_tallies(tallies) | 54 | def total_from_tallies(tallies) |
| 29 | tallies.values.inject(0) {|sum, n| sum + n} | 55 | tallies.values.inject(0) {|sum, n| sum + n} |
| 30 | end | 56 | end |
| 31 | private :total_from_tallies | 57 | private :total_from_tallies |
| 58 | + | ||
| 59 | + | ||
| 32 | end | 60 | end |
| 33 | 61 |
app/views/notices/_summary.html.haml
| @@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
| 2 | %table.summary | 2 | %table.summary |
| 3 | %tr | 3 | %tr |
| 4 | %th Message | 4 | %th Message |
| 5 | - %td.main.nowrap= notice.message | 5 | + %td.main.nowrap= message_graph(notice.problem) |
| 6 | - if notice.request['url'].present? | 6 | - if notice.request['url'].present? |
| 7 | %tr | 7 | %tr |
| 8 | %th URL | 8 | %th URL |
| @@ -19,3 +19,6 @@ | @@ -19,3 +19,6 @@ | ||
| 19 | %tr | 19 | %tr |
| 20 | %th Browser | 20 | %th Browser |
| 21 | %td= user_agent_graph(notice.problem) | 21 | %td= user_agent_graph(notice.problem) |
| 22 | + %tr | ||
| 23 | + %th Tenant | ||
| 24 | + %td= tenant_graph(notice.problem) |