sponsorstats.cgi 2.08 KB
Newer Older
1
#!/usr/bin/ruby
2

3 4
$:.unshift('../rlibs')
require 'udd-db'
5
require 'cgi'
6

lucas's avatar
lucas committed
7
puts "Content-type: text/html; charset=utf-8\n\n"
lucas's avatar
lucas committed
8

9 10
DB = Sequel.connect(UDD_GUEST)
rows = DB["select s.source, s.version, u.changed_by, nmu, signed_by, cl.login
11 12
from sources s, upload_history u, carnivore_emails ce1, carnivore_emails ce2, carnivore_login cl
where s.distribution = 'debian' and s.release = 'sid'
13
and s.source = u.source
14
and s.version = u.version
15 16
and u.changed_by_email = ce1.email
and u.signed_by_email = ce2.email
17
and ce1.id != ce2.id
lucas's avatar
lucas committed
18 19 20
and ce2.id = cl.id
and u.changed_by_email not in (
select email from carnivore_emails, carnivore_login where carnivore_login.id = carnivore_emails.id)
21
"].all.sym2str
22 23 24
names = {}
uploaders = {}
uploads = {}
25
rows.each do |row|
26 27 28 29 30 31 32 33 34 35 36 37
  if not uploaders.has_key?(row['login'])
    uploaders[row['login']] = {}
    names[row['login']] = row['key_id']
    uploads[row['login']] = 0
  end
  uploads[row['login']] += 1
  if not uploaders[row['login']].has_key?(row['changed_by'])
    uploaders[row['login']][row['changed_by']] = []
  end
  uploaders[row['login']][row['changed_by']] << [ row['source'], row['version'], row['nmu'] ]
end

38 39
puts "<!DOCTYPE html><html><head><title>Sponsoring stats</title></head>"
puts "<body>"
lucas's avatar
lucas committed
40
puts "<h1>Sponsoring stats, powered by UDD!</h1>"
lucas's avatar
lucas committed
41
puts "<p>Uploads in <b>bold</b> were NMUs.</p>"
lucas's avatar
lucas committed
42
puts "<p>That excludes uploads done for people who are now DD, even if the upload was done while they were not DD.</p>"
43
puts '<a href="https://salsa.debian.org/qa/udd/blob/master/web/sponsorstats.cgi">source code</a><br/>'
44 45

puts "<ul>"
46
rank = 0
47 48
uploaders.to_a.sort { |a,b| uploads[a[0]] <=> uploads[b[0]] }.reverse.each do |k|
  k, v = k
49 50
  rank += 1
  puts "<li>#{rank}. #{k} -- #{names[k]} (#{uploads[k]} uploads)\n<ul>"
51 52
  v.to_a.sort { |a,b| a[1].length <=> b[1].length }.reverse.each do |k2|
    k2, v = k2
53
    puts "<li>#{CGI.escapeHTML(k2)} (#{v.length} uploads)\n<ul>"
54 55 56 57 58 59 60 61 62 63 64 65 66
    v.each do |u|
      if u[2]
        puts "<li><b>#{u[0]} #{u[1]}</b></li>"
      else
        puts "<li>#{u[0]} #{u[1]}</li>"
      end
    end
    puts "</ul></li>"
  end
  puts "</ul></li>"
end
puts "</ul>"
sth.finish