"Simple parser for Garmin TCX files."

from lxml import objectify

__version__ = '0.3.0'


class TcxParser:

    def __init__(self, tcx_file):
        tree = objectify.parse(tcx_file)
        self.root = tree.getroot()
        self.activity = self.root.Activities.Activity

    @property
    def latitude(self):
        return self.activity.Lap.Track.Trackpoint.Position.LatitudeDegrees

    @property
    def longitude(self):
        return self.activity.Lap.Track.Trackpoint.Position.LongitudeDegrees

    @property
    def activity_type(self):
        return self.activity.attrib['Sport'].lower()

    @property
    def completed_at(self):
        return self.activity.Lap[-1].Track.Trackpoint[-1].Time

    @property
    def distance(self):
        return self.activity.Lap[-1].Track.Trackpoint[-2].DistanceMeters

    @property
    def distance_units(self):
        return 'meters'

    @property
    def duration(self):
        """Returns duration of workout in seconds."""
        return sum(lap.TotalTimeSeconds for lap in self.activity.Lap)

    @property
    def calories(self):
        return sum(lap.Calories for lap in self.activity.Lap)

"Simple parser for Garmin TCX files."

from lxml import objectify

__version__ = '0.4.0'


class TcxParser:

    def __init__(self, tcx_file):
        tree = objectify.parse(tcx_file)
        self.root = tree.getroot()
        self.activity = self.root.Activities.Activity

    @property
    def latitude(self):
        return self.activity.Lap.Track.Trackpoint.Position.LatitudeDegrees.pyval

    @property
    def longitude(self):
        return self.activity.Lap.Track.Trackpoint.Position.LongitudeDegrees.pyval

    @property
    def activity_type(self):
        return self.activity.attrib['Sport'].lower()

    @property
    def completed_at(self):
        return self.activity.Lap[-1].Track.Trackpoint[-1].Time.pyval

    @property
    def distance(self):
        return self.activity.Lap[-1].Track.Trackpoint[-2].DistanceMeters.pyval

    @property
    def distance_units(self):
        return 'meters'

    @property
    def duration(self):
        """Returns duration of workout in seconds."""
        return sum(lap.TotalTimeSeconds for lap in self.activity.Lap)

    @property
    def calories(self):
        return sum(lap.Calories for lap in self.activity.Lap)

Make sure to return python values, not lxml objects
Make sure to return python values, not lxml objects

Bump version to 0.4.0

  "Simple parser for Garmin TCX files."
  
  from lxml import objectify
  
- __version__ = '0.3.0'
+ __version__ = '0.4.0'
  
  
  class TcxParser:
  
      def __init__(self, tcx_file):
          tree = objectify.parse(tcx_file)
          self.root = tree.getroot()
          self.activity = self.root.Activities.Activity
  
      @property
      def latitude(self):
-         return self.activity.Lap.Track.Trackpoint.Position.LatitudeDegrees
+         return self.activity.Lap.Track.Trackpoint.Position.LatitudeDegrees.pyval
  
      @property
      def longitude(self):
-         return self.activity.Lap.Track.Trackpoint.Position.LongitudeDegrees
+         return self.activity.Lap.Track.Trackpoint.Position.LongitudeDegrees.pyval
  
      @property
      def activity_type(self):
          return self.activity.attrib['Sport'].lower()
  
      @property
      def completed_at(self):
-         return self.activity.Lap[-1].Track.Trackpoint[-1].Time
+         return self.activity.Lap[-1].Track.Trackpoint[-1].Time.pyval
  
      @property
      def distance(self):
-         return self.activity.Lap[-1].Track.Trackpoint[-2].DistanceMeters
+         return self.activity.Lap[-1].Track.Trackpoint[-2].DistanceMeters.pyval
  
      @property
      def distance_units(self):
          return 'meters'
  
      @property
      def duration(self):
          """Returns duration of workout in seconds."""
          return sum(lap.TotalTimeSeconds for lap in self.activity.Lap)
  
      @property
      def calories(self):
          return sum(lap.Calories for lap in self.activity.Lap)
  
Make sure to return python values, not lxml objects
## Code Before:
"Simple parser for Garmin TCX files."

from lxml import objectify

__version__ = '0.3.0'


class TcxParser:

    def __init__(self, tcx_file):
        tree = objectify.parse(tcx_file)
        self.root = tree.getroot()
        self.activity = self.root.Activities.Activity

    @property
    def latitude(self):
        return self.activity.Lap.Track.Trackpoint.Position.LatitudeDegrees

    @property
    def longitude(self):
        return self.activity.Lap.Track.Trackpoint.Position.LongitudeDegrees

    @property
    def activity_type(self):
        return self.activity.attrib['Sport'].lower()

    @property
    def completed_at(self):
        return self.activity.Lap[-1].Track.Trackpoint[-1].Time

    @property
    def distance(self):
        return self.activity.Lap[-1].Track.Trackpoint[-2].DistanceMeters

    @property
    def distance_units(self):
        return 'meters'

    @property
    def duration(self):
        """Returns duration of workout in seconds."""
        return sum(lap.TotalTimeSeconds for lap in self.activity.Lap)

    @property
    def calories(self):
        return sum(lap.Calories for lap in self.activity.Lap)

## Instruction:
Make sure to return python values, not lxml objects
## Code After:
"Simple parser for Garmin TCX files."

from lxml import objectify

__version__ = '0.4.0'


class TcxParser:

    def __init__(self, tcx_file):
        tree = objectify.parse(tcx_file)
        self.root = tree.getroot()
        self.activity = self.root.Activities.Activity

    @property
    def latitude(self):
        return self.activity.Lap.Track.Trackpoint.Position.LatitudeDegrees.pyval

    @property
    def longitude(self):
        return self.activity.Lap.Track.Trackpoint.Position.LongitudeDegrees.pyval

    @property
    def activity_type(self):
        return self.activity.attrib['Sport'].lower()

    @property
    def completed_at(self):
        return self.activity.Lap[-1].Track.Trackpoint[-1].Time.pyval

    @property
    def distance(self):
        return self.activity.Lap[-1].Track.Trackpoint[-2].DistanceMeters.pyval

    @property
    def distance_units(self):
        return 'meters'

    @property
    def duration(self):
        """Returns duration of workout in seconds."""
        return sum(lap.TotalTimeSeconds for lap in self.activity.Lap)

    @property
    def calories(self):
        return sum(lap.Calories for lap in self.activity.Lap)
