3 require File.dirname(__FILE__) + '/../config/environment'
10 puts "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />"
11 puts "<title>OpenStreetMap Statistics</title>"
12 puts "<style>th { text-align: left }</style>"
15 puts "<h2>OpenStreetMap stats report run at #{start_time.to_s}</h2>"
18 user_count = User.count(:conditions => "active = true")
19 tracepoint_count = Tracepoint.count()
20 node_count = Node.count() # :conditions => "visible = true")
21 segment_count = Segment.count() # :conditions => "visible = true")
22 way_count = Way.count() # :conditions => "visible = true")
23 tagged_way_count = Way.count(:conditions => "current_ways.visible = true AND current_way_tags.k <> 'created_by'",
24 :joins => "INNER JOIN current_way_tags ON current_way_tags.id = current_ways.id")
27 puts "<tr><td>Number of users</td><td>#{user_count}</td></tr>"
28 puts "<tr><td>Number of uploaded GPS points</td><td>#{tracepoint_count}</td></tr>"
29 puts "<tr><td>Number of nodes</td><td>#{node_count}</td></tr>"
30 puts "<tr><td>Number of segments</td><td>#{segment_count}</td></tr>"
31 puts "<tr><td>Number of ways</td><td>#{way_count}</td></tr>"
32 puts "<tr><td>Number of ways with tags</td><td>#{tagged_way_count}</td></tr>"
35 puts "<h2>Top 10 users for uploads of GPS data</h2>"
37 puts "<tr><th>User</th><th>Number of Points</th></tr>"
39 Trace.sum(:size, :group => :user_id, :order => "sum_size DESC", :limit => 10).each do |user, count|
40 display_name = User.find(user).display_name.gsub('@', ' at ').gsub('.', ' dot ')
41 puts "<tr><td>#{display_name}</td><td>#{count}</td></tr>"
46 puts "<h2>Number of users editing over the past...</h2>"
48 puts "<tr><th>Data Type</th><th>Day</th><th>Week</th><th>Month</th></tr>"
50 day_count = Trace.count(:user_id, :distinct => true,
51 :conditions => "timestamp > NOW() - INTERVAL 1 DAY")
52 week_count = Trace.count(:user_id, :distinct => true,
53 :conditions => "timestamp > NOW() - INTERVAL 7 DAY")
54 month_count = Trace.count(:user_id, :distinct => true,
55 :conditions => "timestamp > NOW() - INTERVAL 28 DAY")
57 puts "<tr><th>GPX Files</th><td>Day</td><td>#{day_count}</td></tr>"
58 puts "<tr><th>GPX Files</th><td>Week</td><td>#{week_count}</td></tr>"
59 puts "<tr><th>GPX Files</th><td>Month</td><td>#{month_count}</td></tr>"
61 day_count = OldNode.count(:user_id, :distinct => true,
62 :conditions => "timestamp > NOW() - INTERVAL 1 DAY")
63 week_count = OldNode.count(:user_id, :distinct => true,
64 :conditions => "timestamp > NOW() - INTERVAL 7 DAY")
65 month_count = OldNode.count(:user_id, :distinct => true,
66 :conditions => "timestamp > NOW() - INTERVAL 28 DAY")
68 puts "<tr><th>Nodes</th><td>Day</td><td>#{day_count}</td></tr>"
69 puts "<tr><th>Nodes</th><td>Week</td><td>#{week_count}</td></tr>"
70 puts "<tr><th>Nodes</th><td>Month</td><td>#{month_count}</td></tr>"
74 puts "<h2>Top users editing over the past...</h2>"
76 puts "<tr><th>Day</th><th>Week</th><th>Month</th></tr>"
78 day_users = OldNode.count(:conditions => "timestamp > NOW() - INTERVAL 1 DAY",
79 :group => :user_id, :order => "count_all DESC", :limit => 60)
80 week_users = OldNode.count(:conditions => "timestamp > NOW() - INTERVAL 7 DAY",
81 :group => :user_id, :order => "count_all DESC", :limit => 60)
82 month_users = OldNode.count(:conditions => "timestamp > NOW() - INTERVAL 28 DAY",
83 :group => :user_id, :order => "count_all DESC", :limit => 60)
85 day_users = day_users.keys.map { |u| User.find(u).display_name.gsub('@', ' at ').gsub('.', ' dot ') }
86 week_users = week_users.keys.map { |u| User.find(u).display_name.gsub('@', ' at ').gsub('.', ' dot ') }
87 month_users = month_users.keys.map { |u| User.find(u).display_name.gsub('@', ' at ').gsub('.', ' dot ') }
89 SyncEnumerator.new(day_users, week_users, month_users).each do |day,week,month|
90 puts "<tr><td>#{day}</td><td>#{week}</td><td>#{month}</td></tr>"
95 puts "<p><em>Exception: #{e.to_s}</em><br />#{e.backtrace.join('<br />')}</p>"
98 puts "<p>Report took #{(Time.new - start_time).to_s} seconds to run</p>"