3 require File.join(File.dirname(__FILE__), "..", "config", "environment")
5 start_time = Time.now.utc
9 puts "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />"
10 puts "<title>OpenStreetMap Statistics</title>"
11 puts "<style>th { text-align: left }</style>"
14 puts "<h1>OpenStreetMap stats</h1>"
15 puts "<h2>Report run at #{start_time}</h2>"
18 ActiveRecord::Base.transaction do
19 user_count = User.where(:status => %w[active confirmed suspended]).count
20 tracepoint_count = Tracepoint.count
21 node_count = Node.where(:visible => true).count
22 way_count = Way.where(:visible => true).count
23 relation_count = Relation.where(:visible => true).count
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 id="top-traces">Top 50 users for uploads of GPS data</h2>'
35 puts "<tr><th>User</th><th>Number of Points</th></tr>"
37 Trace.where(:inserted => true).group(:user_id).order("sum_size DESC").limit(50).sum(:size).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 id="number-of-editors">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.where("timestamp > NOW() - '1 DAY'::INTERVAL").distinct.count(:user_id)
49 week_count = Trace.where("timestamp > NOW() - '7 DAYS'::INTERVAL").distinct.count(:user_id)
50 month_count = Trace.where("timestamp > NOW() - '28 DAYS'::INTERVAL").distinct.count(:user_id)
52 puts "<tr><th>GPX Files</th><td>#{day_count}</td><td>#{week_count}</td><td>#{month_count}</td></tr>"
54 day_count = OldNode.where("timestamp > NOW() - '1 DAY'::INTERVAL").joins(:changeset).distinct.count(:user_id)
55 week_count = OldNode.where("timestamp > NOW() - '7 DAYS'::INTERVAL").joins(:changeset).distinct.count(:user_id)
56 month_count = OldNode.where("timestamp > NOW() - '28 DAYS'::INTERVAL").joins(:changeset).distinct.count(:user_id)
58 puts "<tr><th>Nodes</th><td>#{day_count}</td><td>#{week_count}</td><td>#{month_count}</td></tr>"
62 puts '<h2 id="top-editors">Top users editing over the past...</h2>'
64 puts "<tr><th>Day</th><th>Week</th><th>Month</th></tr>"
66 day_users = OldNode.where("timestamp > NOW() - '1 DAY'::INTERVAL").joins(:changeset).order("count_all DESC").group(:user_id).count
67 week_users = OldNode.where("timestamp > NOW() - '7 DAYS'::INTERVAL").joins(:changeset).order("count_all DESC").limit(60).group(:user_id).count
68 month_users = OldNode.where("timestamp > NOW() - '28 DAYS'::INTERVAL").joins(:changeset).order("count_all DESC").limit(60).group(:user_id).count
70 day_users.zip(week_users, month_users).each do |row|
76 display_name = User.find(column[0]).display_name.gsub("@", " at ").gsub(".", " dot ")
78 puts "<td>#{count} <a href=\"/user/#{display_name}\">#{display_name}</a></td>"
86 rescue StandardError => e
87 puts "<p><em>Exception: #{e}</em><br />#{e.backtrace.join('<br />')}</p>"
90 puts "<p>Report took #{Time.now.utc - start_time} seconds to run</p>"