python-tcxparser icon indicating copy to clipboard operation
python-tcxparser copied to clipboard

Why differenth length of value arrays?

Open ferrigno opened this issue 3 years ago • 2 comments

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

ferrigno avatar Feb 17 '22 11:02 ferrigno

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.

vkurup avatar Feb 20 '22 22:02 vkurup

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

mbartenschlag avatar Aug 09 '24 00:08 mbartenschlag