From b0a4b2574f5f847deba53866cd1edac9957af2d6 Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Fri, 24 Oct 2014 15:48:06 -0400 Subject: [PATCH] Switch from Active Users to Givers --- tests/py/test_charts_json.py | 4 +-- www/about/charts.json.spt | 4 +-- www/about/charts.spt | 18 ++++++------ www/about/retention.json.spt | 53 +++++++++++++++++------------------- 4 files changed, 38 insertions(+), 41 deletions(-) diff --git a/tests/py/test_charts_json.py b/tests/py/test_charts_json.py index b40af2909a..33ae159af8 100644 --- a/tests/py/test_charts_json.py +++ b/tests/py/test_charts_json.py @@ -153,8 +153,8 @@ def test_transfer_volume(self): , "weekly_gifts": 3.0 , "charges": 0.0 , "withdrawals": 0.0 - , "active_users": 3 - , "active_ratio": 7500 + , "givers": 2 + , "giver_ratio": 5000 , "total_users": 4 , "total_gifts": 6.0 } diff --git a/www/about/charts.json.spt b/www/about/charts.json.spt index 0bb7c713b9..81b3f5180a 100644 --- a/www/about/charts.json.spt +++ b/www/about/charts.json.spt @@ -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 diff --git a/www/about/charts.spt b/www/about/charts.spt index a793f00c2f..7fe1f6146f 100644 --- a/www/about/charts.spt +++ b/www/about/charts.spt @@ -26,25 +26,25 @@ $(document).ready(function() {
-

Active Users

-

Users that gave and/or received money within Gratipay (per week)

-
+

Givers

+

Users that gave money using Gratipay (per week)

+
weeks
-

Active Ratio

-

Active users per 10,000 total users

-
+

Giver Ratio

+

Givers per 10,000 total users

+
weeks
-

Cohort Size and Retention

-

The number of new active users per week, and their activity over time

-
+

Giver Cohorts

+

The number of new givers per week, and their activity over time

+
diff --git a/www/about/retention.json.spt b/www/about/retention.json.spt index a81cd6a40e..9fc571f9a9 100644 --- a/www/about/retention.json.spt +++ b/www/about/retention.json.spt @@ -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 @@ -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]