Commit fb03e5a1739c9d6c1b238862b21657e99b3e5294
1 parent
42a2543f
Exists in
master
and in
1 other branch
Tidied whitespace & indentation
Showing
1 changed file
with
13 additions
and
24 deletions
Show diff stats
app/helpers/application_helper.rb
1 | module ApplicationHelper | 1 | module ApplicationHelper |
2 | - | ||
3 | - | ||
4 | - | ||
5 | def message_graph(problem) | 2 | def message_graph(problem) |
6 | create_percentage_table_for(problem) {|notice| notice.message} | 3 | create_percentage_table_for(problem) {|notice| notice.message} |
7 | end | 4 | end |
8 | - | ||
9 | - | ||
10 | - | 5 | + |
11 | def user_agent_graph(problem) | 6 | def user_agent_graph(problem) |
12 | create_percentage_table_for(problem) {|notice| pretty_user_agent(notice.user_agent)} | 7 | create_percentage_table_for(problem) {|notice| pretty_user_agent(notice.user_agent)} |
13 | end | 8 | end |
14 | - | 9 | + |
15 | def pretty_user_agent(user_agent) | 10 | def pretty_user_agent(user_agent) |
16 | (user_agent.nil? || user_agent.none?) ? "N/A" : "#{user_agent.browser} #{user_agent.version}" | 11 | (user_agent.nil? || user_agent.none?) ? "N/A" : "#{user_agent.browser} #{user_agent.version}" |
17 | end | 12 | end |
18 | - | ||
19 | - | ||
20 | - | 13 | + |
21 | def tenant_graph(problem) | 14 | def tenant_graph(problem) |
22 | create_percentage_table_for(problem) {|notice| get_host(notice.request['url'])} | 15 | create_percentage_table_for(problem) {|notice| get_host(notice.request['url'])} |
23 | end | 16 | end |
24 | - | 17 | + |
25 | def get_host(url) | 18 | def get_host(url) |
26 | begin | 19 | begin |
27 | uri = url && URI.parse(url) | 20 | uri = url && URI.parse(url) |
@@ -30,14 +23,13 @@ module ApplicationHelper | @@ -30,14 +23,13 @@ module ApplicationHelper | ||
30 | "N/A" | 23 | "N/A" |
31 | end | 24 | end |
32 | end | 25 | end |
33 | - | ||
34 | - | ||
35 | - | 26 | + |
27 | + | ||
36 | def create_percentage_table_for(problem, &block) | 28 | def create_percentage_table_for(problem, &block) |
37 | tallies = tally(problem.notices, &block) | 29 | tallies = tally(problem.notices, &block) |
38 | create_percentage_table_from_tallies(tallies, :total => problem.notices.count) | 30 | create_percentage_table_from_tallies(tallies, :total => problem.notices.count) |
39 | end | 31 | end |
40 | - | 32 | + |
41 | def tally(collection, &block) | 33 | def tally(collection, &block) |
42 | collection.inject({}) do |tallies, item| | 34 | collection.inject({}) do |tallies, item| |
43 | value = yield item | 35 | value = yield item |
@@ -45,7 +37,7 @@ module ApplicationHelper | @@ -45,7 +37,7 @@ module ApplicationHelper | ||
45 | tallies | 37 | tallies |
46 | end | 38 | end |
47 | end | 39 | end |
48 | - | 40 | + |
49 | def create_percentage_table_from_tallies(tallies, options={}) | 41 | def create_percentage_table_from_tallies(tallies, options={}) |
50 | total = (options[:total] || total_from_tallies(tallies)) | 42 | total = (options[:total] || total_from_tallies(tallies)) |
51 | percent = 100.0 / total.to_f | 43 | percent = 100.0 / total.to_f |
@@ -53,13 +45,10 @@ module ApplicationHelper | @@ -53,13 +45,10 @@ module ApplicationHelper | ||
53 | .sort {|a, b| a[0] <=> b[0]} | 45 | .sort {|a, b| a[0] <=> b[0]} |
54 | render :partial => "errs/tally_table", :locals => {:rows => rows} | 46 | render :partial => "errs/tally_table", :locals => {:rows => rows} |
55 | end | 47 | end |
56 | - | ||
57 | - | ||
58 | - def total_from_tallies(tallies) | ||
59 | - tallies.values.inject(0) {|sum, n| sum + n} | ||
60 | - end | ||
61 | - private :total_from_tallies | ||
62 | - | ||
63 | - | 48 | + |
49 | + private | ||
50 | + def total_from_tallies(tallies) | ||
51 | + tallies.values.inject(0) {|sum, n| sum + n} | ||
52 | + end | ||
64 | end | 53 | end |
65 | 54 |