Skip to content
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

polar_training2tcx fixes and improvements #39

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Sterearch
Copy link
Contributor

@Sterearch Sterearch commented Dec 30, 2022

I used the tools to get training data from Polar M430 and import to Strava (thanks a lot for this project BTW!). For the result to meet my needs, I had to do the changes as in this PR.

Commit 2726621 fixes the loop break condition (line 119) to check route_i as the route samples counter. Without the change, it could stop processing the data prematurely. Also, first_sample_with_gps = false if first_sample_with_gps (line 176) is removed as this variable is not used anywhere else.

Commit 881f3d1 removes the xmlns attribute from <Track> and <Trackpoint> (lines 177, 183 in the original code). It was the key to make Strava import the tracks successfully. I also checked that TCX files created with the PolarFlow app do not contain xmlns for these elements either.

Commit e979012 uncomments and slightly improves the check for route samples to match the currently processed time stamp (line 139). Without this change, all route samples are placed at the beginning of the training, ignoring the actual time of GPS [in]availability. There seem to be some differences with how PolarFlow handles it, but I feel matching the time stamps gives more accurate results.

@@ -173,13 +173,13 @@ def output_tcx(parsed)
}
}
end
}.xmlns = 'http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like Polar Flow excludes the XML namespace of the first Trackpoint of each Track only. Strange!


i += 1
elapsed += recording_interval
elapsed_with_pauses += recording_interval
end
}.xmlns = 'http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, Polar Flow does include the namespace for all , except the first one. Not sure why, maybe to please Strava too?
Those namespaces may not be needed for usual use cases, we can try to remove them and see if someone needs them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it depends on the version and/or the platform of the PolarFlow app. I used their Windows applicaiton to load the trainings, and then downloaded the results via a browser.

@@ -136,7 +136,7 @@ def output_tcx(parsed)

xml.Trackpoint {
xml.Time (start + elapsed_with_pauses).strftime("%Y-%m-%dT%H:%M:%S.%3NZ")
if route_i && route_samples.duration[route_i] #&& (route_samples.duration[route_i] / 1000 <= elapsed)
if route_i && route_samples.duration[route_i] && (route_samples.duration[route_i].to_f / 1000 <= elapsed)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I compare with a Polar Flow TCX export, it looks like that they actually reuse route_samples.latitude|longitude as long as route_samples.duration[route_i].to_f / 1000 <= elapsed.
I just pushed a different fix that gives me the exact same trackpoints as Polar Flow on my latest ride. Please give it a try and check that it works for you too!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it with the same tracks I used before - but no, it does not work as I would need, and neither it matches the PolarFlow TCX files.

Sometimes I start running without waiting for GPS to be found, and so quite a lot of initial trackpoints may have data for distance, cadence etc., but do not have position data. With my patch, it works well, the positions appear late in the track. With your fix, all the positions are still "shifted" to the beginning (which is strange, as the code suggests that instead the first position should be reused again and again) and disappear at the end of the track.

Copy link
Contributor Author

@Sterearch Sterearch Mar 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cmaion, I have figured out why it did not work as I expected; looks like the condition for route_i increment contained an unfortunate typo. I have updated this patch, could you please re-check?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants