def store_local_data(): sn_json = api.Session(auth.username, auth.key, season=2017, data_format="json") sn_xml = api.Session(auth.username, auth.key, season=2017, data_format="xml") os.chdir("C:/Users/stacy/OneDrive/Projects/FIRST_API/tbap/data") season_json = api.get_season(sn_json) with open("season_json.pickle", "wb") as f: pickle.dump(season_json, f, pickle.HIGHEST_PROTOCOL) season_xml = api.get_season(sn_xml) with open("season_xml.pickle", "wb") as f: pickle.dump(season_xml, f, pickle.HIGHEST_PROTOCOL) status_json = api.get_status(sn_json) with open("status_json.pickle", "wb") as f: pickle.dump(status_json, f, pickle.HIGHEST_PROTOCOL) status_xml = api.get_status(sn_xml) with open("status_xml.pickle", "wb") as f: pickle.dump(status_xml, f, pickle.HIGHEST_PROTOCOL) districts_json = api.get_districts(sn_json) with open("districts_json.pickle", "wb") as f: pickle.dump(districts_json, f, pickle.HIGHEST_PROTOCOL) districts_xml = api.get_districts(sn_xml) with open("districts_xml.pickle", "wb") as f: pickle.dump(districts_xml, f, pickle.HIGHEST_PROTOCOL) events_json = api.get_events(sn_json, district="PNW") with open("events_json.pickle", "wb") as f: pickle.dump(events_json, f, pickle.HIGHEST_PROTOCOL) events_xml = api.get_events(sn_xml, district="PNW") with open("events_jxml.pickle", "wb") as f: pickle.dump(events_xml, f, pickle.HIGHEST_PROTOCOL) teams_json = api.get_teams(sn_json, district="PNW") with open("teams_json.pickle", "wb") as f: pickle.dump(teams_json, f, pickle.HIGHEST_PROTOCOL) teams_xml = api.get_teams(sn_xml, district="PNW") with open("teams_xml.pickle", "wb") as f: pickle.dump(teams_xml, f, pickle.HIGHEST_PROTOCOL)
def test_robots(self): sn = api.Session(auth.username, auth.key) team = api.get_team(sn, "frc1318", response="robots") tdata = {"shape": (4, 3), "args": ["team", "frc1318", "robots"], "index_name": "key", "spotcheck": ("frc1318_2017", "robot_name", "Cerberus")} CheckResults.frame(team, tdata)
def test_year_full(self): sn = api.Session(auth.username, auth.key) events = api.get_events(sn, year=2016) tdata = {"shape": (203, 32), "args": ["events", 2016], "index_name": "key", "spotcheck": ("2016waamv", "city", "Auburn")} CheckResults.frame(events, tdata)
def test_years(self): sn = api.Session(auth.username, auth.key) team = api.get_team(sn, "frc1318", response="years_participated") tdata = {"shape": (15, 1), "args": ["team", "frc1318", "years_participated"], "spotcheck": (0, "year", 2004)} CheckResults.frame(team, tdata)
def test_simple(self): sn = api.Session(auth.username, auth.key) team = api.get_team(sn, "frc1318", response="simple") tdata = {"shape": (1, 6), "args": ["team", "frc1318", "simple"], "index_name": "key", "spotcheck": ("frc1318", "team_number", 1318)} CheckResults.frame(team, tdata)
def test_full(self): sn = api.Session(auth.username, auth.key) team = api.get_team(sn, "frc1318") tdata = {"shape": (1, 18), "args": ["team", "frc1318"], "index_name": "key", "spotcheck": ("frc1318", "motto", "Robots Don't Quit!")} CheckResults.frame(team, tdata)
def test_event_full(self): sn = api.Session(auth.username, auth.key) sn.time_zone = "America/Chicago" matches = api.get_matches(sn, "2017tur") tdata = {"shape": (770, 47), "args": ["event", "2017tur", "matches"]} CheckResults.frame(matches, tdata) assert matches.loc["2017tur_f1m2"].at["frc1318", "score"] == 461
def test_event_keys(self): sn = api.Session(auth.username, auth.key) matches = api.get_matches(sn, "2017tur", response="keys") tdata = {"shape": (128, 1), "args": ["event", "2017tur", "matches", "keys"], "spotcheck": (60, "key", "2017tur_qm43")} CheckResults.frame(matches, tdata)
def test_get_insights(self): sn = api.Session(auth.username, auth.key) insights = api.get_insights(sn, event="2017pncmp") tdata = {"shape": (64, 3), "args": ["event", "2017pncmp", "insights"]} CheckResults.frame(insights, tdata) assert (insights.loc["qual", "average_fuel_points"]. at["value_0"] == pytest.approx(7.652344))
def test_team_year(self): sn = api.Session(auth.username, auth.key) awards = api.get_awards(sn, team="frc1318", year=2017) tdata = {"shape": (9, 6), "args": ["team", "frc1318", "awards", 2017], "spotcheck": (8, "name", "District Chairman's Award")} CheckResults.frame(awards, tdata)
def test_event(self): sn = api.Session(auth.username, auth.key) awards = api.get_awards(sn, event="2017tur") tdata = {"shape": (15, 6), "args": ["event", "2017tur", "awards"], "spotcheck": (3, "team_key", "frc2907")} CheckResults.frame(awards, tdata)
def test_event(self): sn = api.Session(auth.username, auth.key) alliances = api.get_alliances(sn, event="2017pncmp") tdata = {"shape": (25, 11), "args": ["event", "2017pncmp", "alliances"]} CheckResults.frame(alliances, tdata) assert alliances.loc["Alliance 8", "frc2907"]["current_level_wins"] == 1
def test_team(self): sn = api.Session(auth.username, auth.key) awards = api.get_awards(sn, team="frc1318") tdata = {"shape": (57, 6), "args": ["team", "frc1318", "awards"], "spotcheck": (15, "event_key", "2014waahs")} CheckResults.frame(awards, tdata)
def test_team_event(self): sn = api.Session(auth.username, auth.key) awards = api.get_awards(sn, team="frc1318", event="2017pncmp") tdata = {"shape": (3, 6), "args": ["team", "frc1318", "event", "2017pncmp", "awards"], "spotcheck": (0, "team_key", "frc3238")} CheckResults.frame(awards, tdata)
def test_rankings(self): sn = api.Session(auth.username, auth.key) rankings = api.get_district_rankings(sn, "2017pnw") tdata = {"shape": (376, 11), "args": ["district", "2017pnw", "rankings"], "spotcheck": (0, "team_key", "frc3238")} CheckResults.frame(rankings, tdata)
def test_simple(self): sn = api.Session(auth.username, auth.key) teams = api.get_teams(sn, page=1, response="simple") tdata = {"shape": (378, 6), "args": ["teams", 1, "simple"], "index_name": "key", "spotcheck": ("frc503", "state_prov", "Michigan")} CheckResults.frame(teams, tdata)
def test_event_rankings(self): sn = api.Session(auth.username, auth.key) rankings = api.get_event_rankings(sn, "2017pncmp") tdata = {"shape": (64, 14), "args": ["event", "2017pncmp", "rankings"], "spotcheck": (3, "team", "frc2046")} CheckResults.frame(rankings, tdata)
def test_get_predictions(self): sn = api.Session(auth.username, auth.key) pred = api.get_predictions(sn, event="2017pncmp") # Check event_stats tdata = {"shape": (14, 1), "args": ["event", "2017pncmp", "predictions"]} CheckResults.frame(pred["event_stats"], tdata) assert (pred["event_stats"].loc["playoff", "brier_scores_gears"]. at["value"] == pytest.approx(0.075659, rel=1e-5)) # Check predictions tdata = {"shape": (2628, 1), "args": ["event", "2017pncmp", "predictions"]} CheckResults.frame(pred["predictions"], tdata) assert (pred["predictions"]. loc["qual", "2017pncmp_qm1", "blue", "gears"]. at["value"] == pytest.approx(5.12684, rel=1e-5)) # Check team rankings tdata = {"shape": (64, 2), "args": ["event", "2017pncmp", "predictions"]} CheckResults.frame(pred["team_rankings"], tdata) assert (pred["team_rankings"]. loc["frc2046"]. at["points"] == pytest.approx(24, rel=1e-2)) # Check team stats tdata = {"shape": (768, 1), "args": ["event", "2017pncmp", "predictions"]} CheckResults.frame(pred["team_stats"], tdata) assert (pred["team_stats"]. loc["frc2907", "score", "mean", "playoff"]. at["value"] == pytest.approx(108.635760, rel=1e-5))
def test_team_simple(self): sn = api.Session(auth.username, auth.key) events = api.get_events(sn, team="frc1318", year="2017") tdata = {"shape": (8, 32), "args": ["team", "frc1318", "events", "2017"], "spotcheck": ("2017cmptx", "event_type_string", "Championship Finals")} CheckResults.frame(events, tdata)
def test_team_year_full(self): sn = api.Session(auth.username, auth.key) matches = api.get_matches(sn, team="frc1318", year="2017") tdata = {"shape": (642, 47), "args": ["team", "frc1318", "matches", "2017"]} assert matches.loc["2017tur_f1m1"].at["frc2046", "teleopFuelPoints"] == 21 CheckResults.frame(matches, tdata)
def test_creation(self): session = api.Session("username", "key") assert session.username == "username" assert session.key == "key" assert session.season == int(datetime.date.today().strftime("%Y")) assert session.data_format == "dataframe" assert session.source == "production"
def test_team_event_status(self): sn = api.Session(auth.username, auth.key) ets = api.get_event_team_status(sn, "2017tur", "frc1318") tdata = {"shape": (34, 1), "args": ["team", "frc1318", "event", "2017tur", "status"], "spotcheck": ("alliance_status_str", "value", r"<b>Captain</b> of <b>Alliance 3</b>")} CheckResults.frame(ets, tdata)
def test_event_team_simple(self): sn = api.Session(auth.username, auth.key) matches = api.get_matches(sn, "2017tur", team="frc1318", response="simple") tdata = {"shape": (102, 12), "args": ["team", "frc1318", "event", "2017tur", "matches", "simple"]} assert matches.loc["2017tur_qm52"].at["frc1318", "score"] == 253 CheckResults.frame(matches, tdata)
def test_match(self): sn = api.Session(auth.username, auth.key) matches = api.get_matches(sn, match="2017wasno_qm79") tdata = {"shape": (6, 47), "args": ["match", "2017wasno_qm79"]} CheckResults.frame(matches, tdata) act_time = matches.loc["2017wasno_qm79"].at["frc4077", "actual_time"] CheckResults.timestamp(act_time, 2017, 3, 26, 11, 24, 20, 61200)
def test_event_simple(self): sn = api.Session(auth.username, auth.key, time_zone="America/Chicago") matches = api.get_matches(sn, "2017tur", response="simple") tdata = {"shape": (770, 12), "args": ["event", "2017tur", "matches", "simple"]} CheckResults.frame(matches, tdata) CheckResults.timestamp(matches.loc["2017tur_f1m2"].at["frc2046", "time"], 2017, 4, 22, 12, 13, 0, 68400) assert matches.attr["timezone"] == "America/Chicago"
def test_districts(self): sn = api.Session(auth.username, auth.key) dist = api.get_districts(sn, 2017) tdata = {"shape": (10, 3), "args": ["districts", 2017], "index_name": "key", "spotcheck": ("2017pnw", "display_name", "Pacific Northwest")} CheckResults.frame(dist, tdata) lm = dist.attr["Last-Modified"] dist2 = api.get_districts(sn, 2017, mod_since=lm) CheckResults.empty(dist2, lm)
def test_build_url(self): sn = api.Session("username", "key", source="staging") args = { "eventCode": None, "teamNumber": "1318", "excludeDistrict": False } url = server.build_first_url(sn, "districts", args) assert url == ("https://frc-staging-api.firstinspires.org" + "/v2.0/2017/districts" + "?teamNumber=1318&excludeDistrict=false")
def test_full(self): sn = api.Session(auth.username, auth.key) teams = api.get_teams(sn, page=1) tdata = {"shape": (378, 18), "args": ["teams", 1], "index_name": "key", "spotcheck": ("frc501", "nickname", "The PowerKnights")} CheckResults.frame(teams, tdata) lm = teams.attr["Last-Modified"] teams = api.get_teams(sn, page=1, mod_since=lm) CheckResults.empty(teams, lm)
def test_get_district_points(self): sn = api.Session(auth.username, auth.key) pts = api.get_district_points(sn, event="2017pncmp") # Check event_stats tdata = {"shape": (68, 5), "args": ["event", "2017pncmp", "district_points"], "spotcheck": ("frc1318", "total", 81)} CheckResults.frame(pts["points"], tdata) # Check predictions tdata = {"shape": (192, 3), "args": ["event", "2017pncmp", "district_points"]} CheckResults.frame(pts["high_scores"], tdata) assert pts["high_scores"].loc["frc2046"].iat[0, 0] == 379
def test_errors(self): with pytest.raises(ValueError): api.Session("username", "key", season=2014) with pytest.raises(ValueError): future_year = int(datetime.date.today().strftime("%Y")) + 2 api.Session("username", "key", season=future_year) with pytest.raises(TypeError): session = api.Session("username", "key") session.data_format = True with pytest.raises(ValueError): session = api.Session("username", "key") session.data_format = "yaml" with pytest.raises(TypeError): api.Session(42, "key") with pytest.raises(TypeError): api.Session("username", True)