本文整理汇总了Python中tapiriik.services.interchange.Waypoint.Calories方法的典型用法代码示例。如果您正苦于以下问题:Python Waypoint.Calories方法的具体用法?Python Waypoint.Calories怎么用?Python Waypoint.Calories使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tapiriik.services.interchange.Waypoint
的用法示例。
在下文中一共展示了Waypoint.Calories方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _populateActivityWaypoints
# 需要导入模块: from tapiriik.services.interchange import Waypoint [as 别名]
# 或者: from tapiriik.services.interchange.Waypoint import Calories [as 别名]
def _populateActivityWaypoints(self, rawData, activity):
''' populate the Waypoints collection from RK API data '''
lap = Lap(stats=activity.Stats, startTime=activity.StartTime, endTime=activity.EndTime)
activity.Laps = [lap]
# path is the primary stream, HR/power/etc must have fewer pts
hasHR = "heart_rate" in rawData and len(rawData["heart_rate"]) > 0
hasCalories = "calories" in rawData and len(rawData["calories"]) > 0
hasDistance = "distance" in rawData and len(rawData["distance"]) > 0
for pathpoint in rawData["path"]:
waypoint = Waypoint(activity.StartTime + timedelta(0, pathpoint["timestamp"]))
waypoint.Location = Location(pathpoint["latitude"], pathpoint["longitude"], pathpoint["altitude"] if "altitude" in pathpoint and float(pathpoint["altitude"]) != 0 else None) # if you're running near sea level, well...
waypoint.Type = self._wayptTypeMappings[pathpoint["type"]] if pathpoint["type"] in self._wayptTypeMappings else WaypointType.Regular
if hasHR:
hrpoint = [x for x in rawData["heart_rate"] if x["timestamp"] == pathpoint["timestamp"]]
if len(hrpoint) > 0:
waypoint.HR = hrpoint[0]["heart_rate"]
if hasCalories:
calpoint = [x for x in rawData["calories"] if x["timestamp"] == pathpoint["timestamp"]]
if len(calpoint) > 0:
waypoint.Calories = calpoint[0]["calories"]
if hasDistance:
distpoint = [x for x in rawData["distance"] if x["timestamp"] == pathpoint["timestamp"]]
if len(distpoint) > 0:
waypoint.Distance = distpoint[0]["distance"]
lap.Waypoints.append(waypoint)
示例2: _addWaypoint
# 需要导入模块: from tapiriik.services.interchange import Waypoint [as 别名]
# 或者: from tapiriik.services.interchange.Waypoint import Calories [as 别名]
def _addWaypoint(timestamp, path=None, heart_rate=None, calories=None, distance=None):
waypoint = Waypoint(activity.StartTime + timedelta(seconds=timestamp))
if path:
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 = self._wayptTypeMappings[path["type"]] if path["type"] in self._wayptTypeMappings else WaypointType.Regular
waypoint.HR = heart_rate
waypoint.Calories = calories
waypoint.Distance = distance
lap.Waypoints.append(waypoint)
示例3: stream_waypoint
# 需要导入模块: from tapiriik.services.interchange import Waypoint [as 别名]
# 或者: from tapiriik.services.interchange.Waypoint import Calories [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)
示例4: create_random_activity
# 需要导入模块: from tapiriik.services.interchange import Waypoint [as 别名]
# 或者: from tapiriik.services.interchange.Waypoint import Calories [as 别名]
def create_random_activity(svc=None, actType=ActivityType.Other, tz=False, record=None):
''' creates completely random activity with valid waypoints and data '''
act = TestTools.create_blank_activity(svc, actType, record=record)
if tz is True:
tz = pytz.timezone(pytz.all_timezones[random.randint(0, len(pytz.all_timezones) - 1)])
act.TZ = tz
elif tz is not False:
act.TZ = tz
if len(act.Waypoints) > 0:
raise ValueError("Waypoint list already populated")
# this is entirely random in case the testing account already has events in it (API doesn't support delete, etc)
act.StartTime = datetime(random.randint(2000, 2020), random.randint(1, 12), random.randint(1, 28), random.randint(0, 23), random.randint(0, 59), random.randint(0, 59))
if tz is not False:
if hasattr(tz, "localize"):
act.StartTime = tz.localize(act.StartTime)
else:
act.StartTime = act.StartTime.replace(tzinfo=tz)
act.EndTime = act.StartTime + timedelta(0, random.randint(60 * 5, 60 * 60)) # don't really need to upload 1000s of pts to test this...
act.Stats.Distance = ActivityStatistic(ActivityStatisticUnit.Meters, value=random.random() * 10000)
act.Name = str(random.random())
paused = False
waypointTime = act.StartTime
backToBackPauses = False
while waypointTime < act.EndTime:
wp = Waypoint()
if waypointTime == act.StartTime:
wp.Type = WaypointType.Start
wp.Timestamp = waypointTime
wp.Location = Location(random.random() * 180 - 90, random.random() * 180 - 90, random.random() * 1000) # this is gonna be one intense activity
if not (wp.HR == wp.Cadence == wp.Calories == wp.Power == wp.Temp == None):
raise ValueError("Waypoint did not initialize cleanly")
if svc.SupportsHR:
wp.HR = float(random.randint(90, 180))
if svc.SupportsPower:
wp.Power = float(random.randint(0, 1000))
if svc.SupportsCalories:
wp.Calories = float(random.randint(0, 500))
if svc.SupportsCadence:
wp.Cadence = float(random.randint(0, 100))
if svc.SupportsTemp:
wp.Temp = float(random.randint(0, 100))
if (random.randint(40, 50) == 42 or backToBackPauses) and not paused: # pause quite often
wp.Type = WaypointType.Pause
paused = True
elif paused:
paused = False
wp.Type = WaypointType.Resume
backToBackPauses = not backToBackPauses
waypointTime += timedelta(0, int(random.random() + 9.5)) # 10ish seconds
if waypointTime > act.EndTime:
wp.Timestamp = act.EndTime
wp.Type = WaypointType.End
act.Waypoints.append(wp)
if len(act.Waypoints) == 0:
raise ValueError("No waypoints populated")
return act
示例5: create_random_activity
# 需要导入模块: from tapiriik.services.interchange import Waypoint [as 别名]
# 或者: from tapiriik.services.interchange.Waypoint import Calories [as 别名]
def create_random_activity(svc=None, actType=ActivityType.Other, tz=False, record=None, withPauses=True, withLaps=True):
''' creates completely random activity with valid waypoints and data '''
act = TestTools.create_blank_activity(svc, actType, record=record)
if tz is True:
tz = pytz.timezone("America/Atikokan")
act.TZ = tz
elif tz is not False:
act.TZ = tz
if act.CountTotalWaypoints() > 0:
raise ValueError("Waypoint list already populated")
# this is entirely random in case the testing account already has events in it (API doesn't support delete, etc)
act.StartTime = datetime(2011, 12, 13, 14, 15, 16)
if tz is not False:
if hasattr(tz, "localize"):
act.StartTime = tz.localize(act.StartTime)
else:
act.StartTime = act.StartTime.replace(tzinfo=tz)
act.EndTime = act.StartTime + timedelta(0, random.randint(60 * 5, 60 * 60)) # don't really need to upload 1000s of pts to test this...
act.Stats.Distance = ActivityStatistic(ActivityStatisticUnit.Meters, value=random.random() * 10000)
act.Name = str(random.random())
paused = False
waypointTime = act.StartTime
backToBackPauses = False
act.Laps = []
lap = Lap(startTime=act.StartTime)
while waypointTime < act.EndTime:
wp = Waypoint()
if waypointTime == act.StartTime:
wp.Type = WaypointType.Start
wp.Timestamp = waypointTime
wp.Location = Location(random.random() * 180 - 90, random.random() * 180 - 90, random.random() * 1000) # this is gonna be one intense activity
if not (wp.HR == wp.Cadence == wp.Calories == wp.Power == wp.Temp == None):
raise ValueError("Waypoint did not initialize cleanly")
if svc.SupportsHR:
wp.HR = float(random.randint(90, 180))
if svc.SupportsPower:
wp.Power = float(random.randint(0, 1000))
if svc.SupportsCalories:
wp.Calories = float(random.randint(0, 500))
if svc.SupportsCadence:
wp.Cadence = float(random.randint(0, 100))
if svc.SupportsTemp:
wp.Temp = float(random.randint(0, 100))
if withPauses and (random.randint(40, 50) == 42 or backToBackPauses) and not paused: # pause quite often
wp.Type = WaypointType.Pause
paused = True
elif paused:
paused = False
wp.Type = WaypointType.Resume
backToBackPauses = not backToBackPauses
waypointTime += timedelta(0, int(random.random() + 9.5)) # 10ish seconds
lap.Waypoints.append(wp)
if waypointTime > act.EndTime:
wp.Timestamp = act.EndTime
wp.Type = WaypointType.End
elif withLaps and wp.Timestamp < act.EndTime and random.randint(40, 60) == 42:
# occasionally start new laps
lap.EndTime = wp.Timestamp
act.Laps.append(lap)
lap = Lap(startTime=waypointTime)
# Final lap
lap.EndTime = act.EndTime
act.Laps.append(lap)
if act.CountTotalWaypoints() == 0:
raise ValueError("No waypoints populated")
act.CalculateUID()
act.EnsureTZ()
return act