]> git.openstreetmap.org Git - rails.git/blob - script/statistics
Salt passwords so that two users with the same password will have
[rails.git] / script / statistics
1 #!/usr/bin/env ruby
2
3 require File.dirname(__FILE__) + '/../config/environment'
4 require 'generator'
5
6 start_time = Time.now
7
8 puts "<html>"
9 puts "<head>"
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>"
13 puts "</head>"
14 puts "<body>"
15 puts "<h2>OpenStreetMap stats report run at #{start_time.to_s}</h2>"
16
17 begin
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 => "visible = true AND EXISTS (SELECT * FROM current_way_tags WHERE id = current_ways.id AND k <> 'created_by')")
24
25   puts "<table>"
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 segments</td><td>#{segment_count}</td></tr>"
30   puts "<tr><td>Number of ways</td><td>#{way_count}</td></tr>"
31   puts "<tr><td>Number of ways with tags</td><td>#{tagged_way_count}</td></tr>"
32   puts "</table>"
33
34   puts "<h2>Top 50 users for uploads of GPS data</h2>"
35   puts "<table>"
36   puts "<tr><th>User</th><th>Number of Points</th></tr>"
37
38   Trace.sum(:size, :group => :user_id, :order => "sum_size DESC", :limit => 50).each do |user, count|
39     display_name = User.find(user).display_name.gsub('@', ' at ').gsub('.', ' dot ')
40     puts "<tr><td>#{display_name}</td><td>#{count}</td></tr>"
41   end
42
43   puts "</table>"
44
45   puts "<h2>Number of users editing over the past...</h2>"
46   puts "<table>"
47   puts "<tr><th>Data Type</th><th>Day</th><th>Week</th><th>Month</th></tr>"
48
49   day_count = Trace.count(:user_id, :distinct => true, 
50                           :conditions => "timestamp > NOW() - INTERVAL 1 DAY")
51   week_count = Trace.count(:user_id, :distinct => true, 
52                            :conditions => "timestamp > NOW() - INTERVAL 7 DAY")
53   month_count = Trace.count(:user_id, :distinct => true, 
54                             :conditions => "timestamp > NOW() - INTERVAL 28 DAY")
55
56   puts "<tr><th>GPX Files</th><td>#{day_count}</td><td>#{week_count}</td><td>#{month_count}</td></tr>"
57
58   day_count = OldNode.count(:user_id, :distinct => true, 
59                             :conditions => "timestamp > NOW() - INTERVAL 1 DAY")
60   week_count = OldNode.count(:user_id, :distinct => true, 
61                              :conditions => "timestamp > NOW() - INTERVAL 7 DAY")
62   month_count = OldNode.count(:user_id, :distinct => true, 
63                               :conditions => "timestamp > NOW() - INTERVAL 28 DAY")
64
65   puts "<tr><th>Nodes</th><td>#{day_count}</td><td>#{week_count}</td><td>#{month_count}</td></tr>"
66
67   puts "</table>"
68   
69   puts "<h2>Top users editing over the past...</h2>"
70   puts "<table>"
71   puts "<tr><th>Day</th><th>Week</th><th>Month</th></tr>"
72
73   day_users = OldNode.count(:conditions => "timestamp > NOW() - INTERVAL 1 DAY",
74                             :group => :user_id, :order => "count_all DESC")
75   week_users = OldNode.count(:conditions => "timestamp > NOW() - INTERVAL 7 DAY",
76                              :group => :user_id, :order => "count_all DESC", :limit => 60)
77   month_users = OldNode.count(:conditions => "timestamp > NOW() - INTERVAL 28 DAY",
78                               :group => :user_id, :order => "count_all DESC", :limit => 60)
79
80   SyncEnumerator.new(day_users, week_users, month_users).each do |row|
81     puts "<tr>"
82     row.each do |column|
83       if column.nil?
84         puts "<td></td>"
85       else
86         display_name = User.find(column[0]).display_name.gsub('@', ' at ').gsub('.', ' dot ')
87         count = column[1]
88         puts "<td>#{count} #{display_name}</td>"
89       end
90     end
91     puts "</tr>"
92   end
93
94   puts "</table>"
95 rescue Exception => e
96   puts "<p><em>Exception: #{e.to_s}</em><br />#{e.backtrace.join('<br />')}</p>"
97 end
98
99 puts "<p>Report took #{(Time.new - start_time).to_s} seconds to run</p>"
100 puts "</body>"
101 puts "</html>"