| import requests | |
| from pprint import pprint | |
| class Team: | |
| def __init__(self, key, opr, seed, dpr): | |
| self.key = key | |
| self.opr = opr | |
| self.seed = seed | |
| self.dpr = dpr | |
| def __str__(self): | |
| return "%d - %d (%d)" % (self.key, self.opr, self.seed) | |
| def __repr__(self): | |
| return "%d - %d (%d)" % (self.key, self.opr, self.seed) | |
| def get_event_info(key): | |
| tba = 'https://www.thebluealliance.com/api/v2/event/2016%s' % key | |
| headers = {'X-TBA-App-Id':'jht:einstein_predictor:1'} | |
| ranking_req = requests.get(tba + '/rankings', headers=headers) | |
| stats_req = requests.get(tba + '/stats', headers=headers) | |
| rankings = [] | |
| count = 0 | |
| for team in ranking_req.json()[1:]: | |
| count += 1 | |
| rankings.append(Team(int(team[1]), stats_req.json()['oprs'][team[1]], count, stats_req.json()['dprs'][team[1]])) | |
| return rankings | |
| def maxopr(teams): | |
| highest = teams[0] | |
| for team in teams[1:]: | |
| if team.opr > highest.opr: | |
| highest = team | |
| return highest | |
| divs = ['arc', 'cars', 'carv', 'cur', 'gal', 'hop', 'new', 'tes'] | |
| all_alliances = [] | |
| for div in divs: | |
| ranks = get_event_info(div) | |
| alliances = [] | |
| for seed in range(0, 8): | |
| captain = ranks.pop(0) | |
| pick1 = ranks[ranks.index(maxopr(ranks))] | |
| ranks.remove(pick1) | |
| alliances.append([captain, pick1]) | |
| for seed in range(7,-1,-1): | |
| pick2 = ranks[ranks.index(maxopr(ranks))] | |
| ranks.remove(pick2) | |
| alliances[seed].append(pick2) | |
| for seed in range(0, 8): | |
| pick3 = ranks[ranks.index(maxopr(ranks))] | |
| ranks.remove(pick3) | |
| alliances[seed].append(pick3) | |
| print("%s alliances:" % div) | |
| pprint(alliances) | |
| all_alliances.append(alliances) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment