Skip to content

Instantly share code, notes, and snippets.

@rasher
Created February 14, 2018 01:22
Show Gist options
  • Save rasher/454aff3d6d624a417ec09dfbb1cc61ee to your computer and use it in GitHub Desktop.
Save rasher/454aff3d6d624a417ec09dfbb1cc61ee to your computer and use it in GitHub Desktop.
#!/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
@rasher
Copy link
Author

rasher commented Feb 14, 2018

Output when run on /r/nfl flair dumps for the 2017-18 playoffs

:WC-Eagles #004C54
:WC-Patriots #002244
:WC-Jaguars #006778
:WC-Vikings #4F2683
:WC-Falcons #000
:WC-Saints #D3BC8D
:WC-Steelers #FFB612
:WC-Titans #4B92DB
:WC-Bills #00338D
:WC-Panthers #0085CA
:WC-Chiefs #E31837
:WC-Rams #002244
:WC-Other #aaa
:WC-None #eee
:DIV-Eagles #004C54
:DIV-Patriots #002244
:DIV-Jaguars #006778
:DIV-Vikings #4F2683
:DIV-Falcons #000
:DIV-Saints #D3BC8D
:DIV-Steelers #FFB612
:DIV-Titans #4B92DB
:DIV-Bills #00338D
:DIV-Panthers #0085CA
:DIV-Chiefs #E31837
:DIV-Rams #002244
:DIV-Other #aaa
:DIV-None #eee
' WC -> DIV
WC-Eagles [96] DIV-Eagles
WC-Jaguars [1] DIV-Eagles
WC-Vikings [1] DIV-Eagles
WC-Bills [15] DIV-Eagles
WC-Chiefs [3] DIV-Eagles
WC-Rams [7] DIV-Eagles
WC-Other [68] DIV-Eagles
WC-None [10] DIV-Eagles
WC-Patriots [145] DIV-Patriots
WC-Bills [8] DIV-Patriots
WC-Chiefs [3] DIV-Patriots
WC-Rams [9] DIV-Patriots
WC-Other [86] DIV-Patriots
WC-None [13] DIV-Patriots
WC-Patriots [1] DIV-Jaguars
WC-Jaguars [553] DIV-Jaguars
WC-Vikings [1] DIV-Jaguars
WC-Saints [1] DIV-Jaguars
WC-Bills [92] DIV-Jaguars
WC-Panthers [2] DIV-Jaguars
WC-Chiefs [13] DIV-Jaguars
WC-Rams [41] DIV-Jaguars
WC-Other [307] DIV-Jaguars
WC-None [26] DIV-Jaguars
WC-Jaguars [8] DIV-Vikings
WC-Vikings [422] DIV-Vikings
WC-Saints [1] DIV-Vikings
WC-Bills [91] DIV-Vikings
WC-Panthers [8] DIV-Vikings
WC-Chiefs [16] DIV-Vikings
WC-Rams [39] DIV-Vikings
WC-Other [286] DIV-Vikings
WC-None [40] DIV-Vikings
WC-Patriots [1] DIV-Falcons
WC-Jaguars [1] DIV-Falcons
WC-Vikings [2] DIV-Falcons
WC-Falcons [42] DIV-Falcons
WC-Bills [16] DIV-Falcons
WC-Panthers [2] DIV-Falcons
WC-Chiefs [4] DIV-Falcons
WC-Rams [19] DIV-Falcons
WC-Other [36] DIV-Falcons
WC-None [6] DIV-Falcons
WC-Eagles [2] DIV-Saints
WC-Jaguars [5] DIV-Saints
WC-Vikings [4] DIV-Saints
WC-Saints [258] DIV-Saints
WC-Steelers [1] DIV-Saints
WC-Bills [66] DIV-Saints
WC-Panthers [2] DIV-Saints
WC-Chiefs [5] DIV-Saints
WC-Rams [49] DIV-Saints
WC-Other [189] DIV-Saints
WC-None [39] DIV-Saints
WC-Patriots [1] DIV-Steelers
WC-Steelers [56] DIV-Steelers
WC-Bills [4] DIV-Steelers
WC-Rams [2] DIV-Steelers
WC-Other [37] DIV-Steelers
WC-None [6] DIV-Steelers
WC-Eagles [2] DIV-Titans
WC-Patriots [1] DIV-Titans
WC-Jaguars [3] DIV-Titans
WC-Vikings [1] DIV-Titans
WC-Falcons [1] DIV-Titans
WC-Saints [1] DIV-Titans
WC-Titans [70] DIV-Titans
WC-Bills [63] DIV-Titans
WC-Panthers [1] DIV-Titans
WC-Chiefs [3] DIV-Titans
WC-Rams [17] DIV-Titans
WC-Other [98] DIV-Titans
WC-None [23] DIV-Titans
WC-Jaguars [1] DIV-Bills
WC-Vikings [1] DIV-Bills
WC-Bills [366] DIV-Bills
WC-Rams [3] DIV-Bills
WC-Other [44] DIV-Bills
WC-None [11] DIV-Bills
WC-Bills [1] DIV-Panthers
WC-Panthers [21] DIV-Panthers
WC-Other [7] DIV-Panthers
WC-None [2] DIV-Panthers
WC-Chiefs [34] DIV-Chiefs
WC-Other [6] DIV-Chiefs
WC-None [3] DIV-Chiefs
WC-Vikings [1] DIV-Rams
WC-Rams [177] DIV-Rams
WC-Other [13] DIV-Rams
WC-None [6] DIV-Rams
WC-Eagles [6] DIV-Other
WC-Patriots [13] DIV-Other
WC-Jaguars [20] DIV-Other
WC-Vikings [8] DIV-Other
WC-Falcons [2] DIV-Other
WC-Saints [14] DIV-Other
WC-Steelers [4] DIV-Other
WC-Bills [128] DIV-Other
WC-Panthers [16] DIV-Other
WC-Chiefs [10] DIV-Other
WC-Rams [63] DIV-Other
WC-Other [2210] DIV-Other
WC-None [27] DIV-Other
WC-Jaguars [1] DIV-None
WC-Bills [2] DIV-None
WC-None [502] DIV-None
:CON-Eagles #004C54
:CON-Patriots #002244
:CON-Jaguars #006778
:CON-Vikings #4F2683
:CON-Falcons #000
:CON-Saints #D3BC8D
:CON-Steelers #FFB612
:CON-Titans #4B92DB
:CON-Bills #00338D
:CON-Panthers #0085CA
:CON-Chiefs #E31837
:CON-Rams #002244
:CON-Other #aaa
:CON-None #eee
' DIV -> CON
DIV-Eagles [173] CON-Eagles
DIV-Patriots [1] CON-Eagles
DIV-Jaguars [3] CON-Eagles
DIV-Falcons [8] CON-Eagles
DIV-Saints [37] CON-Eagles
DIV-Steelers [4] CON-Eagles
DIV-Titans [14] CON-Eagles
DIV-Bills [4] CON-Eagles
DIV-Chiefs [1] CON-Eagles
DIV-Rams [4] CON-Eagles
DIV-Other [90] CON-Eagles
DIV-None [19] CON-Eagles
DIV-Patriots [239] CON-Patriots
DIV-Jaguars [1] CON-Patriots
DIV-Vikings [4] CON-Patriots
DIV-Falcons [5] CON-Patriots
DIV-Saints [17] CON-Patriots
DIV-Steelers [2] CON-Patriots
DIV-Titans [5] CON-Patriots
DIV-Bills [2] CON-Patriots
DIV-Panthers [1] CON-Patriots
DIV-Chiefs [1] CON-Patriots
DIV-Rams [2] CON-Patriots
DIV-Other [94] CON-Patriots
DIV-None [28] CON-Patriots
DIV-Eagles [4] CON-Jaguars
DIV-Patriots [4] CON-Jaguars
DIV-Jaguars [996] CON-Jaguars
DIV-Vikings [24] CON-Jaguars
DIV-Falcons [24] CON-Jaguars
DIV-Saints [113] CON-Jaguars
DIV-Steelers [14] CON-Jaguars
DIV-Titans [71] CON-Jaguars
DIV-Bills [61] CON-Jaguars
DIV-Panthers [2] CON-Jaguars
DIV-Chiefs [3] CON-Jaguars
DIV-Rams [21] CON-Jaguars
DIV-Other [976] CON-Jaguars
DIV-None [180] CON-Jaguars
DIV-Eagles [8] CON-Vikings
DIV-Patriots [7] CON-Vikings
DIV-Jaguars [12] CON-Vikings
DIV-Vikings [856] CON-Vikings
DIV-Falcons [32] CON-Vikings
DIV-Saints [93] CON-Vikings
DIV-Steelers [13] CON-Vikings
DIV-Titans [44] CON-Vikings
DIV-Bills [42] CON-Vikings
DIV-Panthers [1] CON-Vikings
DIV-Chiefs [4] CON-Vikings
DIV-Rams [15] CON-Vikings
DIV-Other [638] CON-Vikings
DIV-None [107] CON-Vikings
DIV-Falcons [35] CON-Falcons
DIV-Panthers [1] CON-Falcons
DIV-Other [1] CON-Falcons
DIV-None [1] CON-Falcons
DIV-Jaguars [1] CON-Saints
DIV-Falcons [1] CON-Saints
DIV-Saints [264] CON-Saints
DIV-Bills [1] CON-Saints
DIV-Panthers [1] CON-Saints
DIV-Other [10] CON-Saints
DIV-None [10] CON-Saints
DIV-Saints [1] CON-Steelers
DIV-Steelers [45] CON-Steelers
DIV-Rams [1] CON-Steelers
DIV-Other [6] CON-Steelers
DIV-None [1] CON-Steelers
DIV-Falcons [1] CON-Titans
DIV-Titans [108] CON-Titans
DIV-Bills [2] CON-Titans
DIV-Rams [1] CON-Titans
DIV-Other [4] CON-Titans
DIV-None [3] CON-Titans
DIV-Bills [276] CON-Bills
DIV-Panthers [18] CON-Panthers
DIV-Chiefs [31] CON-Chiefs
DIV-Rams [140] CON-Rams
DIV-Eagles [16] CON-Other
DIV-Patriots [12] CON-Other
DIV-Jaguars [21] CON-Other
DIV-Vikings [26] CON-Other
DIV-Falcons [22] CON-Other
DIV-Saints [95] CON-Other
DIV-Steelers [27] CON-Other
DIV-Titans [42] CON-Other
DIV-Bills [38] CON-Other
DIV-Panthers [7] CON-Other
DIV-Chiefs [3] CON-Other
DIV-Rams [13] CON-Other
DIV-Other [699] CON-Other
DIV-None [9] CON-Other
DIV-Patriots [1] CON-None
DIV-Jaguars [3] CON-None
DIV-Vikings [1] CON-None
DIV-Falcons [1] CON-None
DIV-Steelers [1] CON-None
DIV-Other [3] CON-None
DIV-None [147] CON-None
:SB-Eagles #004C54
:SB-Patriots #002244
:SB-Jaguars #006778
:SB-Vikings #4F2683
:SB-Falcons #000
:SB-Saints #D3BC8D
:SB-Steelers #FFB612
:SB-Titans #4B92DB
:SB-Bills #00338D
:SB-Panthers #0085CA
:SB-Chiefs #E31837
:SB-Rams #002244
:SB-Other #aaa
:SB-None #eee
' CON -> SB
CON-Eagles [319] SB-Eagles
CON-Patriots [8] SB-Eagles
CON-Jaguars [323] SB-Eagles
CON-Vikings [242] SB-Eagles
CON-Falcons [2] SB-Eagles
CON-Saints [26] SB-Eagles
CON-Steelers [5] SB-Eagles
CON-Titans [2] SB-Eagles
CON-Bills [11] SB-Eagles
CON-Panthers [1] SB-Eagles
CON-Rams [1] SB-Eagles
CON-Other [211] SB-Eagles
CON-None [62] SB-Eagles
CON-Eagles [1] SB-Patriots
CON-Patriots [348] SB-Patriots
CON-Jaguars [105] SB-Patriots
CON-Vikings [76] SB-Patriots
CON-Saints [6] SB-Patriots
CON-Titans [1] SB-Patriots
CON-Bills [1] SB-Patriots
CON-Rams [2] SB-Patriots
CON-Other [204] SB-Patriots
CON-None [59] SB-Patriots
CON-Patriots [1] SB-Jaguars
CON-Jaguars [1342] SB-Jaguars
CON-Falcons [1] SB-Jaguars
CON-Saints [2] SB-Jaguars
CON-Bills [3] SB-Jaguars
CON-Other [29] SB-Jaguars
CON-None [13] SB-Jaguars
CON-Jaguars [24] SB-Vikings
CON-Vikings [946] SB-Vikings
CON-Falcons [2] SB-Vikings
CON-Saints [3] SB-Vikings
CON-Steelers [1] SB-Vikings
CON-Bills [1] SB-Vikings
CON-Panthers [1] SB-Vikings
CON-Chiefs [1] SB-Vikings
CON-Other [27] SB-Vikings
CON-None [12] SB-Vikings
CON-Falcons [23] SB-Falcons
CON-Saints [206] SB-Saints
CON-Steelers [39] SB-Steelers
CON-Titans [94] SB-Titans
CON-Bills [231] SB-Bills
CON-Panthers [14] SB-Panthers
CON-Chiefs [29] SB-Chiefs
CON-Rams [116] SB-Rams
CON-Eagles [38] SB-Other
CON-Patriots [42] SB-Other
CON-Jaguars [692] SB-Other
CON-Vikings [596] SB-Other
CON-Falcons [10] SB-Other
CON-Saints [45] SB-Other
CON-Steelers [9] SB-Other
CON-Titans [22] SB-Other
CON-Bills [28] SB-Other
CON-Panthers [2] SB-Other
CON-Chiefs [1] SB-Other
CON-Rams [21] SB-Other
CON-Other [557] SB-Other
CON-Patriots [2] SB-None
CON-Jaguars [7] SB-None
CON-Vikings [12] SB-None
CON-Bills [1] SB-None
CON-Other [2] SB-None
CON-None [11] SB-None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment