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: diff --git a/src/stravavis/process_data.py b/src/stravavis/process_data.py index 42ab411..6e928fa 100644 --- a/src/stravavis/process_data.py +++ b/src/stravavis/process_data.py @@ -38,8 +38,11 @@ def process_gpx(gpxfile: str) -> pd.DataFrame | None: for activity_track in activity.tracks: for segment in activity_track.segments: - x0 = activity.tracks[0].segments[0].points[0].longitude - y0 = activity.tracks[0].segments[0].points[0].latitude + if not segment.points: + continue + + x0 = segment.points[0].longitude + y0 = segment.points[0].latitude d0 = 0 for point in segment.points: x = point.longitude 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 @@ + + + + + +