diff --git a/geo_activity_playground/core/activities.py b/geo_activity_playground/core/activities.py index 4244ecc..3b66868 100644 --- a/geo_activity_playground/core/activities.py +++ b/geo_activity_playground/core/activities.py @@ -48,6 +48,9 @@ def __len__(self) -> int: return len(self.meta) def add_activity(self, activity_meta: ActivityMeta) -> None: + assert not self.has_activity( + activity_meta["id"] + ), f"Trying to add the following activity which already exists: {activity_meta}" self._loose_activities.append(activity_meta) def commit(self) -> None: @@ -95,7 +98,9 @@ def iter_activities(self, new_to_old=True) -> Iterator[ActivityMeta]: @functools.lru_cache() def get_activity_by_id(self, id: int) -> ActivityMeta: - return self.meta.loc[id] + activity = self.meta.loc[id] + assert isinstance(activity["name"], str), activity["name"] + return activity @functools.lru_cache(maxsize=3000) def get_time_series(self, id: int) -> pd.DataFrame: diff --git a/geo_activity_playground/explorer/grid_file.py b/geo_activity_playground/explorer/grid_file.py index fd8fc19..0e5c5eb 100644 --- a/geo_activity_playground/explorer/grid_file.py +++ b/geo_activity_playground/explorer/grid_file.py @@ -1,3 +1,4 @@ +import json import logging from typing import Iterator from typing import Optional @@ -53,6 +54,11 @@ def make_explorer_rectangle( (x1, y1, zoom), ] ] + try: + json.dumps(properties) + except TypeError: + logger.error(f"Cannot serialize the following as JSON: {properties}") + raise return geojson.Feature( geometry=geojson.Polygon([[(coord[1], coord[0]) for coord in corners]]), properties=properties, diff --git a/geo_activity_playground/importers/strava_api.py b/geo_activity_playground/importers/strava_api.py index 5956306..528fec0 100644 --- a/geo_activity_playground/importers/strava_api.py +++ b/geo_activity_playground/importers/strava_api.py @@ -118,6 +118,9 @@ def try_import_strava(repository: ActivityRepository) -> None: for activity in tqdm( client.get_activities(after=get_after), desc="Downloading Strava activities" ): + # Sometimes we still get an activity here although it has already been imported from the Strava checkout. + if repository.has_activity(activity.id): + continue cache_file = ( pathlib.Path("Cache") / "Activity Metadata" / f"{activity.id}.pickle" )