Skip to content

Commit

Permalink
Merge branch 'main' of github.com:RyanAugust/GoldenCheetahAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanAugust committed Jul 29, 2024
2 parents 770064a + 86b662a commit cfc7f9c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/cheetahpy/cheetahpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import pandas as pd
import io

import logging

logger = logging.getLogger(__name__)

class URLs:
"""Class for retrieving GC AIP URL paths"""
Expand Down Expand Up @@ -73,7 +76,7 @@ def show_athletes(self):
try:
available_athletes = ', '.join(self.athletes)
except Exception as err:
print(f"{err}: Athletes undefinded, referencing API to load athletes")
logger.warning(f"{err}: Athletes undefinded, referencing API to load athletes")
self._get_athletes()
available_athletes = ', '.join(self.athletes)
print(available_athletes)
Expand All @@ -100,7 +103,7 @@ def _validate_athlete(self, athlete:str) -> bool:
try:
available_athletes = ', '.join(self.athletes)
except Exception as err:
print(f"{err}: Athletes undefinded, referencing API to load athletes")
logger.warning(f"{err}: Athletes undefinded, referencing API to load athletes")
self._get_athletes()
available_athletes = ', '.join(self.athletes)
assert athlete in self.athletes, f"Invalid athlete. Choose from:\n {available_athletes}"
Expand Down
7 changes: 5 additions & 2 deletions src/cheetahpy/local_opendata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import os
import json
import pandas as pd
import logging

logger = logging.getLogger(__name__)

class opendata_dataset(object):
def __init__(self, root_dir:str):
Expand Down Expand Up @@ -90,7 +92,7 @@ def _athlete_summary_path(self, athlete_id: str) -> str:
return ath_summary_path

@staticmethod
def _safe_convert(original_series:pd.Series, type_convert:type) -> pd.Series:
def _safe_convert(original_series:pd.Series, type_convert:type, warn_on_convert:bool=False) -> pd.Series:
try:
new_series = original_series.astype(type_convert)
return new_series
Expand All @@ -100,7 +102,8 @@ def _safe_convert(original_series:pd.Series, type_convert:type) -> pd.Series:
a_value_type = type(a_value[0])
else:
a_value_type = "UNKNOWN"
print(f'{err}: cannot convert {original_series.name} (of type: {a_value_type}) to type {type_convert}')
if warn_on_convert:
logger.warning(f'[{err}] cannot convert {original_series.name} (of type: {a_value_type}) to type {type_convert}')
return original_series

@staticmethod
Expand Down

0 comments on commit cfc7f9c

Please sign in to comment.