mirror of
https://github.com/MoonlitJolteon/frc-stat-predictor.git
synced 2025-11-01 13:40:21 +00:00
TBA Connector can now retrieve data, still need to figure out performance metrics
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@ -1 +1,2 @@
|
||||
config.json
|
||||
config.json
|
||||
*/**/__pycache__
|
||||
@ -28,17 +28,19 @@ class DataSource(ABC):
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def get_team_data(self, team_number: int):
|
||||
"""Retrieve data for a specific team
|
||||
def get_team_info(self, team_number: int):
|
||||
"""Retrieve information about a specific team
|
||||
team_number: int
|
||||
The team you want to retrieve data for
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def get_event_matches(self, event_code: str):
|
||||
def get_event_matches(self, event_code: str, team_number: int | None = None):
|
||||
"""Retrieve matches for a specific event
|
||||
event_code: str
|
||||
The eventcode for the event you want to retrieve match data from
|
||||
team_number: int | None
|
||||
The team you want to retrieve data for, if not provided will get all matches reguardless of teams
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
|
||||
@ -20,16 +20,38 @@ class TheBlueAllianceConnector(DataSource):
|
||||
self.__api_token = api_token
|
||||
self.__observed_year = year
|
||||
self.__base_url = "https://www.thebluealliance.com/api/v3"
|
||||
self._headers = {"X-TBA-Auth-Key": self.__api_token}
|
||||
self.__headers = {"X-TBA-Auth-Key": self.__api_token}
|
||||
|
||||
def get_status(self) -> tuple[DataSourceStatus, dict]:
|
||||
pass
|
||||
url = f"{self.__base_url}/status"
|
||||
response = requests.get(url, headers=self.__headers)
|
||||
if response.status_code == 200:
|
||||
response_json = response.json()
|
||||
return (DataSourceStatus.CONNECTED, {"extra_info": response_json})
|
||||
if response.status_code == 401:
|
||||
return (DataSourceStatus.UNAUTHENTICATED, {})
|
||||
|
||||
def get_team_data(self, team_number: int):
|
||||
pass
|
||||
def get_team_info(self, team_number: int) -> dict | None:
|
||||
url = f"{self.__base_url}/team/frc{team_number}"
|
||||
response = requests.get(url, headers=self.__headers)
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
return None
|
||||
|
||||
def get_event_matches(self, event_code: str):
|
||||
pass
|
||||
def get_event_matches(
|
||||
self, event_code: str, team_number: int | None = None
|
||||
) -> dict | None:
|
||||
if team_number != None:
|
||||
url = f"{self.__base_url}/team/frc{team_number}/event/{event_code}/matches"
|
||||
response = requests.get(url, headers=self.__headers)
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
else:
|
||||
url = f"{self.__base_url}/event/{event_code}/matches"
|
||||
response = requests.get(url, headers=self.__headers)
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
return None
|
||||
|
||||
def get_team_performance_metrics(self, team_number, event_code=None):
|
||||
pass
|
||||
def get_team_performance_metrics(self, team_number, event_code=None) -> dict | None:
|
||||
pass # TODO: Decide what performance metrics I care about from TBA, how to calculate them, etc.
|
||||
|
||||
Reference in New Issue
Block a user