web/hgbook/reviewers.py
author amit@thunder
Mon, 25 Jan 2010 18:56:45 +0530
changeset 0 8083d21c0020
permissions -rwxr-xr-x
The first commit of all the required files for the review app
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     1
#!/usr/bin/env python
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     3
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     4
import os, sys
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     5
sys.path.append(os.path.dirname(__file__))
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     6
import dbutil
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     7
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     8
conn = dbutil.connect()
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     9
c = conn.cursor()
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    10
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    11
c.execute('''select submitter_name from comments_comment''')
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    12
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    13
reviewers = {}
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    14
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    15
mappings = {
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    16
    u'alejandro "tab-lover" dubrovsky': u'Alejandro Dubrovsky',
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    17
    u'alex hirzel <ahirzel@mtu.edu>': u'Alex Hirzel',
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    18
    u'anonymous coward': u'Anonymous',
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    19
    u'arthur van leeuwen': u'Arthur van Leeuwen',
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    20
    u'augustss': u'Lennart Augustsson',
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    21
    u'ed t': u'Anonymous',
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    22
    u'geogre moschovitis': u'George Moschovitis',
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    23
    u'george m': u'George Moschovitis',
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    24
    u'haskell newb': u'Anonymous',
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    25
    u'j. pablo fernandez': u'J. Pablo Fernández',
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    26
    u'kamal al-marhoobi': u'Kamal Al-Marhubi',
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    27
    u'kevin w.': u'Kevin Watters',
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    28
    u'max cantor (#haskell - mxc)': u'Max Cantor',
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    29
    u'michael campbell': u'Michael Campbell',
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    30
    u'mike btauwerman': u'Mike Brauwerman',
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    31
    u'no credit necessary': u'Anonymous',
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    32
    u'nykänen, matti': u'Matti Nykänen',
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    33
    u'omar antolin camarena': u'Omar Antolín Camarena',
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    34
    u'ryan t mulligan': u'Ryan T. Mulligan',
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    35
    u'sengan baring-gould': u'Sengan Baring-Gould',
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    36
    u'some guy': u'Anonymous',
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    37
    u'tomas janousek': u'Tomáš Janoušek',
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    38
    u'william halchin': u'William N. Halchin',
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    39
    }
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    40
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    41
def fixup(s):
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    42
    try:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    43
        return s.encode('ascii')
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    44
    except UnicodeEncodeError:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    45
        def f(c):
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    46
            o = ord(c)
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    47
            if o < 128:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    48
                return c
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    49
            return '&#%d;' % o
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    50
        return ''.join(map(f, s))
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    51
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    52
total = 0
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    53
for r in c.fetchall():
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    54
    r = r[0].decode('utf-8')
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    55
    if r in ("Bryan O'Sullivan",):
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    56
        continue
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    57
    total += 1
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    58
    m = mappings.get(r.lower())
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    59
    if m:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    60
        r = m
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    61
    elif len(r) < 2 or ' ' not in r:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    62
        r = 'Anonymous'
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    63
    reviewers.setdefault(r, 0)
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    64
    reviewers[r] += 1
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    65
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    66
reviewers = sorted(reviewers.iteritems(), key=lambda x: x[0])
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    67
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    68
cohorts = [(.01,1),(.002,.01)]
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    69
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    70
for (lo,hi) in cohorts:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    71
    lo = total * lo
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    72
    hi = total * hi
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    73
    for r in [n for n in reviewers if lo <= n[1] < hi]:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    74
        if r[1] > 3:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    75
            print '%s,' % fixup(r[0])
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    76
    print
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    77
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    78
lo = total * .002
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    79
for n in reviewers:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    80
    if n[1] < lo:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    81
        print '%s,' % fixup(n[0])