Skip to content

Commit

Permalink
Showing 9 changed files with 36 additions and 23 deletions.
22 changes: 15 additions & 7 deletions geo_activity_playground/__main__.py
Original file line number Diff line number Diff line change
@@ -2,15 +2,16 @@
import os
import pathlib

from .core.sources import DirectoryTimeSeriesSource
from .core.sources import TimeSeriesSource
from .explorer.grid_file import get_border_tiles
from .explorer.grid_file import get_explored_tiles
from .explorer.grid_file import make_grid_file_geojson
from .explorer.grid_file import make_grid_file_gpx
from .explorer.video import explorer_video_main
from .heatmap import generate_heatmaps_per_cluster
from geo_activity_playground.core.sources import TimeSeriesSource
from geo_activity_playground.strava.api_access import StravaAPITimeSeriesSource
from geo_activity_playground.strava.importing import StravaExportTimeSeriesSource
from .strava.api_access import StravaAPITimeSeriesSource
from .strava.importing import StravaExportTimeSeriesSource


def main() -> None:
@@ -19,14 +20,19 @@ def main() -> None:
)
parser.set_defaults(func=lambda options: parser.print_help())
parser.add_argument("--basedir", type=pathlib.Path, default=pathlib.Path.cwd())
parser.add_argument("--source", choices=["api", "export"], default="api")
parser.add_argument(
"--source",
choices=["strava-api", "strava-export", "directory"],
default="strava-api",
)

subparsers = parser.add_subparsers(
description="The tools are organized in subcommands.", metavar="Command"
)

subparser = subparsers.add_parser(
"explorer-missing", help="Generate GPX file with missing explorer tiles."
"explorer",
help="Generate GeoJSON/GPX files with explored and missing explorer tiles.",
)
subparser.set_defaults(
func=lambda options: main_explorer(
@@ -66,8 +72,10 @@ def make_time_series_source(basedir: pathlib.Path, source: str) -> TimeSeriesSou
os.chdir(basedir)

ts_source: TimeSeriesSource
if source == "api":
if source == "strava-api":
ts_source = StravaAPITimeSeriesSource()
elif source == "export":
elif source == "strava-export":
ts_source = StravaExportTimeSeriesSource()
elif source == "directory":
ts_source = DirectoryTimeSeriesSource()
return ts_source
2 changes: 1 addition & 1 deletion geo_activity_playground/core/activity_parsers.py
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
import gpxpy
import pandas as pd

from geo_activity_playground.core.caching import cache_parquet
from .caching import cache_parquet


def read_fit_activity(path: pathlib.Path, open) -> pd.DataFrame:
8 changes: 8 additions & 0 deletions geo_activity_playground/core/sources.py
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@

import pandas as pd

from .activity_parsers import read_activity


class TimeSeriesSource(abc.ABC):
@abc.abstractmethod
@@ -14,3 +16,9 @@ def iter_activities(self) -> Iterator[pd.DataFrame]:
class DirectoryTimeSeriesSource(TimeSeriesSource):
def iter_activities(self) -> Iterator[pd.DataFrame]:
activity_dir = pathlib.Path.cwd() / "Activities"
for path in activity_dir.rglob("*.*"):
df = read_activity(path)
# Some FIT files don't have any location data, they might be just weight lifting. We'll skip them.
if len(df) == 0:
continue
yield df
2 changes: 1 addition & 1 deletion geo_activity_playground/explorer/converters.py
Original file line number Diff line number Diff line change
@@ -3,8 +3,8 @@

import pandas as pd

from ..core.sources import TimeSeriesSource
from ..core.tiles import compute_tile
from geo_activity_playground.core.sources import TimeSeriesSource


@functools.cache
4 changes: 2 additions & 2 deletions geo_activity_playground/explorer/grid_file.py
Original file line number Diff line number Diff line change
@@ -6,9 +6,9 @@
import numpy as np
import scipy.ndimage

from ..core.sources import TimeSeriesSource
from ..core.tiles import get_tile_upper_left_lat_lon
from geo_activity_playground.core.sources import TimeSeriesSource
from geo_activity_playground.explorer.converters import get_tile_history
from .converters import get_tile_history


def get_border_tiles(ts_source: TimeSeriesSource) -> list[list[list[float]]]:
2 changes: 1 addition & 1 deletion geo_activity_playground/explorer/video.py
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
from PIL import ImageEnhance
from tqdm import tqdm

from geo_activity_playground.core.tiles import get_tile
from ..core.tiles import get_tile


def build_image(
5 changes: 1 addition & 4 deletions geo_activity_playground/heatmap.py
Original file line number Diff line number Diff line change
@@ -17,20 +17,17 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import itertools
import os
import pathlib

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import sklearn.cluster

from .core.directories import get_config
from .core.sources import TimeSeriesSource
from .core.tiles import compute_tile
from .core.tiles import get_tile
from .core.tiles import latlon_to_xy
from geo_activity_playground.core.sources import TimeSeriesSource

# globals
PLT_COLORMAP = "hot" # matplotlib color map
8 changes: 4 additions & 4 deletions geo_activity_playground/strava/api_access.py
Original file line number Diff line number Diff line change
@@ -13,10 +13,10 @@
from stravalib.model import Activity
from tqdm import tqdm

from geo_activity_playground.core.directories import get_config
from geo_activity_playground.core.directories import get_state
from geo_activity_playground.core.directories import set_state
from geo_activity_playground.core.sources import TimeSeriesSource
from ..core.directories import get_config
from ..core.directories import get_state
from ..core.directories import set_state
from ..core.sources import TimeSeriesSource


logger = logging.getLogger(__name__)
6 changes: 3 additions & 3 deletions geo_activity_playground/strava/importing.py
Original file line number Diff line number Diff line change
@@ -4,8 +4,8 @@

import pandas as pd

from geo_activity_playground.core.activity_parsers import read_activity
from geo_activity_playground.core.sources import TimeSeriesSource
from ..core.activity_parsers import read_activity
from ..core.sources import TimeSeriesSource


@functools.cache
@@ -22,7 +22,7 @@ def make_activity_cache_path(activity_path: pathlib.Path) -> pathlib.Path:
class StravaExportTimeSeriesSource(TimeSeriesSource):
def iter_activities(self) -> Iterator[pd.DataFrame]:
activity_paths = list(
(pathlib.Path.cwd() / "Strava Export" / "activities").glob("?????*.*")
(pathlib.Path("Strava Export") / "activities").glob("?????*.*")
)
activity_paths.sort()
for path in activity_paths:

0 comments on commit f1342f2

Please sign in to comment.