def getregion(teamKey): team = getTBAdata("team/" + teamKey + "/simple") districts = getTBAdata("team/" + teamKey + "/districts") if len(districts) != 0: return districts[0]["abbreviation"].upper() elif team["country"] not in ["USA", "Canada"]: return team["country"] else: return team["state_prov"]
def eventDP(event): teams = {} statuses = getTBAdata("event/" + event + "/teams/statuses") num = len(getTBAdata("event/" + event + "/teams/keys")) matches = getTBAdata("event/" + event + "/matches/simple") awards = getTBAdata("event/" + event + "/awards") for key, t in statuses.items(): if t is None: continue if t["qual"] is None: teams[key] = 0 else: teams[key] = ceil( 7.676 * erfinv(0.934579 + 1.86916 * (1 - t["qual"]["ranking"]["rank"]) / num) + 12) if t["alliance"] is not None and t["qual"] is not None: teams[key] += ( (17 - t["alliance"]["number"]) if t["alliance"]["pick"] < 2 else t["alliance"]["number"]) if t["alliance"]["pick"] < 3 else 0 if t["playoff"] is not None: cnt = 0 for lvl in ["qf", "sf", "f"]: if [0, 0, 10, 20][[ "ef", "qf", "sf", "f" ].index(lvl)] < ([0, 0, 10, 20][["ef", "qf", "sf", "f"].index( t["playoff"]["level"])] if t["playoff"]["status"] == "eliminated" else 30): for m in matches: if m["comp_level"] != lvl: continue if key in m["alliances"]["blue"]["team_keys"] and m[ "winning_alliance"] == "blue": cnt += 5 if key in m["alliances"]["red"]["team_keys"] and m[ "winning_alliance"] == "red": cnt += 5 teams[key] += cnt for a in awards: if a["award_type"] not in awarddp: continue for t in a["recipient_list"]: if t["team_key"] is None: continue if t["team_key"] not in teams: print("^^^^ " + t["team_key"]) continue teams[t["team_key"]] += awarddp[a["award_type"]] return teams
for a in awards: if a["award_type"] not in awarddp: continue for t in a["recipient_list"]: if t["team_key"] is None: continue if t["team_key"] not in teams: print("^^^^ " + t["team_key"]) continue teams[t["team_key"]] += awarddp[a["award_type"]] return teams data = {} years = range(2011, 2019) for year in years: yeardp = {} events = getTBAdata("events/" + str(year)) for event in events: if event["event_type"] > 5 or len(event["division_keys"]) > 0: continue print(event["key"]) eventdp = eventDP(event["key"]) for key, dp in eventdp.items(): if key not in yeardp: yeardp[key] = [0, 0] yeardp[key][0] += dp * [1, 1, 1.1, 1.2, 1, 1.1 ][event["event_type"]] yeardp[key][1] += 1 if event["event_type"] != 4 else 0 for key, t in yeardp.items(): if key not in data: data[key] = {} data[key][year] = t with open("data_award.csv", "w+") as file: file.write("Team,")
from functions import getTBAdata avgs = {} events = getTBAdata("events/2018") for event in events: if event["event_type"] > 1: continue print(event["key"]) dps = getTBAdata("event/" + event["key"] + "/district_points")["points"] avgs[event["key"]] = (sum([dps[t]["total"] for t in dps.keys()]) / len(dps), len(dps)) with open("avgs.csv", "w+") as file: file.write("Event,AvgDP,# Teams\n") for event, avg in avgs.items(): file.write(event + "," + str(avg[0]) + "," + str(avg[1]) + "\n")
import random import math from functions import getTBAdata import csv DPs = {} with open("DistrictRankings/SingleYearDP/2018_world_DP.csv") as file: reader = csv.DictReader(file) for row in reader: DPs[row["Team"]] = float(row["Adj DP"]) event = input("event: ") teams = getTBAdata("event/" + event + "/teams/keys") num_matches = int(input("Matches per Team: ")) with open("DistrictRankings/Event Predictor/schedules/" + str(len(teams)) + "_" + str(num_matches) + ".csv") as file: matches = file.readlines() matches = [[int(x) for x in match.strip().split(",")[0::2]] for match in matches] runs = int(input("Iterations: ")) results = {team: [0] * len(teams) for team in teams} avg = {team: 0 for team in teams} for i in range(runs): print(i) random.shuffle(teams) ev = {team: [0, 0] for team in teams} for match in matches: playing = [teams[x - 1] for x in match] redwins = random.random() <= 1 / ( 1 + math.exp(-(sum([DPs[team] for team in playing[:3]]) -
from functions import getTBAdata years = range(2002, 2020) all_events = [] for year in years: events = getTBAdata("events/" + str(year) + "/keys") for event in events: print(event) teams = getTBAdata("event/" + event + "/teams") if len(teams) == 0: continue rookie = sum([1 if t["rookie_year"]==year else 0 for t in teams]) all_events.append((event, rookie, len(teams))) all_events = sorted(all_events, key=lambda x:x[1]/x[2], reverse=True) print(all_events) with open("rookie_percent.csv", "w+") as file: file.write("Event,Rookies,Total,% Rookies\n") for e in all_events: file.write(e[0] + "," + str(e[1]) + "," + str(e[2]) + "," + str(e[1]/e[2]) + "\n")
"wins"] self.ties += status["qual"]["ranking"]["record"][ "ties"] self.losses += status["qual"]["ranking"]["record"][ "losses"] if status["playoff"] is not None: if status["playoff"]["record"] is not None: self.wins += status["playoff"]["record"]["wins"] self.ties += status["playoff"]["record"]["ties"] self.losses += status["playoff"]["record"]["losses"] teams = {} file = open("winning_season.csv", "w+") events = getTBAdata("events/2018") for event in events: if 0 <= event["event_type"] <= 3 or event["event_type"] == 5: if len(event["division_keys"]) == 0: print(event["key"]) statuses = getTBAdata("event/" + str(event["key"]) + "/teams/statuses") for teamKey in statuses: if teamKey in teams: teams[teamKey].add_event(statuses[teamKey]) else: teams[teamKey] = Team(statuses[teamKey]) file.write("Team,Wins,Losses,Ties,Ratio\n") for teamKey in teams: print(teamKey)
districts = getTBAdata("team/" + teamKey + "/districts") if len(districts) != 0: return districts[0]["abbreviation"].upper() elif team["country"] not in ["USA", "Canada"]: return team["country"] else: return team["state_prov"] years = range(2010, 2019) regions = {} for year in years: print(year) cmp_awards = [] events = getTBAdata("events/"+str(year)) for event in events: if event["event_type"] in [3, 4]: print(event["key"]) awards = getTBAdata("event/"+event["key"]+"/awards") for award in awards: if award["award_type"] in [0, 9, 10, 69]: for recipient in award["recipient_list"]: if recipient["team_key"] not in cmp_awards: cmp_awards.append(recipient["team_key"]) print(cmp_awards) yearly = {} for teamKey in cmp_awards: region = getregion(teamKey) if region not in yearly: yearly[region] = 0
self.numevents[year]) + "," else: tmp += ",,,," return tmp teams = {} file = open("yearly_dp_.csv", "w+") file.write("Team #,") for year in range(2010, 2018 + 1): file.write( str(year) + " DP," + str(year) + " OPR," + str(year) + " Rank," + str(year) + " Num Events,") events = getTBAdata("events/" + str(year)) for event in events: if 0 <= event["event_type"] <= 3 or event["event_type"] == 5: if len(event["division_keys"]) == 0: print(event["key"]) statuses = getTBAdata("event/" + event["key"] + "/teams/statuses") oprs = getTBAdata("event/" + event["key"] + "/oprs")["oprs"] for teamKey in statuses: print(statuses[teamKey]) if teamKey in oprs: if teamKey in teams: teams[teamKey].add_event(event, statuses[teamKey], oprs[teamKey]) else: teams[teamKey] = Team(event, statuses[teamKey],
21: "ENGINEERING_EXCELLENCE", 22: "ENTREPRENEURSHIP", 23: "EXCELLENCE_IN_DESIGN", 27: "IMAGERY", 29: "INNOVATION_IN_CONTROL", 30: "SPIRIT", 31: "WEBSITE" } with open("output.txt", "w+") as file: file.write("data = {\n") teams = {} i = 0 while True: tmp = getTBAdata("teams/2018/" + str(i) + "/keys") if len(tmp) == 0: break for team in tmp: print(team) awards = getTBAdata("team/" + team + "/awards") teams[team] = { "WINNER": [], "FINALIST": [], "CHAIRMANS": [], "ENGINEERING_INSPIRATION": [], "CREATIVITY": [], "ENGINEERING_EXCELLENCE": [], "INDUSTRIAL_DESIGN": [], "INNOVATION_IN_CONTROL": [], "QUALITY": [], "ENTREPRENEURSHIP": [],
from functions import getTBAdata import traceback years = range(2010, 2020) data = {y: [0] * 8 for y in years} for year in years: print(year) events = getTBAdata("events/" + str(year)) for event in events: if event["event_type"] > 5 or len(event["division_keys"]) > 0: continue alliances = getTBAdata("event/" + event["key"] + "/alliances") print(event["key"]) if alliances is None: continue for i, a in enumerate(alliances): try: if a["status"] == "unknown": continue if a["status"]["level"] == "f": try: print(i + 1) data[year][i] += 1 except: traceback.print_exc() print(a) except: traceback.print_exc() print(a) with open("finals.csv", "w+") as file: file.write("Year," + ",".join([str(x) for x in range(1, 9)]) + "\n") for year, alliances in data.items(): file.write(str(year) + ",")
import math from functions import getTBAdata DPs = {} with open("DistrictRankings/Ranking Points/world_RP.csv") as file: allteams = file.readlines() titles = allteams[0].strip().split(",") for team in allteams[1:]: team = team.strip().split(",") key = ("frc" if team[0][:2] == "frc" else "") + team[0] DPs[key] = {} for i, element in enumerate(team[1:], start=1): DPs[key][titles[i]] = float(element) event = input("event: ") teams = getTBAdata("event/" + event + "/teams/keys") matches = getTBAdata("event/" + event + "/matches/simple") runs = int(input("Iterations: ")) results = {team: [0] * len(teams) for team in teams} avg = {team: 0 for team in teams} match_results = [0] * len(matches) auto_results = [[0, 0] for i in matches] climb_results = [[0, 0] for i in matches] for i in range(runs): print(i) ev = {team: [0, 0] for team in teams} for match in matches: if match["comp_level"] != "qm": continue playing = match["alliances"]["red"]["team_keys"] + match["alliances"][ "blue"]["team_keys"]
"2019mosl", "2019azfl", "2019flor", "2019mxcm", "2019azpx", "2019flwp", "2019mxmo", "2019paca", "2019bcvi", "2019hiho", "2019mxto", "2019qcmo", "2019caav", "2019iacf", "2019ndgf", "2019qcqc", "2019cada", "2019idbo", "2019nvlv", "2019scmb", "2019cadm", "2019ilch", "2019nyli", "2019tnkn", "2019cafr", "2019ilpe", "2019nyli2", "2019tuis", "2019cala", "2019ksla", "2019nyny", "2019tuis2", "2019caln", "2019lake", "2019nyro", "2019utwv", "2019camb", "2019mndu", "2019nysu", "2019wila", "2019caoc", "2019mndu2", "2019nytr", "2019wimi" ] districts = [ "2019chs", "2019fim", "2019fnc", "2019in", "2019isr", "2019ne", "2019pch", "2019pnw", "2019tx", "2019ont", "2019fma" ] for event in regionals: teams = getTBAdata("event/" + event + "/teams/keys") ranked = [] for t in teams: try: ranked.append((t, allteams[t])) except: ranked.append((t, 0)) ranked = sorted(ranked, key=lambda x: x[1], reverse=True) print(event) picks[event] = ranked for district in districts: teams = getTBAdata("district/" + district + "/teams/keys") ranked = [] for t in teams: try:
from functions import getTBAdata import csv from scipy.stats.mstats import gmean from numpy import std dps = {} with open("DistrictRankings/YearlyPredictor/data_award.csv") as file: reader = csv.DictReader(file) for row in reader: dps[row["Team"]] = float(row["Avg"]) scores = [] events = getTBAdata("events/2019/keys") for event in events: print(event) teams = getTBAdata("event/" + event + "/teams/keys") if len(teams) < 2: continue localdps = [dps[t] if t in dps and dps[t]!=0 else 1 for t in teams] scores.append((event, gmean(localdps), std(localdps))) scores = sorted(scores, key=lambda x:x[1]/x[2], reverse=True) with open("DistrictRankings/YearlyPredictor/ranked_events.csv", "w+") as file: file.write("Event,Mean,StDev,Score\n") for e in scores: file.write(e[0] + "," + str(e[1]) + "," + str(e[2]) + "," + str(e[1]/e[2]) + "\n")
from functions import getTBAdata data = {} events = getTBAdata("events/2018/simple") for event in events: if event["event_type"] > 0: continue print(event["key"]) DPs = getTBAdata("event/" + event["key"] + "/district_points")["points"] statuses = getTBAdata("event/" + event["key"] + "/teams/statuses") ranking = [] for teamKey, dp in DPs.items(): try: alliance = {"alliance":statuses[teamKey]["alliance"]["number"], "pick":statuses[teamKey]["alliance"]["pick"]+1} except: alliance = {"alliance":-1, "pick":-1} if dp["award_points"]<10: ranking.append({"key":teamKey, "DP":dp, "qual":statuses[teamKey]["qual"]["ranking"]["rank"], "alliance":alliance}) ranking.sort(key=lambda x:(x["DP"]["total"], x["DP"]["elim_points"], x["DP"]["alliance_points"], x["DP"]["qual_points"]),reverse=True) data[event["key"]] = ranking with open("DistrictRankings/RegionalDistribution/regionals.csv", "w+") as file: file.write("Event,Team,DP Rank,Qual Rank,Alliance #,Alliance Pick,Qual DP,Alliance DP,Playoff DP,Awards DP,Total DP\n") for event, ranking in data.items(): for i, team in enumerate(ranking, start=1): file.write(event + "," + team["key"] + "," + str(i) + "," + str(team["qual"]) + "," +
import tkinter as tk from tkinter import filedialog from operator import itemgetter from functions import getTBAdata DPs = {} tk.Tk().withdraw() with open(filedialog.askopenfilename()) as file: allteams = file.readlines() titles = allteams[0].strip().split(",") for team in allteams[1:]: team = team.strip().split(",") DPs["frc" + team[0]] = {} for i, element in enumerate(team[1:], start=1): DPs["frc" + team[0]][titles[i]] = element teams = [] competing = getTBAdata("event/" + input("Event Key: ") + "/teams/keys") for team in competing: teams.append((team, float(DPs[team]["AdjDP"]))) teams = sorted(teams, key=itemgetter(1), reverse=True) print(teams)
team = team.strip().split(",") teams[team[0]] = (float(team[1]), float(team[2])) m = Basemap(projection='mill', llcrnrlon=-130, llcrnrlat=15, urcrnrlon=-66, urcrnrlat=55) # m = Basemap(projection='merc',llcrnrlat=-60,urcrnrlat=80,llcrnrlon=-180,urcrnrlon=180) m.drawcoastlines() m.drawmapboundary(fill_color='gray') m.fillcontinents(color='white', zorder=0) m.drawcountries(linewidth=1.2) m.drawstates(linewidth=.3) events = getTBAdata("events/2018") for event in events: if event["event_type"] > 2: continue print(event["key"]) # color = ["red", "blue", "#38b9ff"][event["event_type"]] color = [ "#ff4444", "#33ffff", "#f3ae09", "#68a429", "#6b3232", "#727211", "#33ccff" ][event["week"]] # color = "purple" teamkeys = getTBAdata("event/" + event["key"] + "/teams/keys") for teamkey in teamkeys: try: m.drawgreatcircle(teams[teamkey[3:]][1], teams[teamkey[3:]][0],
from functions import getTBAdata teams = {} events = getTBAdata("events/2018/simple") for event in events: if event["event_type"] <= 5: print(event["key"]) matches = getTBAdata("event/" + event["key"] + "/matches") for match in matches: if match["comp_level"] == "qm": for alliance in ["blue", "red"]: for team in match["alliances"][alliance]["team_keys"]: if team not in teams: teams[team] = [0, 0, 0, 0] teams[team][0] += 1 teams[team][1] += 2 if match[ "winning_alliance"] == alliance else 0 teams[team][2] += 1 if match["score_breakdown"][ alliance]["autoQuestRankingPoint"] else 0 teams[team][3] += 1 if match["score_breakdown"][ alliance]["faceTheBossRankingPoint"] else 0 with open("world_RP.csv", "w+") as file: file.write("Team,Avg Win RP,Adj Auto RP,Avg Climb RP\n") for team in teams: file.write(team + "," + str(teams[team][1] / teams[team][0]) + "," + str(teams[team][2] / teams[team][0]) + "," + str(teams[team][3] / teams[team][0]) + "\n")
from functions import getTBAdata file = open("champs_ranking.csv", "w+") file.write("Team #,DP,DivDP,OPR,CCWM,Region\n") for event, cmp in ([ "carv", "gal", "hop", "new", "roe", "tur", "arc", "cars", "cur", "dal", "dar", "tes" ], ["tx"] * 6 + ["mi"] * 6): print(event) teams = getTBAdata("event/2018" + event + "/district_points")["points"] metrics = getTBAdata("2018" + event + "/oprs") for teamKey in teams: DP = teams[teamKey]["total"] try: if getTBAdata("team/" + teamKey + "/event/2018" + event + "/status")["playoff"]["status"] == "won": print("einstein! " + str(DP)) einstein_matches = getTBAdata("team/" + teamKey + "/event/2018cmp" + cmp + "/matches") for match in einstein_matches: DP += 5 if ( teamKey in match["alliances"]["blue"]["team_keys"] ) != (match['winning_alliance'] == "red") else 0 einstein_awards = getTBAdata("team/" + teamKey + "/event/2018cmp" + cmp + "/awards") for award in einstein_awards: DP += 12 if award["award_type"] == 0 else 10 if award[ "award_type"] == 69 else 0 except: