Skip to content

Instantly share code, notes, and snippets.

@DavidCain
Last active March 22, 2017 23:48
Show Gist options
  • Save DavidCain/4a59d624188342b69a683d48f1df564e to your computer and use it in GitHub Desktop.
Save DavidCain/4a59d624188342b69a683d48f1df564e to your computer and use it in GitHub Desktop.
MITOC trip participation over the past year
"""
Gather some basic statistics about trips in the past year.
"""
from __future__ import print_function
from collections import Counter, OrderedDict
from datetime import timedelta
from ws import models
from ws.utils import dates as dateutils
last_year = dateutils.local_now() - timedelta(days=365)
recent_trips = models.Trip.objects.filter(trip_date__gt=last_year)
label = "Trips from {} until {}".format(last_year.date(), dateutils.local_date())
print(label)
print('-' * len(label))
print("Total: {}".format(recent_trips.count()))
print()
print("By type:")
trip_type_count = Counter(trip.get_activity_display() for trip in recent_trips)
for activity, count in trip_type_count.most_common():
print(" - {}: {}".format(activity, count))
def print_affiliations(participants):
affiliation_mapper = OrderedDict([
('MU', "MIT undergrad"),
('NU', "Non-MIT undergrad"),
('MG', "MIT grad student"),
('NG', "Non-MIT grad student"),
('MA', 'MIT affiliate'),
('NA', 'Non-affiliate'),
# Deprecated statuses
('S', 'Student (MIT affiliation unknown)'),
('M', 'MIT affiliate'),
('N', 'Non-affiliate')
])
affiliation_codes = participants.values_list('affiliation', flat=True)
affiliations = (affiliation_mapper[code] for code in affiliation_codes)
for affiliation, count in Counter(affiliations).most_common():
print(" - {}: {}".format(affiliation, count))
print()
print("Participation")
print("-------------")
signups = models.SignUp.objects.filter(trip__trip_date__lte=last_year)
print("{} distinct signups (FCFS & lottery)".format(signups.count()))
leaders = models.Participant.leaders
active_leaders = leaders.filter(trips_led__trip_date__gte=last_year)
print("{} leaders led at least one trip".format(active_leaders.count()))
print_affiliations(leaders)
participants = models.Participant.objects.filter(signup__on_trip=True).distinct()
print("{} participants went on at least one trip".format(participants.count()))
print_affiliations(participants)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment