vkurup / python-tcxparser

Simple parser for Garmin TCX files
BSD 2-Clause "Simplified" License
87 stars 46 forks source link

Why differenth length of value arrays? #87

Open ferrigno opened 2 years ago

ferrigno commented 2 years ago

Hello. Thanks for this module !

I downloaded an activity done on an home trainer. I notices that the length of array of power values or cadence values or time values is different. Why ? How can I reconcile the arrays ?

Thanks

vkurup commented 2 years ago

Hi, I no longer actively use this, so I'm not certain. Perhaps someone else will be able to provide some guidance. If you can provide an example data file, it might be helpful to them.

mbartenschlag commented 3 months ago

I discovered a similar bug this evening when looking at an activity where the band of my Polar OH1+ arm-worn optical heart rate sensor flipped causing the sensor to face outward and not record data for half of the activity. I flipped it back around for the last 10 minutes of the activity.

The parsed TCX file yields len(tcx.time_values()) = 2985 and len(tcx.hr_values()) = 682.

What I ended up doing instead is iterating through the activity's Trackpoint nodes myself to build a dict of timestamp to heart rate values.

def read_file(source_file):
    tcx = TCXParser(source_file)
    print(f"{source_file}: timestamps = {len(tcx.time_values())}, hr_records = {len(tcx.hr_values())}.") # 2985 != 682
    data = [ ]
    namespace = "http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2"
    for node in tcx.root.xpath("//ns:Trackpoint", namespaces={"ns": namespace}):
        timestamp = int(dt.fromisoformat(str(node.Time)).strftime("%s"))
        hr = int(node.HeartRateBpm.Value) if hasattr(node, "HeartRateBpm") else None
        data.append([timestamp, hr])
    return data