Skip to content

Commit

Permalink
Merge pull request #51 from ToonElewaut/main
Browse files Browse the repository at this point in the history
Added methods for converting trackpoints to a list of dictionaries
  • Loading branch information
alenrajsp authored Apr 2, 2024
2 parents 1fbfa13 + 999de2e commit fc0e74a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tcxreader/tcx_exercise.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,17 @@ def __init__(self, trackpoints: List[TCXTrackPoint] = None, activity_type: str =
self.author: TCXAuthor = author
self.tpx_ext_stats: dict = tpx_ext_stats
self.lx_ext: dict = lx_ext

def trackpoints_to_dict(self) -> list:
"""
Convert trackpoints to a list of dictionaries.
Returns:
list: A list of dictionaries containing trackpoint data.
"""
trackpoint_dict = []

for tp in self.trackpoints:
trackpoint_dict.append(tp.to_dict())


return trackpoint_dict
20 changes: 20 additions & 0 deletions tcxreader/tcx_track_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,25 @@ def __str__(self) -> str:
return f'Time:{time}\nLatitude:\t{latitude}\nLongitude:\t{longitude}\nElevation:\t{elevation}\nDistance:\t{distance}\n' \
f'Heartrate:\t{hr_value}\nCadence:\t{cadence} \nTPX Extensions: {tpx_str}\n#############################'

def to_dict(self) -> dict:
"""
Convert trackpoint to a dictionary.
Returns:
dict: A dictionary containing trackpoint data.
"""
tp_dict = {
'time': self.time,
'longitude': self.longitude,
'latitude': self.latitude,
'distance': self.distance,
'elevation': self.elevation,
'hr_value': self.hr_value,
'cadence': self.cadence,
}
for key in self.tpx_ext:
tp_dict[key] = self.tpx_ext[key]

return tp_dict

def __unicode__(self):
return self.__str__()

0 comments on commit fc0e74a

Please sign in to comment.