triskadecaepyon / pyworkout-toolkit

Python tools to process workout data and telemetry for metrics and machine learning
BSD 3-Clause "New" or "Revised" License
18 stars 3 forks source link

Parser fail to parse a activity tcx file, in case there is only one 'Lap' element available #9

Closed paulogonc closed 5 years ago

paulogonc commented 5 years ago

I tried to read an activity file from my Garmin edge 1000 and it throws an exception. Enclosed there is the dataset from the repository where I could reproduce the error. I deleted the Lap element #2 and #3 from the file and tried to parse it and it raised in the same exception. The error occurs in the tcxtools.py file in the _traverse_laps method during the iteration of the Lap object activities. Maybe you've have an idea why the iterator doesn't seems to work for files with only one Lap element.

test_dataset_1_reduced.tcx.log

triskadecaepyon commented 5 years ago

@Maschinenbauer Actually it looks like Garmin has yet again changed the schema location (which are referenced in lines 13 and 14 of https://github.com/triskadecaepyon/pyworkout-toolkit/blob/master/pyworkout/parsers/tcxtools.py

I'll need to update them so it can read the schema correctly again.

triskadecaepyon commented 5 years ago

@Maschinenbauer it seems there was another element at play, namely that the original LXML code assumed the first element of getnext() would get the first element--however LXML has deprecated the code in the latest few versions and it now can use a true iterator to go through the elements, removing the need for using getnext() and the error we've seen.

If you build from master the fix should be in place. I'll have to update the conda-forge feedstock and also upload to pip before later this week before they are available for download it via conda or pip.

Let me know if this fixes your problem.

paulogonc commented 5 years ago

@triskadecaepyon I can confirm that your fix is also working with my original tcx file! :-) Thanks.

triskadecaepyon commented 5 years ago

Closing the issue after confirmed fixes and tests passing.