コード例 #1
0
ファイル: parser.py プロジェクト: akolar/training
    def serialize(self, o, **kwargs):
        if not isinstance(o, Track):
            raise TypeError('Object should be of type {}, is {}'.format(type(Track), type(o)))

        a = Activity()
        a.date = o.created_at

        a.elapsed = o.elapsed_time()
        a.moving = o.moving_time()
        a.total_distance = o.total_distance()
        a.elevation_gain = o.elevation_gain()

        a.speed_avg = o.average_speed()
        a.speed_max = o.max_speed()
        a.hr_avg = o.average_heart_rate()
        a.hr_max = o.max_heart_rate()

        a.zones_elevation = o.elevation_zones()
        a.zones_speed = o.speed_zones()
        a.zones_hr = o.heart_rate_zones()
        a.zones_grade = o.grade_zones()

        a.track = LineString(o.track())
        a.time = o.time_entries()
        a.distance = o.distance_entries()

        hr = o.heart_rate_entries()
        a.heart_rate = [e if e else -1 for e in hr] if hr else None

        cad = o.cadence_entries()
        a.cadence = [e if e else -1 for e in cad] if cad else None

        temp = o.temperature_entries()
        a.temperature = [e if e else -1 for e in temp] if temp else None

        # User, activity type, objectives, etc.
        for key, value in kwargs.iteritems():
            if key not in ['user', 'sport', 'description', 'comments', 'equipment', 'primary_objective',
                           'secondary_objective', 'rating']:
                continue

            setattr(a, key, value)

        return a