当前位置: 首页>>代码示例>>Python>>正文


Python Waypoint.Speed方法代码示例

本文整理汇总了Python中tapiriik.services.interchange.Waypoint.Speed方法的典型用法代码示例。如果您正苦于以下问题:Python Waypoint.Speed方法的具体用法?Python Waypoint.Speed怎么用?Python Waypoint.Speed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tapiriik.services.interchange.Waypoint的用法示例。


在下文中一共展示了Waypoint.Speed方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _addWaypoint

# 需要导入模块: from tapiriik.services.interchange import Waypoint [as 别名]
# 或者: from tapiriik.services.interchange.Waypoint import Speed [as 别名]
 def _addWaypoint(timestamp, path=None, heart_rate=None, power=None, distance=None, speed=None, cadence=None):
     waypoint = Waypoint(activity.StartTime + timedelta(seconds=timestamp))
     if path:
         if path["latitude"] != 0 and path["longitude"] != 0:
             waypoint.Location = Location(path["latitude"], path["longitude"], path["altitude"] if "altitude" in path and float(path["altitude"]) != 0 else None)  # if you're running near sea level, well...
         waypoint.Type = WaypointType.Regular
     waypoint.HR = heart_rate
     waypoint.Distance = distance
     waypoint.Speed = speed
     waypoint.Cadence = cadence
     waypoint.Power = power
     lap.Waypoints.append(waypoint)
开发者ID:OkanEsen,项目名称:tapiriik,代码行数:14,代码来源:pulsstory.py

示例2: stream_waypoint

# 需要导入模块: from tapiriik.services.interchange import Waypoint [as 别名]
# 或者: from tapiriik.services.interchange.Waypoint import Speed [as 别名]
        def stream_waypoint(offset, speed=None, distance=None, heartrate=None, calories=None, steps=None, watts=None, gps=None, **kwargs):
            wp = Waypoint()
            wp.Timestamp = activity.StartTime + timedelta(seconds=offset)
            wp.Speed = float(speed) if speed else None
            wp.Distance = float(distance) / 1000 if distance else None
            wp.HR = float(heartrate) if heartrate else None
            wp.Calories = float(calories) if calories else None
            wp.Power = float(watts) if watts else None

            if gps:
                wp.Location = Location(lat=float(gps["latitude"]), lon=float(gps["longitude"]), alt=float(gps["elevation"]))
            lap.Waypoints.append(wp)
开发者ID:andylolz,项目名称:tapiriik,代码行数:14,代码来源:nikeplus.py

示例3: DownloadActivity

# 需要导入模块: from tapiriik.services.interchange import Waypoint [as 别名]
# 或者: from tapiriik.services.interchange.Waypoint import Speed [as 别名]
    def DownloadActivity(self, svcRecord, activity):
        if activity.ServiceData["Manual"]:  # I should really add a param to DownloadActivity for this value as opposed to constantly doing this
            # We've got as much information as we're going to get - we need to copy it into a Lap though.
            activity.Laps = [Lap(startTime=activity.StartTime, endTime=activity.EndTime, stats=activity.Stats)]
            return activity
        activityID = activity.ServiceData["ActivityID"]

        streamdata = requests.get("https://www.strava.com/api/v3/activities/" + str(activityID) + "/streams/time,altitude,heartrate,cadence,watts,temp,moving,latlng,distance,velocity_smooth", headers=self._apiHeaders(svcRecord))
        if streamdata.status_code == 401:
            raise APIException("No authorization to download activity", block=True, user_exception=UserException(UserExceptionType.Authorization, intervention_required=True))

        try:
            streamdata = streamdata.json()
        except:
            raise APIException("Stream data returned is not JSON")

        if "message" in streamdata and streamdata["message"] == "Record Not Found":
            raise APIException("Could not find activity")

        ridedata = {}
        for stream in streamdata:
            ridedata[stream["type"]] = stream["data"]

        lap = Lap(stats=activity.Stats, startTime=activity.StartTime, endTime=activity.EndTime) # Strava doesn't support laps, but we need somewhere to put the waypoints.
        activity.Laps = [lap]
        lap.Waypoints = []

        hasHR = "heartrate" in ridedata and len(ridedata["heartrate"]) > 0
        hasCadence = "cadence" in ridedata and len(ridedata["cadence"]) > 0
        hasTemp = "temp" in ridedata and len(ridedata["temp"]) > 0
        hasPower = ("watts" in ridedata and len(ridedata["watts"]) > 0)
        hasAltitude = "altitude" in ridedata and len(ridedata["altitude"]) > 0
        hasDistance = "distance" in ridedata and len(ridedata["distance"]) > 0
        hasVelocity = "velocity_smooth" in ridedata and len(ridedata["velocity_smooth"]) > 0

        if "error" in ridedata:
            raise APIException("Strava error " + ridedata["error"])

        inPause = False

        waypointCt = len(ridedata["time"])
        for idx in range(0, waypointCt - 1):

            waypoint = Waypoint(activity.StartTime + timedelta(0, ridedata["time"][idx]))
            if "latlng" in ridedata:
                latlng = ridedata["latlng"][idx]
                waypoint.Location = Location(latlng[0], latlng[1], None)
                if waypoint.Location.Longitude == 0 and waypoint.Location.Latitude == 0:
                    waypoint.Location.Longitude = None
                    waypoint.Location.Latitude = None

            if hasAltitude:
                if not waypoint.Location:
                    waypoint.Location = Location(None, None, None)
                waypoint.Location.Altitude = float(ridedata["altitude"][idx])

            # When pausing, Strava sends this format:
            # idx = 100 ; time = 1000; moving = true
            # idx = 101 ; time = 1001; moving = true  => convert to Pause
            # idx = 102 ; time = 2001; moving = false => convert to Resume: (2001-1001) seconds pause
            # idx = 103 ; time = 2002; moving = true

            if idx == 0:
                waypoint.Type = WaypointType.Start
            elif idx == waypointCt - 2:
                waypoint.Type = WaypointType.End
            elif idx < waypointCt - 2 and ridedata["moving"][idx+1] and inPause:
                waypoint.Type = WaypointType.Resume
                inPause = False
            elif idx < waypointCt - 2 and not ridedata["moving"][idx+1] and not inPause:
                waypoint.Type = WaypointType.Pause
                inPause = True

            if hasHR:
                waypoint.HR = ridedata["heartrate"][idx]
            if hasCadence:
                waypoint.Cadence = ridedata["cadence"][idx]
            if hasTemp:
                waypoint.Temp = ridedata["temp"][idx]
            if hasPower:
                waypoint.Power = ridedata["watts"][idx]
            if hasVelocity:
                waypoint.Speed = ridedata["velocity_smooth"][idx]
            if hasDistance:
                waypoint.Distance = ridedata["distance"][idx]
            lap.Waypoints.append(waypoint)

        return activity
