diff --git a/scouting_addons/README.md b/scouting_addons/README.md new file mode 100644 index 0000000..2378f1f --- /dev/null +++ b/scouting_addons/README.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! 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