marcusvolz / strava_py

Create artistic visualisations with your exercise data (Python version)
MIT License
162 stars 19 forks source link

bug: dies if trkseg is empty #45

Open JeromeSchmied opened 6 days ago

JeromeSchmied commented 6 days ago

description

if the gpx file doesn't contain any coordinates: the trkseg is empty, stravavis panics and quits, without actually saying which file is problematic

although I do love this tool, it gave me quite a head-ache to figure out what the problem was

problem

take the following example, which is (as far as I can tell, according to xmllint) a valid gpx file:

<?xml version="1.0" encoding="utf-8"?>
<gpx version="1.1" xmlns="http://www.topografix.com/GPX/1/1" creator="https://github.com/georust/gpx">
  <trk>
    <trkseg />
  </trk>
</gpx>

log

when the execution gets to this file, it kindly produces the following output

$ stravavis strava_data/activities
...
multiprocessing.pool.RemoteTraceback:
"""
Traceback (most recent call last):
  File "/usr/lib/python3.12/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
                    ^^^^^^^^^^^^^^^^^^^
  File "/home/jero/code/python/strava_vis/.venv/lib/python3.12/site-packages/stravavis/process_data.py", line 17, in process_file
    return process_gpx(fpath)
           ^^^^^^^^^^^^^^^^^^
  File "/home/jero/code/python/strava_vis/.venv/lib/python3.12/site-packages/stravavis/process_data.py", line 41, in process_gpx
    x0 = activity.tracks[0].segments[0].points[0].longitude
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/jero/code/python/strava_vis/.venv/bin/stravavis", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/jero/code/python/strava_vis/.venv/lib/python3.12/site-packages/stravavis/cli.py", line 119, in main
    df = process_data(filenames)
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jero/code/python/strava_vis/.venv/lib/python3.12/site-packages/stravavis/process_data.py", line 138, in process_data
    processed = list(it)
                ^^^^^^^^
  File "/home/jero/code/python/strava_vis/.venv/lib/python3.12/site-packages/rich/progress.py", line 170, in track
    yield from progress.track(
  File "/home/jero/code/python/strava_vis/.venv/lib/python3.12/site-packages/rich/progress.py", line 1217, in track
    for value in sequence:
                 ^^^^^^^^
  File "/usr/lib/python3.12/multiprocessing/pool.py", line 873, in next
    raise value
IndexError: list index out of range
hugovk commented 1 day ago

Please see PR #48.

JeromeSchmied commented 19 hours ago

looks good, how could I test that branch? (I have literally no python knowledge)

hugovk commented 19 hours ago

Try this to install direct from the GitHub branch:

python3 -m pip install git+https://github.com/hugovk/strava_py.git@fix-empty-trkseg

JeromeSchmied commented 8 hours ago

not quite there yet, running with from that branch with same examplle file shows this output:

$stravavis test_data
Processing data...
Cache filename: /tmp/stravavis/cached_activities_b41c762bc35cf07ff790ea2a0bf714bb.pkl
Loaded cached activities
Plotting facets...
Traceback (most recent call last):
  File "/home/jero/code/python/strava_vis/.venv/bin/stravavis", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/jero/code/python/strava_vis/.venv/lib/python3.12/site-packages/stravavis/cli.py", line 128, in main
    plot_facets(df, output_file=outfile)
  File "/home/jero/code/python/strava_vis/.venv/lib/python3.12/site-packages/stravavis/plot_facets.py", line 20, in plot_facets
    p = sns.FacetGrid(
        ^^^^^^^^^^^^^^
  File "/home/jero/code/python/strava_vis/.venv/lib/python3.12/site-packages/seaborn/axisgrid.py", line 429, in __init__
    nrow = int(np.ceil(len(col_names) / col_wrap))
                       ~~~~~~~~~~~~~~~^~~~~~~~~~
ZeroDivisionError: division by zero
hugovk commented 8 hours ago

Thanks for testing, I've pushed an update, can you try again?

❯ stravavis tests/gpx/empty-trkseg.gpx
Processing data...
Cache filename: /var/folders/p6/lf2s1s5d4kb335g2n1td8z8c0000gn/T/stravavis/cached_activities_8f342e3343e3fbd635f5626cbd59b2a3.pkl
Cache not found
Processing ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00
No data to plot

❯ stravavis tests/gpx/empty-trkseg.gpx
Processing data...
Cache filename: /var/folders/p6/lf2s1s5d4kb335g2n1td8z8c0000gn/T/stravavis/cached_activities_8f342e3343e3fbd635f5626cbd59b2a3.pkl
Loaded cached activities
No data to plot