polar_training2tcx fixes and improvements - #39
Conversation
| } | ||
| } | ||
| end | ||
| }.xmlns = 'http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2' |
There was a problem hiding this comment.
Looks like Polar Flow excludes the XML namespace of the first Trackpoint of each Track only. Strange!
| elapsed += recording_interval | ||
| elapsed_with_pauses += recording_interval | ||
| end | ||
| }.xmlns = 'http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2' |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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?
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_ias 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
xmlnsattribute 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 containxmlnsfor 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.