Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Merge pull request #1377 from zwn/master
Browse files Browse the repository at this point in the history
Show number of active weekly users and $ transferred in the headline of each page.
  • Loading branch information
chadwhitacre committed Sep 6, 2013
2 parents 1ec6781 + 2260052 commit 76dee91
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
13 changes: 13 additions & 0 deletions branch.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-------------------------------------------------------------------------------
-- https://github.com/gittip/www.gittip.com/issues/703

ALTER TABLE paydays
ADD COLUMN nactive bigint DEFAULT 0;

UPDATE paydays SET nactive=(
SELECT count(DISTINCT foo.*) FROM (
SELECT tipper FROM transfers WHERE "timestamp" >= ts_start AND "timestamp" < ts_end
UNION
SELECT tippee FROM transfers WHERE "timestamp" >= ts_start AND "timestamp" < ts_end
) AS foo
);
4 changes: 4 additions & 0 deletions configure-aspen.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import locale
import os
import threading
import time
Expand Down Expand Up @@ -88,6 +89,9 @@ def add_stuff(request):
request.context['github'] = github
request.context['twitter'] = twitter
request.context['bountysource'] = bountysource
stats = gittip.db.one('SELECT nactive, transfer_volume FROM paydays ORDER BY ts_end DESC LIMIT 1', default=(0, 0.0))
request.context['gnactive'] = locale.format("%d", stats[0], grouping=True)
request.context['gtransfer_volume'] = locale.format("%d", round(stats[1], -2), grouping=True)

website.hooks.inbound_early += [add_stuff]

Expand Down
16 changes: 16 additions & 0 deletions gittip/billing/payday.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def run(self):
self.pachinko(ts_start, self.genparticipants(ts_start, ts_start))
self.clear_pending_to_balance()
self.payout(ts_start, self.genparticipants(ts_start, False))
self.set_nactive(ts_start)

self.end()

Expand Down Expand Up @@ -349,6 +350,21 @@ def clear_pending_to_balance(self):
log("Cleared pending to balance. Ready for payouts.")


def set_nactive(self, ts_start):
self.db.run("""\
UPDATE paydays
SET nactive=(
SELECT count(DISTINCT foo.*) FROM (
SELECT tipper FROM transfers WHERE "timestamp" >= %(ts_start)s
UNION
SELECT tippee FROM transfers WHERE "timestamp" >= %(ts_start)s
) AS foo
)
WHERE ts_end='1970-01-01T00:00:00+00'::timestamptz
""", {'ts_start': ts_start})

def end(self):
self.db.one("""\
Expand Down
2 changes: 1 addition & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ <h1>
</a>
</h1>
</td><td class="motto luxury">
Distributed Genius Grants
{{ gnactive }} users exchanging ${{ gtransfer_volume }} per week
</td></tr></table>
{% if user.ANON %}
{% include sign-in-using.html %}
Expand Down
5 changes: 3 additions & 2 deletions tests/test_billing_payday.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ def setUp(self):
self.payday = Payday(self.db)

def get_numbers(self):
"""Return a list of 9 ints:
"""Return a list of 10 ints:
nachs
nach_failing
nactive
ncc_failing
ncc_missing
ncharges
Expand All @@ -59,7 +60,7 @@ def test_charge_without_cc_marked_as_failure(self):
self.payday.start()
self.payday.charge(alice, Decimal('1.00'))
actual = self.get_numbers()
assert_equals(actual, [0, 0, 0, 1, 0, 0, 0, 0, 0, 0])
assert_equals(actual, [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0])

@mock.patch('gittip.billing.payday.Payday.charge_on_balanced')
def test_charge_failure_returns_None(self, cob):
Expand Down

0 comments on commit 76dee91

Please sign in to comment.