def UploadActivity(self, serviceRecord, activity):
        logger.debug("Motivato UploadActivity")
        session = self._get_session(record=serviceRecord)

        dic = dict(
            training_at=activity.StartTime.strftime("%Y-%m-%d"),
            distance=activity.Stats.Distance.asUnits(ActivityStatisticUnit.Kilometers).Value,
            duration="",
            user_comment=activity.Notes,
            updated_at=datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
            created_at=activity.StartTime.strftime("%Y-%m-%d %H:%M:%S"),
            discipline_id=self._activityMappings[activity.Type],
            source_id=8,
            metas=dict(
                distance=activity.Stats.Distance.asUnits(ActivityStatisticUnit.Kilometers).Value,
                duration="",

                time_start=activity.StartTime.strftime("%H:%M:%S")
            ),
            track={}
        )

        if activity.Stats.TimerTime.Value is not None:
            secs = activity.Stats.TimerTime.asUnits(ActivityStatisticUnit.Seconds).Value
        elif activity.Stats.MovingTime.Value is not None:
            secs = activity.Stats.MovingTime.asUnits(ActivityStatisticUnit.Seconds).Value
        else:
            secs = (activity.EndTime - activity.StartTime).total_seconds()


        dic["metas"]["duration"] = str(timedelta(seconds=secs))
        dic["duration"] = str(timedelta(seconds=secs))

        pace=str(timedelta(seconds=secs/activity.Stats.Distance.Value))
        meta_hr_avg=activity.Stats.HR.Average
        meta_hr_max=activity.Stats.HR.Max

        if pace:
            dic["metas"]["pace"] = pace

        if meta_hr_avg:
            dic["metas"]["meta_hr_avg"] = meta_hr_avg

        if meta_hr_max:
            dic["metas"]["meta_hr_max"] = meta_hr_max

        if len(activity.Laps) > 0:
            dic["track"] = dict(
                name=activity.Name,
                mtime=secs,
                points=[]
            )

            for tk in activity.Laps:
                for wpt in tk.Waypoints:
                    pt = dict(
                        lat=wpt.Location.Latitude,
                        lon=wpt.Location.Longitude,
                        ele=wpt.Location.Altitude,
                        bpm=wpt.HR,
                        moment=wpt.Timestamp.strftime('%Y-%m-%d %H:%M:%S')
                    )

                    if wpt.Speed and wpt.Speed != None and wpt.Speed != 0:
                        pt["pace"]=(1000.0/wpt.Speed)

                    dic["track"]["points"].append(pt)

        toSend = json.dumps(dic)

        try:
            res = session.post(self._urlRoot + "/api/workout", data=toSend)
        except APIWarning as e:
            raise APIException(str(e))

        if res.status_code != 201:
            raise APIException("Activity didn't upload: %s, %s" % (res.status_code, res.text))

        try:
            retJson = res.json()
        except ValueError:
            raise APIException("Activity upload parse error for %s, %s" % (res.status_code, res.text))

        return retJson["id"]
dataset/ETHPy150Open cpfair/tapiriik/tapiriik/services/Motivato/motivato.py/MotivatoService.UploadActivity/original