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 ActiveRecord::Base.transaction do
19 user_count = User.count(:conditions => "active = 1")
20 tracepoint_count = Tracepoint.count()
21 node_count = Node.count(:conditions => "visible = true")
22 way_count = Way.count(:conditions => "visible = true")
23 relation_count = Relation.count(:conditions => "visible = true")
26 puts "<tr><td>Number of users</td><td>#{user_count}</td></tr>"
27 puts "<tr><td>Number of uploaded GPS points</td><td>#{tracepoint_count}</td></tr>"
28 puts "<tr><td>Number of nodes</td><td>#{node_count}</td></tr>"
29 puts "<tr><td>Number of ways</td><td>#{way_count}</td></tr>"
30 puts "<tr><td>Number of relations</td><td>#{relation_count}</td></tr>"
33 puts "<h2>Top 50 users for uploads of GPS data</h2>"
35 puts "<tr><th>User</th><th>Number of Points</th></tr>"
37 Trace.sum(:size, :conditions => { :inserted => true }, :group => :user_id, :order => "sum_size DESC", :limit => 50).each do |user, count|
38 display_name = User.find(user).display_name.gsub('@', ' at ').gsub('.', ' dot ')
39 puts "<tr><td><a href=\"/user/#{display_name}\">#{display_name}</a></td><td>#{count}</td></tr>"
44 puts "<h2>Number of users editing over the past...</h2>"
46 puts "<tr><th>Data Type</th><th>Day</th><th>Week</th><th>Month</th></tr>"
48 day_count = Trace.count(:user_id, :distinct => true,
49 :conditions => "timestamp > NOW() - '1 DAY'::INTERVAL")
50 week_count = Trace.count(:user_id, :distinct => true,
51 :conditions => "timestamp > NOW() - '7 DAYS'::INTERVAL")
52 month_count = Trace.count(:user_id, :distinct => true,
53 :conditions => "timestamp > NOW() - '28 DAYS'::INTERVAL")
55 puts "<tr><th>GPX Files</th><td>#{day_count}</td><td>#{week_count}</td><td>#{month_count}</td></tr>"
57 day_count = OldNode.count(:user_id, :distinct => true, :joins => :changeset,
58 :conditions => "timestamp > NOW() - '1 DAY'::INTERVAL")
59 week_count = OldNode.count(:user_id, :distinct => true, :joins => :changeset,
60 :conditions => "timestamp > NOW() - '7 DAYS'::INTERVAL")
61 month_count = OldNode.count(:user_id, :distinct => true, :joins => :changeset,
62 :conditions => "timestamp > NOW() - '28 DAYS'::INTERVAL")
64 puts "<tr><th>Nodes</th><td>#{day_count}</td><td>#{week_count}</td><td>#{month_count}</td></tr>"
68 puts "<h2>Top users editing over the past...</h2>"
70 puts "<tr><th>Day</th><th>Week</th><th>Month</th></tr>"
72 day_users = OldNode.count(:conditions => "timestamp > NOW() - '1 DAY'::INTERVAL",
73 :joins => :changeset, :group => :user_id,
74 :order => "count_all DESC")
75 week_users = OldNode.count(:conditions => "timestamp > NOW() - '7 DAYS'::INTERVAL",
76 :joins => :changeset, :group => :user_id,
77 :order => "count_all DESC", :limit => 60)
78 month_users = OldNode.count(:conditions => "timestamp > NOW() - '28 DAYS'::INTERVAL",
79 :joins => :changeset, :group => :user_id,
80 :order => "count_all DESC", :limit => 60)
82 SyncEnumerator.new(day_users, week_users, month_users).each do |row|
88 display_name = User.find(column[0]).display_name.gsub('@', ' at ').gsub('.', ' dot ')
90 puts "<td>#{count} <a href=\"/user/#{display_name}\">#{display_name}</a></td>"
99 puts "<p><em>Exception: #{e.to_s}</em><br />#{e.backtrace.join('<br />')}</p>"
102 puts "<p>Report took #{(Time.new - start_time).to_s} seconds to run</p>"