Skip to content

Instantly share code, notes, and snippets.

@mrdrozdov
Created March 21, 2016 00:24
Show Gist options
  • Select an option

  • Save mrdrozdov/703c07e678575a8f9fb3 to your computer and use it in GitHub Desktop.

Select an option

Save mrdrozdov/703c07e678575a8f9fb3 to your computer and use it in GitHub Desktop.
checkin stats
import json
import pytz
import datetime
utc = pytz.utc
aest = pytz.timezone('Australia/Sydney')
def ts_to_date(ts):
date = datetime.datetime.utcfromtimestamp(int(ts)).replace(tzinfo=utc)
return aest.normalize(date)
def date_to_weekstamp(d):
# Note: At some point, I decided that monthly granularity was easier to read than weekly
# return "{}-{:02d}".format(d.year, int(d.timetuple().tm_yday / 7))
return "{}-{:02d}".format(d.year, d.month)
with open('alumni-checkins.json') as f:
data = json.load(f)
by_subject = {}
by_user = {}
by_day = {}
by_weekday = {}
by_hour = {}
by_week = {}
for m in data['messages']:
user = m['sender_id']
subject = m['subject']
ts = m['timestamp']
date = ts_to_date(ts)
day = date.strftime('%Y-%m-%d')
weekday = date.weekday()
hour = date.hour
week = date_to_weekstamp(date)
if 'Checkins!' not in subject: continue
if user not in by_user:
by_user[user] = []
by_user[user].append(m)
if day not in by_day:
by_day[day] = []
by_day[day].append(m)
if weekday not in by_weekday:
by_weekday[weekday] = []
by_weekday[weekday].append(m)
if hour not in by_hour:
by_hour[hour] = []
by_hour[hour].append(m)
if week not in by_week:
by_week[week] = set()
by_week[week].add(user)
total_days = len(by_day.keys())
total_ppl = len(by_user.keys())
total_msgs = sum([len(by_user[k]) for k in by_user.keys()])
# Total Days
print("Alumni Checkins have been running for {} days.".format(total_days))
# Unique People Overall
print("Over that time {} have checked in, and there have been {} checkins.".format(total_ppl, total_msgs))
print()
print("Note: Only messages on checkin threads were included in these and the following counts.")
print()
print("Here are the total unique users by month:")
for k in sorted(by_week.keys()):
s = by_week[k]
print("{}: {}".format(k, len(s)))
print()
print("Here are the total messages distributed over days:")
days = [
"Mo","Tu","We","Th","Fr","Sa","Su"
]
for x in range(7):
print("{}: {}".format(days[x], len(by_weekday[x])))
print()
print("Here are the total messages distributed over hours (AEST):")
for x in range(24):
print("{:2d}: {}".format(x, len(by_hour[x])))
print()
print("Thank you for all the wonderful messages :smile_cat: I hope weekly checkins will\nencourage an increasing number of people to share what they're doing\nmore frequently.")
print()
print("Special thanks to @**Faculty** for everything they've done to make RC the special\ncommunity that it is. And to everyone who was involved in the discussion\nregarding weekly-checkins.")
checkins_gist = "https://gist.githubusercontent.com/mrdrozdov/1a2805eb870f14a312f7/raw/9f5f53aeef93467dcb30055e7fb02f35af390bf2/weekly-checkins.txt"
checkins_msg = "Welcome to [weekly checkins]({})!".format(checkins_gist)
print()
print(checkins_msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment