activereader.tcx module

.tcx file reader architecture.

Originated in heartandsole back in the day.

See also

Garmin’s TCX schema

XML file describing the schema for TCX files.

Garmin’s ActivityExtension schema

XML file describing Garmin’s extensions to the TCX schema.

activereader.tcx.Tcx(lxml_elem)

Represents an entire .tcx file object.

activereader.tcx.Activity(lxml_elem)

TCX files representing a run should only contain one Activity.

activereader.tcx.Lap(lxml_elem)

Represents one bout from {start/lap} -> {lap/stop}.

activereader.tcx.Track(lxml_elem)

In a running TCX file, there is typically one Track per Lap.

activereader.tcx.Trackpoint(lxml_elem)

Represents a single data sample corresponding to a point in time.

class activereader.tcx.Tcx(lxml_elem)

Bases: ActivityElement

Represents an entire .tcx file object.

TAG = 'TrainingCenterDatabase'

XML tag name of the element.

If an instance of the class is initialized from a lxml.etree._Element with any other tag name, a TypeError will be raised.

classmethod from_file(file_obj)

Initialize a Tcx element from a file-like object.

Parameters

file_obj (str, bytes, io.StringIO, io.BytesIO) – File-like object. If str, either filename or a string representation of XML object. If str or StringIO, the encoding should not be declared within the string.

Returns

An instance initialized with the _Element that was read in.

Return type

Tcx

property activities

All element descendents with tag name “Activity”.

Type

list of Activity

property laps

All element descendents with tag name “Lap”.

Type

list of Lap

property tracks

All element descendents with tag name “Track”.

Type

list of Track

property trackpoints

All element descendents with tag name “Trackpoint”.

Type

list of Trackpoint

class activereader.tcx.Activity(lxml_elem)

Bases: ActivityElement

TCX files representing a run should only contain one Activity.

Contains one or more Lap elements.

TAG = 'Activity'

XML tag name of the element.

If an instance of the class is initialized from a lxml.etree._Element with any other tag name, a TypeError will be raised.

property start_time

Timestamp for activity start time.

See also

Timestamps

Type

datetime.datetime

property sport

Activity sport.

Restricted to “Running”, “Biking”, or “Other” according to Garmin’s TCX file schema.

Type

str

property device

Device brand name.

Type

str

property device_id

Device ID - specific to the individual device.

Type

int

property laps

All element descendents with tag name “Lap”.

Type

list of Lap

property tracks

All element descendents with tag name “Track”.

Type

list of Track

property trackpoints

All element descendents with tag name “Trackpoint”.

Type

list of Trackpoint

class activereader.tcx.Lap(lxml_elem)

Bases: ActivityElement

Represents one bout from {start/lap} -> {lap/stop}.

There is at least one lap per activity file, created by the start button press and ended by the stop button press. Hitting the lap button begins a new lap. Hitting the pause button stops data recording, but the same lap resumes after the pause.

Made up of 1 or more Track in the XML structure.

TAG = 'Lap'

XML tag name of the element.

If an instance of the class is initialized from a lxml.etree._Element with any other tag name, a TypeError will be raised.

property start_time

Timestamp of lap start.

See also

Timestamps

Type

datetime.datetime

property total_time_s

Total lap time, in seconds, as reported by the device.

This is timer time, not elapsed time; it does not include any time when the device is paused.

Type

float

property distance_m

Total lap distance, in meters, as reported by the device.

See also

Distance

Type

float

property max_speed_ms

The maximum speed achieved during the lap as reported by the device, in meters per second.

Type

float

property avg_speed_ms

The average speed during the lap as reported by the device, in meters per second.

Type

float

property hr_avg

average heart rate during the lap as reported by the device.

Type

float

property hr_max

maximum heart rate during the lap as reported by the device.

Type

float

property cadence_avg

average cadence during the lap as reported by the device, in RPM.

See also

Cadence

Type

float

property cadence_max

maximum cadence during the lap as reported by the device, in RPM.

See also

Cadence

Type

float

property calories

Calories burned during the lap as approximated by the device.

Type

float

property tracks

All element descendents with tag name “Track”.

Type

list of Track

property trackpoints

All element descendents with tag name “Trackpoint”.

Type

list of Trackpoint

class activereader.tcx.Track(lxml_elem)

Bases: ActivityElement

In a running TCX file, there is typically one Track per Lap.

As far as I can tell, in a running file, Tracks and Laps are one and the same; when a Lap starts or ends, so does its contained Track.

Made up of 1 or more Trackpoint in xml file.

TAG = 'Track'

XML tag name of the element.

If an instance of the class is initialized from a lxml.etree._Element with any other tag name, a TypeError will be raised.

property trackpoints

All element descendents with tag name “Trackpoint”.

Type

list of Trackpoint

class activereader.tcx.Trackpoint(lxml_elem)

Bases: ActivityElement

Represents a single data sample corresponding to a point in time.

The most granular of data contained in the file.

TAG = 'Trackpoint'

XML tag name of the element.

If an instance of the class is initialized from a lxml.etree._Element with any other tag name, a TypeError will be raised.

property time

Timestamp when trackpoint was recorded.

See also

Timestamps

Type

datetime.datetime

property lat

Latitude in degrees N (-90 to 90).

Type

float

property lon

Longitude in degrees E (-180 to 180).

Type

float

property altitude_m

Elevation of ground surface in meters above sea level.

Type

float

property distance_m

Cumulative distance from the start of the activity, in meters.

See also

Distance

Type

float

property hr

Heart rate.

Type

int

property speed_ms

Speed in meters per second.

Type

float

property cadence_rpm

Cadence in RPM.

See also

Cadence

Type

int