Skip to content

Instantly share code, notes, and snippets.

@hancush
Last active March 16, 2017 15:59
Show Gist options
  • Save hancush/ae680555182bf9d080a980c9b54e0513 to your computer and use it in GitHub Desktop.
Save hancush/ae680555182bf9d080a980c9b54e0513 to your computer and use it in GitHub Desktop.
pick yr bracket w wildly misinterpreted statistics scraped from espn.com

🏀🗑 march sadness

if u love ur friends but hate basketball, let the computer do your brack for you.

75 percent of the time it returns the better team as measured by power index ranking. 25 percent of the time it returns the underdog. for teams within 15 spots of one another, it returns whichever team has a color closest to my fave (bright yellow).

use

make sure to pip install colormath and also use python 3.x bc we're usin the input method!

then,

git clone [email protected]:ae680555182bf9d080a980c9b54e0513.git ncaa && cd ncaa

and

python compare_teams.py

enter the matchup separated by commas, i.e. Kansas, Kentucky, and hit enter. (case matters bc i am very lazy.) do this for all matchups. sports are fun!

import functools
import json
from random import random
from colormath.color_objects import sRGBColor, LabColor
from colormath.color_conversions import convert_color
from colormath.color_diff import delta_e_cie2000
data = json.load(open('team_data.json', 'r'))
def get_team(team_name):
for team in data:
if team['n'] == team_name:
return team
return None
def compare_colors(color):
favorite_color = convert_color(sRGBColor(255, 206, 0), LabColor)
difference = delta_e_cie2000(favorite_color, color)
return difference
def to_lab_color(hex_str):
return convert_color(sRGBColor.new_from_rgb_hex(hex_str), LabColor)
def compare_stat(array, func):
return func(array, key=lambda x: x[1])
def compare_teams(team_a, team_b):
bpi = [(team['n'], team['bpi']) for team in (team_a, team_b)]
f = min if random() > 0.25 else max
power_index = compare_stat(bpi, f)
adv = abs(functools.reduce(lambda x, y: x-y, [int(x[1]) for x in bpi]))
if adv <= 15:
color_diffs = [(team['n'], compare_colors(to_lab_color(team['c']))) \
for team in (team_a, team_b)]
prettiest = compare_stat(color_diffs, min)
print('returning prettiest color')
return prettiest
which = 'better' if f is min else 'underdog'
print('returning %s team' % which)
return power_index, adv
if __name__ == '__main__':
while True:
a, b = tuple(input('Enter matchup: ').split(', '))
team_a = get_team(a)
team_b = get_team(b)
if all([team_a, team_b]):
print(compare_teams(team_a, team_b))
else:
print('Invalid team/s: %s' % ', '.join(t for t in [a, b] if not get_team(t)))
[
{
"c":"123d7C",
"r":"31-3",
"sl":0,
"eid":222,
"n":"Villanova",
"s":1,
"bpi":"1",
"a":"NOVA",
"id":1,
"e":"False"
},
{
"c":"f4f142",
"r":"19-15",
"sl":1,
"eid":116,
"n":"MSM",
"s":16,
"bpi":"207",
"a":"MSM",
"id":2,
"e":"False"
},
{
"c":"A00002",
"r":"25-9",
"sl":2,
"eid":275,
"n":"Wisconsin",
"s":8,
"bpi":"21",
"a":"WIS",
"id":3,
"e":"False"
},
{
"c":"74232D",
"r":"22-10",
"sl":3,
"eid":259,
"n":"Virginia Tech",
"s":9,
"bpi":"50",
"a":"VT",
"id":4,
"e":"False"
},
{
"c":"00204E",
"r":"22-10",
"sl":4,
"eid":258,
"n":"UVA",
"s":5,
"bpi":"4",
"a":"UVA",
"id":5,
"e":"False"
},
{
"c":"1d2f68",
"r":"29-5",
"sl":5,
"eid":350,
"n":"UNC Wilmington",
"s":12,
"bpi":"61",
"a":"UNCW",
"id":6,
"e":"False"
},
{
"c":"0021A5",
"r":"24-8",
"sl":6,
"eid":57,
"n":"Florida",
"s":4,
"bpi":"8",
"a":"FLA",
"id":7,
"e":"False"
},
{
"c":"002d61",
"r":"27-7",
"sl":7,
"eid":2193,
"n":"ETSU",
"s":13,
"bpi":"74",
"a":"ETSU",
"id":8,
"e":"False"
},
{
"c":"E32F38",
"r":"30-4",
"sl":8,
"eid":2567,
"n":"SMU",
"s":6,
"bpi":"16",
"a":"SMU",
"id":9,
"e":"False"
},
{
"c":"F36E21",
"r":"24-9",
"sl":9,
"eid":30,
"n":"USC",
"s":11,
"bpi":"59",
"a":"USC",
"id":10,
"e":"False"
},
{
"c":"004834",
"r":"25-7",
"sl":10,
"eid":239,
"n":"Baylor",
"s":3,
"bpi":"17",
"a":"BAY",
"id":11,
"e":"False"
},
{
"c":"891216",
"r":"28-5",
"sl":11,
"eid":166,
"n":"New Mexico St",
"s":14,
"bpi":"98",
"a":"NMSU",
"id":12,
"e":"False"
},
{
"c":"670010",
"r":"22-10",
"sl":12,
"eid":2579,
"n":"South Carolina",
"s":7,
"bpi":"43",
"a":"SC",
"id":13,
"e":"False"
},
{
"c":"083963",
"r":"19-12",
"sl":13,
"eid":269,
"n":"Marquette",
"s":10,
"bpi":"29",
"a":"MARQ",
"id":14,
"e":"False"
},
{
"c":"001A57",
"r":"27-8",
"sl":14,
"eid":150,
"n":"Duke",
"s":2,
"bpi":"6",
"a":"DUKE",
"id":15,
"e":"False"
},
{
"c":"AE0210",
"r":"22-14",
"sl":15,
"eid":2653,
"n":"Troy",
"s":15,
"bpi":"127",
"a":"TROY",
"id":16,
"e":"False"
},
{
"c":"002967",
"r":"32-1",
"sl":16,
"eid":2250,
"n":"Gonzaga",
"s":1,
"bpi":"2",
"a":"GONZ",
"id":17,
"e":"False"
},
{
"c":"005DAB",
"r":"18-16",
"sl":17,
"eid":2571,
"n":"South Dakota St",
"s":16,
"bpi":"188",
"a":"SDST",
"id":18,
"e":"False"
},
{
"c":"372286",
"r":"23-11",
"sl":18,
"eid":77,
"n":"Northwestern",
"s":8,
"bpi":"46",
"a":"NW",
"id":19,
"e":"False"
},
{
"c":"000000",
"r":"19-15",
"sl":19,
"eid":238,
"n":"Vanderbilt",
"s":9,
"bpi":"39",
"a":"VAN",
"id":20,
"e":"False"
},
{
"c":"00122b",
"r":"25-9",
"sl":20,
"eid":87,
"n":"Notre Dame",
"s":5,
"bpi":"22",
"a":"ND",
"id":21,
"e":"False"
},
{
"c":"ff9408",
"r":"23-6",
"sl":21,
"eid":163,
"n":"Princeton",
"s":12,
"bpi":"54",
"a":"PRIN",
"id":22,
"e":"False"
},
{
"c":"FFC600",
"r":"26-8",
"sl":22,
"eid":277,
"n":"West Virginia",
"s":4,
"bpi":"7",
"a":"WVU",
"id":23,
"e":"False"
},
{
"c":"000060",
"r":"26-8",
"sl":23,
"eid":2083,
"n":"Bucknell",
"s":13,
"bpi":"85",
"a":"BUCK",
"id":24,
"e":"False"
},
{
"c":"D5002B",
"r":"24-8",
"sl":24,
"eid":120,
"n":"Maryland",
"s":6,
"bpi":"49",
"a":"MD",
"id":25,
"e":"False"
},
{
"c":"002144",
"r":"21-13",
"sl":25,
"eid":2752,
"n":"Xavier",
"s":11,
"bpi":"35",
"a":"XAV",
"id":26,
"e":"False"
},
{
"c":"782F40",
"r":"25-8",
"sl":26,
"eid":52,
"n":"FSU",
"s":3,
"bpi":"20",
"a":"FSU",
"id":27,
"e":"False"
},
{
"c":"00885a",
"r":"26-7",
"sl":27,
"eid":526,
"n":"FGCU",
"s":14,
"bpi":"80",
"a":"FGCU",
"id":28,
"e":"False"
},
{
"c":"003768",
"r":"28-4",
"sl":28,
"eid":2608,
"n":"Saint Mary's",
"s":7,
"bpi":"12",
"a":"SMC",
"id":29,
"e":"False"
},
{
"c":"929292",
"r":"26-8",
"sl":29,
"eid":2670,
"n":"VCU",
"s":10,
"bpi":"40",
"a":"VCU",
"id":30,
"e":"False"
},
{
"c":"002449",
"r":"30-4",
"sl":30,
"eid":12,
"n":"Arizona",
"s":2,
"bpi":"24",
"a":"ARIZ",
"id":31,
"e":"False"
},
{
"c":"00A26B",
"r":"22-9",
"sl":31,
"eid":155,
"n":"North Dakota",
"s":15,
"bpi":"146",
"a":"UND",
"id":32,
"e":"False"
},
{
"c":"0022B4",
"r":"28-4",
"sl":32,
"eid":2305,
"n":"Kansas",
"s":1,
"bpi":"10",
"a":"KU",
"id":33,
"e":"False"
},
{
"c":"bb0000",
"r":"22-12",
"sl":33,
"eid":302,
"n":"UC Davis",
"s":16,
"bpi":"210",
"a":"UCD",
"id":34,
"e":"False"
},
{
"c":"004325",
"r":"21-11",
"sl":34,
"eid":2390,
"n":"Miami",
"s":8,
"bpi":"28",
"a":"MIA",
"id":35,
"e":"False"
},
{
"c":"18453B",
"r":"19-14",
"sl":35,
"eid":127,
"n":"Michigan State",
"s":9,
"bpi":"44",
"a":"MSU",
"id":36,
"e":"False"
},
{
"c":"660015",
"r":"23-10",
"sl":36,
"eid":66,
"n":"Iowa State",
"s":5,
"bpi":"23",
"a":"ISU",
"id":37,
"e":"False"
},
{
"c":"153E5F",
"r":"28-6",
"sl":37,
"eid":2440,
"n":"Nevada",
"s":12,
"bpi":"48",
"a":"NEV",
"id":38,
"e":"False"
},
{
"c":"B89D29",
"r":"25-7",
"sl":38,
"eid":2509,
"n":"Purdue",
"s":4,
"bpi":"11",
"a":"PUR",
"id":39,
"e":"False"
},
{
"c":"013C24",
"r":"29-5",
"sl":39,
"eid":261,
"n":"Vermont",
"s":13,
"bpi":"51",
"a":"UVM",
"id":40,
"e":"False"
},
{
"c":"13299e",
"r":"25-9",
"sl":40,
"eid":156,
"n":"Creighton",
"s":6,
"bpi":"27",
"a":"CREI",
"id":41,
"e":"False"
},
{
"c":"3691C6",
"r":"24-9",
"sl":41,
"eid":227,
"n":"URI",
"s":11,
"bpi":"33",
"a":"URI",
"id":42,
"e":"False"
},
{
"c":"044520",
"r":"29-5",
"sl":42,
"eid":2483,
"n":"Oregon",
"s":3,
"bpi":"13",
"a":"ORE",
"id":43,
"e":"False"
},
{
"c":"8c001a",
"r":"22-12",
"sl":43,
"eid":314,
"n":"Iona",
"s":14,
"bpi":"137",
"a":"IONA",
"id":44,
"e":"False"
},
{
"c":"00274c",
"r":"24-11",
"sl":44,
"eid":130,
"n":"Michigan",
"s":7,
"bpi":"18",
"a":"MICH",
"id":45,
"e":"False"
},
{
"c":"FF6500",
"r":"20-12",
"sl":45,
"eid":197,
"n":"Oklahoma State",
"s":10,
"bpi":"26",
"a":"OKST",
"id":46,
"e":"False"
},
{
"c":"ad000a",
"r":"24-8",
"sl":46,
"eid":97,
"n":"Louisville",
"s":2,
"bpi":"5",
"a":"LOU",
"id":47,
"e":"False"
},
{
"c":"b50500",
"r":"20-14",
"sl":47,
"eid":55,
"n":"Jacksonville St",
"s":15,
"bpi":"174",
"a":"JVST",
"id":48,
"e":"False"
},
{
"c":"99bfe5",
"r":"27-7",
"sl":48,
"eid":153,
"n":"UNC",
"s":1,
"bpi":"3",
"a":"UNC",
"id":49,
"e":"False"
},
{
"c":"6A0403",
"r":"23-11",
"sl":49,
"eid":2640,
"n":"Texas Southern",
"s":16,
"bpi":"178",
"a":"TXSO",
"id":50,
"e":"False"
},
{
"c":"9c1831",
"r":"25-9",
"sl":50,
"eid":8,
"n":"Arkansas",
"s":8,
"bpi":"47",
"a":"ARK",
"id":51,
"e":"False"
},
{
"c":"0857B1",
"r":"21-11",
"sl":51,
"eid":2550,
"n":"Seton Hall",
"s":9,
"bpi":"53",
"a":"HALL",
"id":52,
"e":"False"
},
{
"c":"7F011B",
"r":"24-9",
"sl":52,
"eid":135,
"n":"Minnesota",
"s":5,
"bpi":"38",
"a":"MINN",
"id":53,
"e":"False"
},
{
"c":"0079C2",
"r":"30-4",
"sl":53,
"eid":2393,
"n":"Mid Tennessee",
"s":12,
"bpi":"45",
"a":"MTSU",
"id":54,
"e":"False"
},
{
"c":"0d1361",
"r":"23-8",
"sl":54,
"eid":2086,
"n":"Butler",
"s":4,
"bpi":"25",
"a":"BUT",
"id":55,
"e":"False"
},
{
"c":"9e0b0e",
"r":"26-6",
"sl":55,
"eid":2737,
"n":"Winthrop",
"s":13,
"bpi":"101",
"a":"WIN",
"id":56,
"e":"False"
},
{
"c":"000000",
"r":"29-5",
"sl":56,
"eid":2132,
"n":"Cincinnati",
"s":6,
"bpi":"19",
"a":"CIN",
"id":57,
"e":"False"
},
{
"c":"588fe8",
"r":"20-13",
"sl":57,
"eid":2306,
"n":"KSU",
"s":11,
"bpi":"37",
"a":"KSU",
"id":58,
"e":"False"
},
{
"c":"005C8E",
"r":"29-4",
"sl":58,
"eid":26,
"n":"UCLA",
"s":3,
"bpi":"14",
"a":"UCLA",
"id":59,
"e":"False"
},
{
"c":"002445",
"r":"22-13",
"sl":59,
"eid":2309,
"n":"Kent State",
"s":14,
"bpi":"139",
"a":"KENT",
"id":60,
"e":"False"
},
{
"c":"004B8D",
"r":"24-7",
"sl":60,
"eid":2168,
"n":"Dayton",
"s":7,
"bpi":"36",
"a":"DAY",
"id":61,
"e":"False"
},
{
"c":"0d0a03",
"r":"30-4",
"sl":61,
"eid":2724,
"n":"Wichita State",
"s":10,
"bpi":"15",
"a":"WICH",
"id":62,
"e":"False"
},
{
"c":"005DAA",
"r":"29-5",
"sl":62,
"eid":96,
"n":"Kentucky",
"s":2,
"bpi":"9",
"a":"UK",
"id":63,
"e":"False"
},
{
"c":"000000",
"r":"24-10",
"sl":63,
"eid":94,
"n":"N Kentucky",
"s":15,
"bpi":"177",
"a":"NKU",
"id":64,
"e":"False"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment