From b53406d53d3cbeea4f0ea3b7ebf69e78fd090d16 Mon Sep 17 00:00:00 2001 From: Bart Hazen Date: Wed, 22 Jan 2020 22:39:41 +0100 Subject: [PATCH] Documentation and linting updates. --- src/__init__.py | 3 +++ src/api/__init__.py | 3 +++ src/api/odds.py | 22 ++++++++++++---------- src/autobet/__init__.py | 3 +++ src/autobet/autobet.py | 16 ++++++++++------ src/components/__init__.py | 3 +++ src/components/odds.py | 4 ++++ 7 files changed, 38 insertions(+), 16 deletions(-) diff --git a/src/__init__.py b/src/__init__.py index e69de29..981a1c5 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -0,0 +1,3 @@ +""" +Package to determine sure bets. +""" diff --git a/src/api/__init__.py b/src/api/__init__.py index e69de29..b1259e6 100644 --- a/src/api/__init__.py +++ b/src/api/__init__.py @@ -0,0 +1,3 @@ +""" +API methods. +""" diff --git a/src/api/odds.py b/src/api/odds.py index 948a9d0..71609eb 100644 --- a/src/api/odds.py +++ b/src/api/odds.py @@ -16,6 +16,8 @@ class OddsAPI: + """Connect to the-odds-api.""" + def __init__(self, config_file: Optional[str] = None): """ Initialise odds API. @@ -23,10 +25,10 @@ def __init__(self, config_file: Optional[str] = None): """ config = load_config(config_file if config_file else os.path.join(sys.prefix, 'autobet', 'config.yml')) - self._KEY = config.get('api', {}).get('key', '') - self._URL = config.get('api', {}).get('url', '') - self._REGION = config.get('api', {}).get('region', 'eu') - self._SITES = config.get('api', {}).get('sites', []) + self._key = config.get('api', {}).get('key', '') + self._url = config.get('api', {}).get('url', '') + self._region = config.get('api', {}).get('region', 'eu') + self._sites = config.get('api', {}).get('sites', []) def request(self, method: str, **params) -> Any: """ @@ -34,14 +36,14 @@ def request(self, method: str, **params) -> Any: :param method: Either odds or sports. :return: Response dictionary. """ - LOGGER.info('Called %s with params: %s', os.path.join(self._URL, f'{method}'), params) + LOGGER.info('Called %s with params: %s', os.path.join(self._url, f'{method}'), params) if method not in ['sports', 'odds']: raise NotImplementedError(f'Request method {method} does not exist.') response = requests.get( - os.path.join(self._URL, f'{method}'), - params={**{'api_key': self._KEY}, **params} + os.path.join(self._url, f'{method}'), + params={**{'api_key': self._key}, **params} ) if response.status_code == 200: @@ -71,7 +73,7 @@ def get_odds(self, sport: str) -> List[Odds]: """ Get list of odds for a specific sport. :param sport: Sports keys - :return: List of odds. + :return: List of odds. """"" sports_keys = self.get_sports_key(sport) @@ -79,12 +81,12 @@ def get_odds(self, sport: str) -> List[Odds]: for key in sports_keys: if input(f'Would you like to retrieve data for {key}? [Y/n]').lower() in ['', 'y', 'yes']: - odds_list = self.request('odds', sport=key, region=self._REGION) + odds_list = self.request('odds', sport=key, region=self._region) for odds_item in odds_list: odds_item['sites'] = [Site(**s) for s in odds_item['sites'] - if s['site_key'] in self._SITES or not self._SITES] + if s['site_key'] in self._sites or not self._sites] odds.append(Odds(**odds_item)) diff --git a/src/autobet/__init__.py b/src/autobet/__init__.py index e69de29..a6a9411 100644 --- a/src/autobet/__init__.py +++ b/src/autobet/__init__.py @@ -0,0 +1,3 @@ +""" +Autobet module. +""" diff --git a/src/autobet/autobet.py b/src/autobet/autobet.py index 3640833..b1a200b 100644 --- a/src/autobet/autobet.py +++ b/src/autobet/autobet.py @@ -14,18 +14,14 @@ @dataclass class AutoBetStats: + """Allow easily accessible statistics object creation""" min_index: int min_value: float max_index: int max_value: float - def __gt__(self, other: AutoBetStats) -> bool: - return self.min_value > other.min_value - - def __lt__(self, other: AutoBetStats) -> bool: - return not self.min_value > other.min_value - def sure_bet(self, other: AutoBetStats) -> Tuple[bool, int, int]: + """Determine whether a sure bet can be found""" sure_bet_max = 1 / self.max_value + 1 / other.max_value if sure_bet_max < 1: @@ -34,21 +30,29 @@ def sure_bet(self, other: AutoBetStats) -> Tuple[bool, int, int]: return False, 0, 0 def sure_bet_profit(self, other: AutoBetStats) -> float: + """Determine the most profitable bet.""" return 1 - (1 / self.max_value + 1 / other.max_value) class AutoBet: + """ + Automatically find the right bets. + """ + def __init__(self, odds: List[Odds]): + """Initialise instance.""" self._odds = odds @staticmethod def minmax(odds: List[float]) -> AutoBetStats: + """Find the minimum and maximum values for the odds across all sites.""" min_index, min_value = min(enumerate(odds), key=lambda p: p[1]) max_index, max_value = max(enumerate(odds), key=lambda p: p[1]) return AutoBetStats(min_index, min_value, max_index, max_value) def make_suggestions(self) -> List[Dict[str, Any]]: + """Make suggestions for sure bets.""" suggestions = [] for match in self._odds: if match.sites: diff --git a/src/components/__init__.py b/src/components/__init__.py index e69de29..ec6c51c 100644 --- a/src/components/__init__.py +++ b/src/components/__init__.py @@ -0,0 +1,3 @@ +""" +Additional required components. +""" diff --git a/src/components/odds.py b/src/components/odds.py index dc7c564..49dc9fc 100644 --- a/src/components/odds.py +++ b/src/components/odds.py @@ -7,6 +7,9 @@ @dataclass class Site: + """ + Site object + """ site_key: str site_nice: str last_update: int @@ -32,4 +35,5 @@ class Odds: @property def away_team(self): + """Find away team""" return self.teams[abs(self.teams.index(self.home_team) - 1)]