开发者ID:scottrfrancis,项目名称:tapiriik,代码行数:90,代码来源:strava.py

示例4: DownloadActivity

# 需要导入模块: from tapiriik.services.interchange import Waypoint [as 别名]
# 或者: from tapiriik.services.interchange.Waypoint import Speed [as 别名]
    def DownloadActivity(self, svcRecord, activity):

        activityID = activity.ServiceData["ActivityID"]
        extID = svcRecord.ExternalID
        url = self.SingletrackerDomain + "getRideData"

        payload = {"userId": extID, "rideId": activityID}
        headers = {
            'content-type': "application/json",
            'cache-control': "no-cache",
        }
        streamdata = requests.post(url, data=json.dumps(payload), headers=headers)
        if streamdata.status_code == 500:
            raise APIException("Internal server error")

        if streamdata.status_code == 403:
            raise APIException("No authorization to download activity", block=True,
                               user_exception=UserException(UserExceptionType.Authorization,
                                                            intervention_required=True))
        if streamdata.status_code != 200:
            raise APIException("Unknown Singletracker response %d %s" % (streamdata.status_code, streamdata.text))

        try:
            streamdata = streamdata.json()
        except:
            raise APIException("Stream data returned is not JSON")

        ridedata = {}

        lap = Lap(stats=activity.Stats, startTime=activity.StartTime,
                  endTime=activity.EndTime)  # Singletracker doesn't support laps, but we need somewhere to put the waypoints.
        activity.Laps = [lap]
        lap.Waypoints = []

        wayPointExist = False

        for stream in streamdata:
            waypoint = Waypoint(dateutil.parser.parse(stream["time"], ignoretz=True))

            if "latitude" in stream:
                if "longitude" in stream:
                    latitude = stream["latitude"]
                    longitude = stream["longitude"]
                    waypoint.Location = Location(latitude, longitude, None)
                    if waypoint.Location.Longitude == 0 and waypoint.Location.Latitude == 0:
                        waypoint.Location.Longitude = None
                        waypoint.Location.Latitude = None

            if "elevation" in stream:
                if not waypoint.Location:
                    waypoint.Location = Location(None, None, None)
                waypoint.Location.Altitude = stream["elevation"]

            if "distance" in stream:
                waypoint.Distance = stream["distance"]
            if "speed" in stream:
                waypoint.Speed = stream["speed"]
            waypoint.Type = WaypointType.Regular
            lap.Waypoints.append(waypoint)

        return activity
开发者ID:OkanEsen,项目名称:tapiriik,代码行数:63,代码来源:singletracker.py


注:本文中的tapiriik.services.interchange.Waypoint.Speed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。