Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scouting_addons/README.md
Original file line number Diff line number Diff line change
@@ -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!
85 changes: 85 additions & 0 deletions scouting_addons/match_schedule_csv_maker.py
Original file line number Diff line number Diff line change
@@ -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)
Loading