diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 03ffd12..39d6a6d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,14 +1,39 @@ module ApplicationHelper - - def user_agent_graph(error) - tallies = tally(error.notices) {|notice| pretty_user_agent(notice.user_agent)} - create_percentage_table(tallies, :total => error.notices.count) + + + + def message_graph(problem) + create_percentage_table_for(problem) {|notice| notice.message} end - + + + + def user_agent_graph(problem) + create_percentage_table_for(problem) {|notice| pretty_user_agent(notice.user_agent)} + end + def pretty_user_agent(user_agent) (user_agent.nil? || user_agent.none?) ? "N/A" : "#{user_agent.browser} #{user_agent.version}" end - + + + + def tenant_graph(problem) + create_percentage_table_for(problem) {|notice| get_host(notice.request['url'])} + end + + def get_host(url) + uri = url && URI.parse(url) + uri.blank? ? "N/A" : uri.host + end + + + + def create_percentage_table_for(problem, &block) + tallies = tally(problem.notices, &block) + create_percentage_table_from_tallies(tallies, :total => problem.notices.count) + end + def tally(collection, &block) collection.inject({}) do |tallies, item| value = yield item @@ -16,18 +41,21 @@ module ApplicationHelper tallies end end - - def create_percentage_table(tallies, options={}) + + def create_percentage_table_from_tallies(tallies, options={}) total = (options[:total] || total_from_tallies(tallies)) percent = 100.0 / total.to_f rows = tallies.map {|value, count| [(count.to_f * percent), value]} \ .sort {|a, b| a[0] <=> b[0]} render :partial => "errs/tally_table", :locals => {:rows => rows} end - + + def total_from_tallies(tallies) tallies.values.inject(0) {|sum, n| sum + n} end private :total_from_tallies + + end diff --git a/app/views/notices/_summary.html.haml b/app/views/notices/_summary.html.haml index 91214d1..b75e22d 100644 --- a/app/views/notices/_summary.html.haml +++ b/app/views/notices/_summary.html.haml @@ -2,7 +2,7 @@ %table.summary %tr %th Message - %td.main.nowrap= notice.message + %td.main.nowrap= message_graph(notice.problem) - if notice.request['url'].present? %tr %th URL @@ -19,3 +19,6 @@ %tr %th Browser %td= user_agent_graph(notice.problem) + %tr + %th Tenant + %td= tenant_graph(notice.problem) -- libgit2 0.21.2