<commit_before>import locale
from gittip import db

^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, goal FROM participants WHERE goal > 0 ORDER BY goal DESC")
goals = goals if goals is not None else []

^L

{% extends templates/base.html %}
{% block body %}
<p class="below-header"><a href="./">About</a></p>

<h2>{{ ngoals}} people have set a funding goal.</h2>
<table>
    {% for rec in goals %}
    <tr>
        <th><a href="/{{ rec['id'] }}/">{{ rec['id'] }}</a></th>
        <td>{{ locale.format("%.2f", rec['goal'], grouping=True) }}</a></td>
    </tr>
    {% end %}
</table>
{% end %}<commit_msg>Add backed and percentage to goals.html (#217)<commit_after>import locale
from gittip import db

# ==== ^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, goal
      FROM participants
     WHERE goal > 0
  ORDER BY goal DESC

""")
goals = goals if goals is not None else []

backed = db.fetchall("""
        SELECT tippee, sum(amount) AS backed
          FROM ( SELECT DISTINCT ON (tipper)
                        amount
                      , tipper
                      , tippee
                   FROM tips
                   JOIN participants p ON p.id = tipper
                    AND last_bill_result = ''
               GROUP BY tipper, tippee, amount, mtime
               ORDER BY tipper
                      , mtime DESC
                ) AS foo
      GROUP BY tippee
""")
if backed is None:
    backed == {}
else:
    _backed = {}
    for rec in backed:
        _backed[rec['tippee']] = rec['backed']
    backed = _backed


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
               ]
        yield row
rows = list(rows(goals, backed))

def sortfunc(a, b):
    percentage = cmp(a[3], b[3])
    if percentage != 0:
        return percentage * -1
    else:
        return cmp((a[1], a[0]), (b[1], a[1]))

rows.sort(cmp=sortfunc)


# ==== ^L
{% extends templates/base.html %}
{% block body %}
<p class="below-header"><a href="./">About</a></p>
<style>
    TH, TD {
        padding-right: 1em;
    }
</style>

<h2>{{ ngoals}} people have set a funding goal.</h2>
<table>
    <tr>
        <th>Participant</th>
        <th style="text-align: right;">Goal ($)</a></th>
        <th colspan="2">Backed ($, %)</a></th>
    </tr>
    {% for participant_id, goal, backed, percentage in rows %}
    <tr>
        <th><a href="/{{ participant_id }}/">{{ participant_id }}</a></th>
        <td>{{ locale.format("%.2f", goal, grouping=True) }}</td>
        <td>{{ locale.format("%.2f", backed, grouping=True) }}</td>
        <td>{{ "%5.1f" % percentage }}</td>
    </tr>
    {% end %}
</table>
{% end %}
{'fraction_non_alphanumeric': 0.17314722499169158, 'fraction_numerical': 0.010634762379528082, 'mean_word_length': 2.1751054852320677, 'pattern_counts': {'":': 0, '<': 52, '<?xml version=': 0, '>': 56, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3997619', 'n_tokens_mistral': 1068, 'n_tokens_neox': 980, 'n_words': 294}