From b6cf1425457089bd20d8a3eb4ad8f7766255a038 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Mon, 30 Sep 2024 19:20:32 +0300 Subject: [PATCH 1/4] Add failing test file --- tests/gpx/empty-trkseg.gpx | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 tests/gpx/empty-trkseg.gpx diff --git a/tests/gpx/empty-trkseg.gpx b/tests/gpx/empty-trkseg.gpx new file mode 100644 index 0000000..48bf947 --- /dev/null +++ b/tests/gpx/empty-trkseg.gpx @@ -0,0 +1,6 @@ + + + + + + From b9982a49b01172e2227bdcde203124ad88bcf51b Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Mon, 30 Sep 2024 19:22:08 +0300 Subject: [PATCH 2/4] Skip segments with empty trkseg --- src/stravavis/process_data.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/stravavis/process_data.py b/src/stravavis/process_data.py index 42ab411..996b371 100644 --- a/src/stravavis/process_data.py +++ b/src/stravavis/process_data.py @@ -38,6 +38,9 @@ def process_gpx(gpxfile: str) -> pd.DataFrame | None: for activity_track in activity.tracks: for segment in activity_track.segments: + if not activity.tracks[0].segments[0].points: + continue + x0 = activity.tracks[0].segments[0].points[0].longitude y0 = activity.tracks[0].segments[0].points[0].latitude d0 = 0 From e32bdebb2770605525feaa5c79fbecf581fa3143 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Tue, 1 Oct 2024 15:02:23 +0300 Subject: [PATCH 3/4] Start at first point of each segment --- src/stravavis/process_data.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/stravavis/process_data.py b/src/stravavis/process_data.py index 996b371..6e928fa 100644 --- a/src/stravavis/process_data.py +++ b/src/stravavis/process_data.py @@ -38,11 +38,11 @@ def process_gpx(gpxfile: str) -> pd.DataFrame | None: for activity_track in activity.tracks: for segment in activity_track.segments: - if not activity.tracks[0].segments[0].points: + if not segment.points: continue - x0 = activity.tracks[0].segments[0].points[0].longitude - y0 = activity.tracks[0].segments[0].points[0].latitude + x0 = segment.points[0].longitude + y0 = segment.points[0].latitude d0 = 0 for point in segment.points: x = point.longitude From 059ac475362904d33d4c7fa890c21485d53d77db Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Tue, 1 Oct 2024 22:09:01 +0300 Subject: [PATCH 4/4] Exit if there's no data to plot --- src/stravavis/cli.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/stravavis/cli.py b/src/stravavis/cli.py index a964c88..76f8139 100644 --- a/src/stravavis/cli.py +++ b/src/stravavis/cli.py @@ -117,6 +117,8 @@ def main(): print("Processing data...") df = process_data(filenames) + if df.empty: + sys.exit("No data to plot") activities = None if args.activities_path: