def tester(event_code): event = frc.Event(event_code) realPoints = {} calculatedPoints = {} keys = set() print("Testing event {}".format(event_code)) if event.districtPoints == None: errorMessage = "districtPointGeneration test cannot be run on event {} because the TBA API doesn't provide district points to test against".format( event_code) raise Exception(errorMessage) if DEBUG: print("Getting real district points") first = True for team in event.getTeamList(): realPoints[team] = event.districtPoints["points"][team] if first: first = False keys = set(realPoints[team].keys()) event.districtPoints = None if DEBUG: print("Getting calculated district points") first = True for team in event.getTeamList(): calculatedPoints[team] = event.getDistrictPoints(team) if first: first = False keys = keys.union(set(calculatedPoints[team].keys())) if DEBUG: print("Generating point differences") for team in event.getTeamList(): if realPoints[team] != calculatedPoints[team]: print("{} calculation not consistent.".format(team)) if DEBUG: print(" {:20} Real Calc".format("Key")) for key in keys: rv = -1 cv = -1 if key in calculatedPoints[team]: cv = calculatedPoints[team][key] if key in realPoints[team]: rv = realPoints[team][key] print(" {:20} {:02d} {:02d}".format( key, int(rv), int(cv))) print("Done with event {}".format(event_code))
import frcstat as frc import time from scipy import stats from collections import defaultdict from tqdm import tqdm teamDict = defaultdict(lambda: [0, 0]) season = frc.Season(2017) for ev in tqdm(season.getOfficialEvents()): event = frc.Event(ev["key"]) try: for t in event.teamList: if event.coprs == None: event.coprs = event.getComponentOPRS() if event.coprs["autoFuelPoints"][event.lookup[t]] > teamDict[t][0]: teamDict[t][0] = event.coprs["autoFuelPoints"][event.lookup[t]] if event.coprs["teleopFuelPoints"][ event.lookup[t]] > teamDict[t][1]: teamDict[t][1] = event.coprs["teleopFuelPoints"][ event.lookup[t]] except: print(ev["key"]) with open("2017shooters.csv", 'w') as fp: for t in teamDict: fp.write("{},{},{}\n".format(t, str(teamDict[t][0]), str(teamDict[t][1])))
import frcstat as frc import time from scipy import stats cc = frc.Event("2017new", 1) coprs = cc.coprs lookup = cc.lookup i118 = lookup["frc118"] i1678 = lookup["frc1678"] zoprs = stats.zscore(cc.oprs) z = cc._assocArrayToDict(zoprs) with open("zscores.csv", 'w') as fp: for t in cc.getTeamList(): fp.write("{},{},{}\n".format(t, str(cc.oprs[lookup[t]]), str(z[t])))
import frcstat as frc from collections import defaultdict from tqdm import tqdm ''' For an event, this program will make a CSV of all the awards the teams and their highest OPRS from all the events that season ''' a = frc.Event("2016new") teamAwards = {} teamBestOPR = defaultdict(lambda: -1000000) savedOPRS = {} for t in tqdm(a.getTeamList()): fteam = frc.Team(t) teamAwards[t] = len(fteam.getAwardsByYear(2016)) fevents = fteam.getEventsByYear(2016) for event in fevents: if event["week"] != None: if event["key"] not in savedOPRS: fevent = frc.Event(event["key"]) savedOPRS[event["key"]] = fevent.scoreMetricFromPattern() if savedOPRS[event["key"]]["{}1".format(t)] > teamBestOPR[t]: teamBestOPR[t] = savedOPRS[event["key"]]["{}1".format(t)] with open("awardAndOPR.csv", "w") as fp: fp.write("Team,Awards,OPR\n") for t in a.getTeamList(): fp.write("{},{},{}\n".format(t, str(teamAwards[t]), str(teamBestOPR[t])))
We create x values we want to solve for as team variables with certain suffixes. B1 , B2 , B3 , R1 , R2 , R3 are the base variable creation strings to be used This means that we can append any string suffix to the end to create a variable we will be returned out B11 , B12 , B1_OPR , R1_WOWZERS are all valid variables that can be used Linear Combination Example B1_OPR + B2_OPR + B3_OPR - R1_DPR - R2_DPR - R3_DPR Evaluatable Constant Example B1 - score_breakdown_blue_foulPoints BS and RS can be used as the Blue Score value and Red Score Value respectively The way to see what variables are available to use for a certain event, run the function getValidPatternData(). A list of valid constant variables are returned that can be used in calculations """ cc = frc.Event("2017cc", 2) oprs = cc.scoreMetricFromPattern(cc.getCalculationPatterns()["OPR"]) #eq = "B1_P + B2_P + B3_P = BS - (score_breakdown_blue_foulPoints + score_breakdown_blue_kPaBonusPoints + score_breakdown_blue_teleopTakeoffPoints + score_breakdown_blue_autoMobilityPoints);" #eq += "R1_P + R2_P + R3_P = RS - (score_breakdown_red_foulPoints + score_breakdown_red_kPaBonusPoints + score_breakdown_red_teleopTakeoffPoints + score_breakdown_red_autoMobilityPoints)" eq = "B1_P + B2_P + B3_P = BS - (score_breakdown_blue_foulPoints);" eq += "R1_P + R2_P + R3_P = RS - (score_breakdown_red_foulPoints)" powerRating = cc.scoreMetricFromPattern(eq) with open("power.csv", 'w') as fp: for t in cc.getTeamList(): fp.write("{},{},{}\n".format(t, str(oprs["{}1".format(t)]), str(powerRating["{}_P".format(t)])))