Created
February 14, 2018 01:22
-
-
Save rasher/454aff3d6d624a417ec09dfbb1cc61ee to your computer and use it in GitHub Desktop.
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
#!/usr/bin/python | |
import sys | |
import csv | |
colors = { | |
'none': '#eee', | |
'other': '#aaa', | |
'vikings': '#4F2683', | |
'jaguars': '#006778', | |
'panthers': '#0085CA', | |
'falcons': '#000', | |
'bills': '#00338D', | |
'steelers': '#FFB612', | |
'titans': '#4B92DB', | |
'eagles': '#004C54', | |
'rams': '#002244', | |
'patriots': '#002244', | |
'saints': '#D3BC8D', | |
'chiefs': '#E31837', | |
} | |
def collect(fn, allusers): | |
classes = {} | |
users = {} | |
with open(fn) as fp: | |
for row in csv.DictReader(fp, ['un', 'class', 'text']): | |
cls = row['class'].replace('bandwagon', '').strip() if 'bandwagon' in row['class'] else 'other' | |
if row['class'] == 'None': | |
cls = 'none' | |
if cls not in classes: | |
classes[cls] = [] | |
classes[cls].append(row['un']) | |
users[row['un']] = cls | |
for user in allusers: | |
if user in users: | |
continue | |
if 'none' not in classes: | |
classes['none'] = [] | |
classes['none'].append(user) | |
users[user] = 'none' | |
return fn, classes, users | |
def sortteams(item): | |
"""Desperate and futile attempt at making D3 order teams usefully""" | |
order = ['eagles', 'patriots', | |
'jaguars', 'vikings', | |
'falcons', 'saints', 'steelers', 'titans', | |
'bills', 'panthers', 'chiefs', 'rams', | |
'other', 'none'] | |
tn = item[0] | |
return order.index(tn) | |
def print_transitions(this, previous): | |
for cls, users in sorted(this[1].items(), key=sortteams): | |
print(":%s-%s %s" % (this[0], cls[0].upper()+cls[1:], colors[cls])) | |
if previous[0] == None: | |
return | |
print("' %s -> %s" % (previous[0], this[0])) | |
for cls, users in sorted(this[1].items(), key=sortteams): | |
counter = {} | |
for user in users: | |
prevcls = previous[2][user] if user in previous[2] else 'other' | |
if prevcls not in counter: | |
counter[prevcls] = 0 | |
counter[prevcls] += 1 | |
for prevcls, count in sorted(counter.items(), key=sortteams): | |
print("%s-%s [%d] %s-%s" % (previous[0], prevcls[0].upper() + prevcls[1:], count, this[0], cls[0].upper()+cls[1:])) | |
if __name__ == "__main__": | |
previous = None, {}, {} | |
allusers = [line.strip() for line in open(sys.argv[1]).readlines()] | |
for f in sys.argv[2:]: | |
this = collect(f, allusers) | |
print_transitions(this, previous) | |
previous = this |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output when run on /r/nfl flair dumps for the 2017-18 playoffs