Skip to content

Commit

Permalink
Add option to choose which visualisations to generate
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Oct 20, 2024
1 parent b6810a9 commit 3040870
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 64 deletions.
38 changes: 34 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,35 @@ Then run from the terminal:
stravavis --help
```

## How to use

If your activity data is in a folder called `activities`, run the following command:

```sh
stravavis activities
```

By default, this will create output images prefixed `strava-`.

If you have an `activities.csv` file:

```sh
stravavis activities --activities_path activities.csv
```

To only map activities contained within a
[bounding box](https://boundingbox.klokantech.com/):

```sh
stravavis activities --bbox 24.782802,59.922486,25.254511,60.29785`
```

To only plot certain visualisations:

```sh
stravavis activities --vis map facets landscape
```

## Examples

### Facets
Expand Down Expand Up @@ -69,9 +98,7 @@ Requires "activities.csv" from the bulk Strava export.

![map](https://raw.githubusercontent.com/marcusvolz/strava_py/main/plots/dumbbell001.png "Dumbbell plot")

## How to use

### Bulk export from Strava
## Bulk export from Strava

The process for downloading data is described on the Strava website here:
[https://support.strava.com/hc/en-us/articles/216918437-Exporting-your-Data-and-Bulk-Export#Bulk],
Expand All @@ -92,7 +119,10 @@ but in essence, do the following:
7. Click the link in email to download zipped folder containing activities
8. Unzip files
### Process the data
## Programmatic use
The package can also be used programmatically. The following code snippets demonstrate
how to use the package to create the visualisations.
The main function for importing and processing activity files expects a path to a
directory of unzipped GPX and / or FIT files. If required, the
Expand Down
153 changes: 93 additions & 60 deletions src/stravavis/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
import os.path
import sys

VISUALISATIONS = {
"all",
"calendar",
"dumbbell",
"elevations",
"facets",
"landscape",
"map",
}


def main():
parser = argparse.ArgumentParser(
Expand All @@ -13,6 +23,13 @@ def main():
parser.add_argument(
"path", help="Input path specification to folder with GPX and / or FIT files"
)
parser.add_argument(
"--vis",
default="all",
choices=VISUALISATIONS,
nargs="+",
help="Which visualisations to generate",
)
parser.add_argument(
"-o", "--output_prefix", default="strava", help="Prefix for output PNG files"
)
Expand Down Expand Up @@ -85,6 +102,9 @@ def main():
)
args = parser.parse_args()

if "all" in args.vis:
args.vis = VISUALISATIONS

# Expand "~" or "~user"
args.path = os.path.expanduser(args.path)

Expand All @@ -106,13 +126,6 @@ def main():

# Normally imports go at the top, but scientific libraries can be slow to import
# so let's validate arguments first
from .plot_calendar import plot_calendar
from .plot_dumbbell import plot_dumbbell
from .plot_elevations import plot_elevations
from .plot_facets import plot_facets
from .plot_landscape import plot_landscape
from .plot_map import plot_map
from .process_activities import process_activities
from .process_data import process_data

print("Processing data...")
Expand All @@ -122,69 +135,89 @@ def main():

activities = None
if args.activities_path:
from .process_activities import process_activities

print("Processing activities...")
activities = process_activities(args.activities_path)

print("Plotting facets...")
outfile = f"{args.output_prefix}-facets.png"
plot_facets(df, output_file=outfile)
print(f"Saved to {outfile}")

print("Plotting map...")
outfile = f"{args.output_prefix}-map.png"
plot_map(
df,
args.lon_min,
args.lon_max,
args.lat_min,
args.lat_max,
args.alpha,
args.linewidth,
outfile,
)
print(f"Saved to {outfile}")

print("Plotting elevations...")
outfile = f"{args.output_prefix}-elevations.png"
plot_elevations(df, output_file=outfile)
print(f"Saved to {outfile}")

print("Plotting landscape...")
outfile = f"{args.output_prefix}-landscape.png"
plot_landscape(df, output_file=outfile)
print(f"Saved to {outfile}")
if "facets" in args.vis:
from .plot_facets import plot_facets

if activities is not None:
print("Plotting calendar...")
outfile = f"{args.output_prefix}-calendar.png"
fig_height = args.fig_height or 15
fig_width = args.fig_width or 9
plot_calendar(
activities,
args.year_min,
args.year_max,
args.max_dist,
fig_height,
fig_width,
outfile,
)
print("Plotting facets...")
outfile = f"{args.output_prefix}-facets.png"
plot_facets(df, output_file=outfile)
print(f"Saved to {outfile}")

print("Plotting dumbbell...")
outfile = f"{args.output_prefix}-dumbbell.png"
fig_height = args.fig_height or 34
fig_width = args.fig_width or 34
plot_dumbbell(
activities,
args.year_min,
args.year_max,
args.local_timezone,
fig_height,
fig_width,
if "map" in args.vis:
from .plot_map import plot_map

print("Plotting map...")
outfile = f"{args.output_prefix}-map.png"
plot_map(
df,
args.lon_min,
args.lon_max,
args.lat_min,
args.lat_max,
args.alpha,
args.linewidth,
outfile,
)
print(f"Saved to {outfile}")

if "elevations" in args.vis:
from .plot_elevations import plot_elevations

print("Plotting elevations...")
outfile = f"{args.output_prefix}-elevations.png"
plot_elevations(df, output_file=outfile)
print(f"Saved to {outfile}")

if "landscape" in args.vis:
from .plot_landscape import plot_landscape

print("Plotting landscape...")
outfile = f"{args.output_prefix}-landscape.png"
plot_landscape(df, output_file=outfile)
print(f"Saved to {outfile}")

if activities is not None:
if "calendar" in args.vis:
from .plot_calendar import plot_calendar

print("Plotting calendar...")
outfile = f"{args.output_prefix}-calendar.png"
fig_height = args.fig_height or 15
fig_width = args.fig_width or 9
plot_calendar(
activities,
args.year_min,
args.year_max,
args.max_dist,
fig_height,
fig_width,
outfile,
)
print(f"Saved to {outfile}")

if "dumbbell" in args.vis:
from .plot_dumbbell import plot_dumbbell

print("Plotting dumbbell...")
outfile = f"{args.output_prefix}-dumbbell.png"
fig_height = args.fig_height or 34
fig_width = args.fig_width or 34
plot_dumbbell(
activities,
args.year_min,
args.year_max,
args.local_timezone,
fig_height,
fig_width,
outfile,
)
print(f"Saved to {outfile}")


if __name__ == "__main__":
main()

0 comments on commit 3040870

Please sign in to comment.