From fbc795ec03b16733ac3326a96ea57569576a6c41 Mon Sep 17 00:00:00 2001 From: Tristan Date: Mon, 10 Nov 2025 18:24:22 -0800 Subject: [PATCH 1/2] match to csv --- scouting_addons/match_schedule_csv_maker.py | 85 +++++++++++++++++++++ scouting_addons/readme_addons.md | 1 + 2 files changed, 86 insertions(+) create mode 100644 scouting_addons/match_schedule_csv_maker.py create mode 100644 scouting_addons/readme_addons.md diff --git a/scouting_addons/match_schedule_csv_maker.py b/scouting_addons/match_schedule_csv_maker.py new file mode 100644 index 0000000..3a2100a --- /dev/null +++ b/scouting_addons/match_schedule_csv_maker.py @@ -0,0 +1,85 @@ +from operator import concat + +import requests +import json +import re +import csv + +event_key = "2025wasam" +TBA_key = "YOUR_TBA_KEY" + +base_url = "https://www.thebluealliance.com/api/v3/event/" + event_key +team_url = base_url + "/teams?X-TBA-Auth-Key=" + TBA_key +print(team_url) +match_url = base_url + "/matches/simple?X-TBA-Auth-Key=" + TBA_key +print(match_url) + +# Get teams list +r = requests.get(team_url) +r_json = r.json() +teams_list = [[0 for i in range(2)] for j in range(len(r_json))] +i = 0 +for team in r_json: + teams_list[i][0] = (team["team_number"]) + i += 1 + +teams_list.sort() +print(teams_list) + + +#Get match schedule +match_raw = requests.get(match_url) +match_json = match_raw.json() +qual_matches = [] +for match in match_json: + if match["comp_level"] == "qm": + qual_matches.append(match) + +matches = [[0 for i in range(7)] for j in range(len(qual_matches))] +i = 0 +for match in match_json: + if match["comp_level"] == "qm": + for j in range(3): + matches[i][0] = match["match_number"] + only_red = int(re.sub('[^0-9]', '', match["alliances"]["red"]["team_keys"][j])) + matches[i][j+1] = only_red + only_blue = int(re.sub('[^0-9]', '', match["alliances"]["blue"]["team_keys"][j])) + matches[i][j+4] = only_blue + i += 1 + +matches.sort() +print(matches) + +my_matches = [] +previous_matches = [[]] + +for match in matches: + previous_setup = [] + for team in match: + for team2 in teams_list: + if team == team2[0]: + previous_setup.append(team2[1]) + previous_matches.append(previous_setup) + for i in range(1,6): + for team in teams_list: + if match[i] == team[0]: + team[1] = match[0] + +csv_matches = [[]] +for idx, match in enumerate(matches): + to_write = [] + for d in match: + to_write.append(d) + for d in previous_matches[idx+1]: + to_write.append(d) + csv_matches.append(to_write) +csv_matches.pop(0) + +print(previous_matches) +print(teams_list) + +with open("test.csv", 'w', newline='') as csvfile: + fieldnames = ['math', 'r1', 'r2', 'r3', 'b1', 'b2', 'b3', 'prev_r1', 'prev_r2', 'prev_r3', 'prev_b1', 'prev_b2', 'prev_b3'] + writer = csv.writer(csvfile) + writer.writerow(fieldnames) + writer.writerows(csv_matches) \ No newline at end of file diff --git a/scouting_addons/readme_addons.md b/scouting_addons/readme_addons.md new file mode 100644 index 0000000..4836518 --- /dev/null +++ b/scouting_addons/readme_addons.md @@ -0,0 +1 @@ +The python script will generate a CSV file for the given event code with matches and previous matches. You need to give it your TBA key and event code by editing the python file directly. Works on my machine! \ No newline at end of file From ff599d38c4925ad22b11cdac67678503c176d60e Mon Sep 17 00:00:00 2001 From: Tristan <50113330+TrisDooley@users.noreply.github.com> Date: Mon, 10 Nov 2025 18:30:33 -0800 Subject: [PATCH 2/2] Rename readme_addons.md to README.md --- scouting_addons/{readme_addons.md => README.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename scouting_addons/{readme_addons.md => README.md} (91%) diff --git a/scouting_addons/readme_addons.md b/scouting_addons/README.md similarity index 91% rename from scouting_addons/readme_addons.md rename to scouting_addons/README.md index 4836518..2378f1f 100644 --- a/scouting_addons/readme_addons.md +++ b/scouting_addons/README.md @@ -1 +1 @@ -The python script will generate a CSV file for the given event code with matches and previous matches. You need to give it your TBA key and event code by editing the python file directly. Works on my machine! \ No newline at end of file +The python script will generate a CSV file for the given event code with matches and previous matches. You need to give it your TBA key and event code by editing the python file directly. Works on my machine!