Created
November 7, 2012 06:29
-
-
Save tuulos/4029841 to your computer and use it in GitHub Desktop.
Churn in Bitdeli
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bitdeli, json | |
from datetime import datetime | |
from time import mktime, strptime | |
bitdeli.set_theme('eighties') | |
BASELINE = mktime(strptime('2012-03-01', '%Y-%m-%d')) | |
all_users = [0] * 30 | |
active_users = [0] * 30 | |
def time(t): | |
return datetime.utcfromtimestamp(t) | |
def activity(events, zeroday): | |
prev_day = 0 | |
yield 0 | |
for event in events: | |
t = event['properties']['time'] | |
# Nth day of activity since signup | |
day = (time(t) - zeroday).days | |
if day > 0 and day != prev_day: | |
prev_day = day | |
if day < 30: | |
yield day | |
def chart(data, label, color): | |
# normalize counts to % of all users | |
norm = lambda x: round((100 * x / float(data[0])), 1) | |
bitdeli.Bar(label=label, | |
size=[12,2], | |
color=color, | |
data=list(enumerate(map(norm, data)))[1:]) | |
for profile in bitdeli.profiles(): | |
events = [json.loads(e) for e in profile['events']] | |
if events[0]['event'] == '$signup': | |
signup_time = events[0]['properties']['time'] | |
if signup_time > BASELINE: | |
# loop over all events | |
for day in activity(events[1:], time(signup_time)): | |
# count the number of users active on the Nth day after signup | |
all_users[day] += 1 | |
chart(all_users, 'Days since signup - % all users', color=1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment