import locale from gittip import db def rows(goals, backed): for rec in goals: so_far = backed.get(rec['id'], 0) row = [ rec['id'] , rec['goal'] , so_far , (so_far / rec['goal']) * 100 , rec['statement'] ] yield row def sortfunc(a, b): percentage = cmp(a[3], b[3]) if percentage != 0: # percentage descending return percentage * -1 else: # goal, id ascending return cmp((a[1], a[0]), (b[1], a[1])) # ==== ^L ngoals = db.fetchone("SELECT count(id) FROM participants WHERE goal > 0") ngoals = ngoals['count'] if ngoals is not None else 0 goals = db.fetchall(""" \ SELECT id, statement, goal FROM participants WHERE goal > 0 ORDER BY goal DESC """) goals = goals if goals is not None else [] backed = db.fetchall(""" SELECT tippee as id, sum(amount) as amount FROM ( SELECT DISTINCT ON (tipper, tippee) tippee, amount FROM tips JOIN participants p ON p.id = tipper JOIN participants p2 ON p2.id = tippee WHERE p.last_bill_result = '' AND p2.claimed_time IS NOT NULL ORDER BY tipper, tippee, mtime DESC ) AS foo GROUP BY tippee """) backed = backed if backed is not None else [] backed = {rec['id']:rec['amount'] for rec in backed} rows = list(rows(goals, backed)) rows.sort(cmp=sortfunc) # ==== ^L {% extends templates/base.html %} {% block page %}
| Participant | Goal ($) | Backed ($, %) | |
|---|---|---|---|
| {{ participant_id }} | {{ locale.format("%.2f", goal, grouping=True) }} | {{ locale.format("%.2f", backed, grouping=True) }} | {{ "%5.1f" % percentage }} |
{{ statement }}
| |||