mirror of
https://github.com/MoonlitJolteon/frc-stat-predictor.git
synced 2025-11-02 22:05:03 +00:00
TBA Connector can now retrieve data, still need to figure out performance metrics
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
config.json
|
config.json
|
||||||
|
*/**/__pycache__
|
||||||
@ -28,17 +28,19 @@ class DataSource(ABC):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_team_data(self, team_number: int):
|
def get_team_info(self, team_number: int):
|
||||||
"""Retrieve data for a specific team
|
"""Retrieve information about a specific team
|
||||||
team_number: int
|
team_number: int
|
||||||
The team you want to retrieve data for
|
The team you want to retrieve data for
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@abstractmethod
|
@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
|
"""Retrieve matches for a specific event
|
||||||
event_code: str
|
event_code: str
|
||||||
The eventcode for the event you want to retrieve match data from
|
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
|
@abstractmethod
|
||||||
|
|||||||
@ -20,16 +20,38 @@ class TheBlueAllianceConnector(DataSource):
|
|||||||
self.__api_token = api_token
|
self.__api_token = api_token
|
||||||
self.__observed_year = year
|
self.__observed_year = year
|
||||||
self.__base_url = "https://www.thebluealliance.com/api/v3"
|
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]:
|
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):
|
def get_team_info(self, team_number: int) -> dict | None:
|
||||||
pass
|
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):
|
def get_event_matches(
|
||||||
pass
|
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):
|
def get_team_performance_metrics(self, team_number, event_code=None) -> dict | None:
|
||||||
pass
|
pass # TODO: Decide what performance metrics I care about from TBA, how to calculate them, etc.
|
||||||
|
|||||||
Reference in New Issue
Block a user