- puts "</table>"
-
- puts "<h2>Number of users editing over the past...</h2>"
- puts "<table>"
- puts "<tr><th>Data Type</th><th>Day</th><th>Week</th><th>Month</th></tr>"
-
- day_count = Trace.count(:user_id, :distinct => true,
- :conditions => "timestamp > NOW() - '1 DAY'::INTERVAL")
- week_count = Trace.count(:user_id, :distinct => true,
- :conditions => "timestamp > NOW() - '7 DAYS'::INTERVAL")
- month_count = Trace.count(:user_id, :distinct => true,
- :conditions => "timestamp > NOW() - '28 DAYS'::INTERVAL")
-
- puts "<tr><th>GPX Files</th><td>#{day_count}</td><td>#{week_count}</td><td>#{month_count}</td></tr>"
-
- day_count = OldNode.count(:user_id, :distinct => true, :joins => :changeset,
- :conditions => "timestamp > NOW() - '1 DAY'::INTERVAL")
- week_count = OldNode.count(:user_id, :distinct => true, :joins => :changeset,
- :conditions => "timestamp > NOW() - '7 DAYS'::INTERVAL")
- month_count = OldNode.count(:user_id, :distinct => true, :joins => :changeset,
- :conditions => "timestamp > NOW() - '28 DAYS'::INTERVAL")
-
- puts "<tr><th>Nodes</th><td>#{day_count}</td><td>#{week_count}</td><td>#{month_count}</td></tr>"
-
- puts "</table>"
-
- puts "<h2>Top users editing over the past...</h2>"
- puts "<table>"
- puts "<tr><th>Day</th><th>Week</th><th>Month</th></tr>"
-
- day_users = OldNode.count(:conditions => "timestamp > NOW() - '1 DAY'::INTERVAL",
- :joins => :changeset, :group => :user_id,
- :order => "count_all DESC")
- week_users = OldNode.count(:conditions => "timestamp > NOW() - '7 DAYS'::INTERVAL",
- :joins => :changeset, :group => :user_id,
- :order => "count_all DESC", :limit => 60)
- month_users = OldNode.count(:conditions => "timestamp > NOW() - '28 DAYS'::INTERVAL",
- :joins => :changeset, :group => :user_id,
- :order => "count_all DESC", :limit => 60)
-
- SyncEnumerator.new(day_users, week_users, month_users).each do |row|
- puts "<tr>"
- row.each do |column|
- if column.nil?
- puts "<td></td>"
- else
- display_name = User.find(column[0]).display_name.gsub('@', ' at ').gsub('.', ' dot ')
- count = column[1]
- puts "<td>#{count} <a href=\"/user/#{display_name}\">#{display_name}</a></td>"
+ puts "<tr><th>Nodes</th><td>#{day_count}</td><td>#{week_count}</td><td>#{month_count}</td></tr>"
+
+ puts "</table>"
+
+ puts '<h2 id="top-editors">Top users editing over the past...</h2>'
+ puts "<table>"
+ puts "<tr><th>Day</th><th>Week</th><th>Month</th></tr>"
+
+ day_users = OldNode.where("timestamp > NOW() - '1 DAY'::INTERVAL").joins(:changeset).order("count_all DESC").group(:user_id).count
+ week_users = OldNode.where("timestamp > NOW() - '7 DAYS'::INTERVAL").joins(:changeset).order("count_all DESC").limit(60).group(:user_id).count
+ month_users = OldNode.where("timestamp > NOW() - '28 DAYS'::INTERVAL").joins(:changeset).order("count_all DESC").limit(60).group(:user_id).count
+
+ day_users.zip(week_users, month_users).each do |row|
+ puts "<tr>"
+ row.each do |column|
+ if column.nil?
+ puts "<td></td>"
+ else
+ display_name = User.find(column[0]).display_name.gsub("@", " at ").gsub(".", " dot ")
+ count = column[1]
+ puts "<td>#{count} <a href=\"https://www.openstreetmap.org/user/#{display_name}\">#{display_name}</a></td>"
+ end