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

Commit

Permalink
Switch from Active Users to Givers
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed Oct 24, 2014
1 parent 834108e commit 0b4f6fa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 39 deletions.
4 changes: 2 additions & 2 deletions www/about/charts.json.spt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ charts = website.db.all("""\

SELECT ts_start::date AS date
, nparticipants AS total_users
, nactive AS active_users
, ((nactive::float / nparticipants) * 10000)::int AS active_ratio
, ntippers AS givers
, ((ntippers::float / nparticipants) * 10000)::int AS giver_ratio
, ( SELECT sum(transfer_volume)
FROM paydays
WHERE ts_start <= p.ts_start
Expand Down
18 changes: 9 additions & 9 deletions www/about/charts.spt
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ $(document).ready(function() {

<div class="chart-wrapper">
<a name="active"></a>
<h2>Active Users</h2>
<p class="note">Users that gave and/or received money within Gratipay (per week)</p>
<div class="chart bar" id="chart_active_users"></div>
<h2>Givers</h2>
<p class="note">Users that gave money using Gratipay (per week)</p>
<div class="chart bar" id="chart_givers"></div>
<div class="x-axis">weeks</div>
</div>

<div class="chart-wrapper">
<a name="pactive"></a>
<h2>Active Ratio</h2>
<p class="note">Active users per 10,000 total users</p>
<div class="chart bar" id="chart_active_ratio" data-y-max="1500"></div>
<h2>Giver Ratio</h2>
<p class="note">Givers per 10,000 total users</p>
<div class="chart bar" id="chart_giver_ratio" data-y-max="1500" data-max-since="8"></div>
<div class="x-axis">weeks</div>
</div>

<div class="chart-wrapper">
<a name="cohort"></a>
<h2>Cohort Size and Retention</h2>
<p class="note">The number of new active users per week, and their activity over time</p>
<div class="chart bar" id="chart_new_users"></div>
<h2>Giver Cohorts</h2>
<p class="note">The number of new givers per week, and their activity over time</p>
<div class="chart bar" id="chart_new_givers"></div>
<div class="x-axis"></div>
<div class="chart retention" id="chart_retention"></div>
</div>
Expand Down
53 changes: 25 additions & 28 deletions www/about/retention.json.spt
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
from collections import defaultdict

def get_cohorts():
transfers = website.db.all("select timestamp::date as date, tippee, tipper "
"from transfers where context='tip' or context='take' "
"order by timestamp", back_as=dict)
transfers = website.db.all("select timestamp::date as date, tipper as username "
"from transfers where context='tip' order by timestamp")

usermap = {}
cohorts = defaultdict(list)

for transfer in transfers:
date = transfer['date']
for username in (transfer['tipper'], transfer['tippee']):
if username not in usermap:
usermap[username] = [date, date]
cohorts[date].append(username)
else:
usermap[username][1] = date
for date, username in transfers:
if username not in usermap:
usermap[username] = [date, date]
cohorts[date].append(username)
else:
usermap[username][1] = date

return usermap, cohorts

Expand All @@ -27,31 +24,31 @@ if bool(qs.get('recompute', 0)):
usermap, cohorts = get_cohorts()


# Compute a retentions distribution for each cohort.
# ==================================================
# Compute the retention for each cohort.
# ======================================

new_users = []
distributions = []
for date, users in sorted(cohorts.items()):
new_givers = []
retentions = []
for date, givers in sorted(cohorts.items()):

distribution = defaultdict(int)
for username in users:
retention = defaultdict(int)
for username in givers:
start, end = usermap[username]
nweeks = (end - start).days // 7
for n in range(nweeks, -1, -1):
distribution[n] += 1
retention[n] += 1

max_weeks = max(distribution.keys())
tusers = len(users)
new_users.append({'new_users': tusers}) # formatted to work with charts.js
max_weeks = max(retention.keys())
tgivers = len(givers)
new_givers.append({'new_givers': tgivers}) # formatted to work with charts.js

distributions.append([])
retentions.append([])
for nweeks in range(0, max_weeks+1):
nusers = distribution.get(nweeks, 0)
pusers = nusers / tusers
pusers = float('{:.3}'.format(pusers))
distributions[-1].append((pusers, nusers))
ngivers = retention.get(nweeks, 0)
pgivers = ngivers / tgivers
pgivers = float('{:.3}'.format(pgivers))
retentions[-1].append((pgivers, ngivers))

response.headers["Access-Control-Allow-Origin"] = "*"
[---] application/json via json_dump
[new_users, distributions]
[new_givers, retentions]

0 comments on commit 0b4f6fa

Please sign in to comment.