Skip to content

Commit

Permalink
Fix issue where activities are downloaded twice
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-ueding committed Feb 3, 2024
1 parent eac8e04 commit 3ca523d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion geo_activity_playground/core/activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions geo_activity_playground/explorer/grid_file.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import logging
from typing import Iterator
from typing import Optional
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions geo_activity_playground/importers/strava_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down

0 comments on commit 3ca523d

Please sign in to comment.