New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: GPX output for fitdump #108
Conversation
@emirpnet Thanks for this! I made some changes to it to allow for generating the GPX output without having to load the whole input file into memory or process it twice. You can see them at https://github.com/dtcooper/python-fitparse/tree/feature/gpx . Do you see any issues with it or things you'd like changed? |
@pR0Ps I'd be happy for the feature to be merged. Personally I use it a lot. Just some questions, as I don't understand the control flow here (from line 108): # file creation time (if a file_id record exists)
first_record = []
for message in records:
if message.name == "file_id":
for field_data in message:
if field_data.name == "time_created" and type(field_data.value) == datetime.datetime:
yield ' <time>{}</time>\n'.format(field_data.value.strftime(GPX_TIME_FMT))
break
else:
# No time found in the fields, check next record
continue
break
elif message.name == "record":
first_record.append(message)
break First of all I'm not sure where the But more importantly I'm not sure I understand the break statements at the end of the if and elif block correctly. So you are looking for the first occurance of either a "file_id" message or "record" message. (Does the "file_id" always come before the first "record" in a FIT file? I have really no knowledge about the FIT file specification.) And in line 136: for message in itertools.chain(first_record, records): the code goes through the first_record and all the other records, right? Doesn't that double the first_record in the output, if there is no "file_id"? Sorry for all the questions, I'd really like to learn from the code. |
You are correct that the loop is looking for the first In Python, Since The later Hopefully that answered all your questions. I agree that the control flow is a bit weird. I'm not super happy with it but I couldn't think of a cleaner way to do it in a single pass without resorting to something like making the iterator peekable which seemed like overkill. I'm open to suggestions though. |
@pR0Ps Thank you for clearing it up for me! I didn't know about the else statement for loops in Python. (Should have thought about |
Currently only outputs time, position, elevation, and speed.
Merged in 0f4e23e |
Basic GPX output for fitdump (at this point without the Garmin-extension of the GPX specs, so all non-GPS data like heartrate, cadence, etc. is discarded)