From d772e9a163af4d32017bf66bfdbab5666f74e9c4 Mon Sep 17 00:00:00 2001 From: Moonlit Jolteon Date: Mon, 17 Mar 2025 10:53:31 -0400 Subject: [PATCH] Added abstract data_source class and tba datasource --- data_sources/base.py | 52 ++++++++++++++++++++++++++++++++++++++++++++ data_sources/tba.py | 35 +++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 data_sources/base.py create mode 100644 data_sources/tba.py diff --git a/data_sources/base.py b/data_sources/base.py new file mode 100644 index 0000000..47f22a1 --- /dev/null +++ b/data_sources/base.py @@ -0,0 +1,52 @@ +from abc import ABC, abstractmethod +from enum import Enum + + +class DataSourceStatus(Enum): + CONNECTED = 1 + UNAUTHENTICATED = 2 + NOT_FOUND = 3 + + +class DataSource(ABC): + """Abstract base class for all data sources""" + + @abstractmethod + def get_status(self) -> tuple[DataSourceStatus, dict]: + """ + Retrieves the status of the data source along with any additional information. + + Returns: + ------- + tuple[DataSourceStatus, dict] + A tuple containing the data source status and a dictionary. + The dictionary may include extra information under the keys "errors" and "extra_info". + + Notes: + ----- + The errors and extra_info may be missing if there is nothing to be sent in them. + """ + + @abstractmethod + def get_team_data(self, team_number: int): + """Retrieve data for a specific team + team_number: int + The team you want to retrieve data for + """ + + @abstractmethod + def get_event_matches(self, event_code: str): + """Retrieve matches for a specific event + event_code: str + The eventcode for the event you want to retrieve match data from + """ + + @abstractmethod + def get_team_performance_metrics(self, team_number, event_code=None): + """Get performance metrics for a team, optionally at a specific event + + team_number: int + The team you want to retrieve data for + + (Optional) event_code: str | None + The eventcode for the event you want to retrieve match data from""" diff --git a/data_sources/tba.py b/data_sources/tba.py new file mode 100644 index 0000000..bfa534e --- /dev/null +++ b/data_sources/tba.py @@ -0,0 +1,35 @@ +import requests +from data_sources.base import DataSource, DataSourceStatus +from datetime import datetime + + +class TheBlueAllianceConnector(DataSource): + """Data source to handle pulling data from TheBlueAlliance.com""" + + def __init__(self, api_token: str, year=datetime.now().year): + """ + Initializes the class instance with an API token and a specific year. + + Args + ----- + api_token : str + The authentication token required for API access. + year : int, optional + The year for which data will be retrieved. Defaults to the current year. + """ + 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} + + def get_status(self) -> tuple[DataSourceStatus, dict]: + pass + + def get_team_data(self, team_number: int): + pass + + def get_event_matches(self, event_code: str): + pass + + def get_team_performance_metrics(self, team_number, event_code=None): + pass