本文整理汇总了Python中tapiriik.services.interchange.Lap.Intensity方法的典型用法代码示例。如果您正苦于以下问题:Python Lap.Intensity方法的具体用法?Python Lap.Intensity怎么用?Python Lap.Intensity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tapiriik.services.interchange.Lap
的用法示例。
在下文中一共展示了Lap.Intensity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _downloadActivity
# 需要导入模块: from tapiriik.services.interchange import Lap [as 别名]
# 或者: from tapiriik.services.interchange.Lap import Intensity [as 别名]
def _downloadActivity(self, serviceRecord, activity, returnFirstLocation=False):
activityURI = activity.ServiceData["ActivityURI"]
headers = self._getAuthHeaders(serviceRecord)
activityData = requests.get(activityURI, headers=headers)
activityData = activityData.json()
if "clock_duration" in activityData:
activity.EndTime = activity.StartTime + timedelta(seconds=float(activityData["clock_duration"]))
activity.Private = "sharing" in activityData and activityData["sharing"] != "public"
activity.GPS = False # Gets set back if there is GPS data
if "notes" in activityData:
activity.Notes = activityData["notes"]
activity.Stats.Energy = ActivityStatistic(ActivityStatisticUnit.Kilojoules, value=float(activityData["calories"]))
activity.Stats.Elevation = ActivityStatistic(ActivityStatisticUnit.Meters, gain=float(activityData["elevation_gain"]) if "elevation_gain" in activityData else None, loss=float(activityData["elevation_loss"]) if "elevation_loss" in activityData else None)
activity.Stats.HR = ActivityStatistic(ActivityStatisticUnit.BeatsPerMinute, avg=activityData["avg_heartrate"] if "avg_heartrate" in activityData else None, max=activityData["max_heartrate"] if "max_heartrate" in activityData else None)
activity.Stats.Cadence = ActivityStatistic(ActivityStatisticUnit.RevolutionsPerMinute, avg=activityData["avg_cadence"] if "avg_cadence" in activityData else None, max=activityData["max_cadence"] if "max_cadence" in activityData else None)
activity.Stats.Power = ActivityStatistic(ActivityStatisticUnit.Watts, avg=activityData["avg_power"] if "avg_power" in activityData else None, max=activityData["max_power"] if "max_power" in activityData else None)
laps_info = []
laps_starts = []
if "laps" in activityData:
laps_info = activityData["laps"]
for lap in activityData["laps"]:
laps_starts.append(dateutil.parser.parse(lap["start_time"]))
lap = None
for lapinfo in laps_info:
lap = Lap()
activity.Laps.append(lap)
lap.StartTime = dateutil.parser.parse(lapinfo["start_time"])
lap.EndTime = lap.StartTime + timedelta(seconds=lapinfo["clock_duration"])
if "type" in lapinfo:
lap.Intensity = LapIntensity.Active if lapinfo["type"] == "ACTIVE" else LapIntensity.Rest
if "distance" in lapinfo:
lap.Stats.Distance = ActivityStatistic(ActivityStatisticUnit.Meters, value=float(lapinfo["distance"]))
if "duration" in lapinfo:
lap.Stats.TimerTime = ActivityStatistic(ActivityStatisticUnit.Seconds, value=lapinfo["duration"])
if "calories" in lapinfo:
lap.Stats.Energy = ActivityStatistic(ActivityStatisticUnit.Kilojoules, value=lapinfo["calories"])
if "elevation_gain" in lapinfo:
lap.Stats.Elevation.update(ActivityStatistic(ActivityStatisticUnit.Meters, gain=float(lapinfo["elevation_gain"])))
if "elevation_loss" in lapinfo:
lap.Stats.Elevation.update(ActivityStatistic(ActivityStatisticUnit.Meters, loss=float(lapinfo["elevation_loss"])))
if "max_speed" in lapinfo:
lap.Stats.Speed.update(ActivityStatistic(ActivityStatisticUnit.MetersPerSecond, max=float(lapinfo["max_speed"])))
if "max_speed" in lapinfo:
lap.Stats.Speed.update(ActivityStatistic(ActivityStatisticUnit.MetersPerSecond, max=float(lapinfo["max_speed"])))
if "avg_speed" in lapinfo:
lap.Stats.Speed.update(ActivityStatistic(ActivityStatisticUnit.MetersPerSecond, avg=float(lapinfo["avg_speed"])))
if "max_heartrate" in lapinfo:
lap.Stats.HR.update(ActivityStatistic(ActivityStatisticUnit.BeatsPerMinute, max=float(lapinfo["max_heartrate"])))
if "avg_heartrate" in lapinfo:
lap.Stats.HR.update(ActivityStatistic(ActivityStatisticUnit.BeatsPerMinute, avg=float(lapinfo["avg_heartrate"])))
if lap is None: # No explicit laps => make one that encompasses the entire activity
lap = Lap()
activity.Laps.append(lap)
lap.Stats = activity.Stats
lap.StartTime = activity.StartTime
lap.EndTime = activity.EndTime
elif len(activity.Laps) == 1:
activity.Stats.update(activity.Laps[0].Stats) # Lap stats have a bit more info generally.
activity.Laps[0].Stats = activity.Stats
timerStops = []
if "timer_stops" in activityData:
for stop in activityData["timer_stops"]:
timerStops.append([dateutil.parser.parse(stop[0]), dateutil.parser.parse(stop[1])])
def isInTimerStop(timestamp):
for stop in timerStops:
if timestamp >= stop[0] and timestamp < stop[1]:
return True
if timestamp >= stop[1]:
return False
return False
# Collate the individual streams into our waypoints.
# Global sample rate is variable - will pick the next nearest stream datapoint.
# Resampling happens on a lookbehind basis - new values will only appear their timestamp has been reached/passed
wasInPause = False
currentLapIdx = 0
lap = activity.Laps[currentLapIdx]
streams = []
for stream in ["location", "elevation", "heartrate", "power", "cadence", "distance"]:
if stream in activityData:
streams.append(stream)
stream_indices = dict([(stream, -1) for stream in streams]) # -1 meaning the stream has yet to start
stream_lengths = dict([(stream, len(activityData[stream])/2) for stream in streams])
# Data comes as "stream":[timestamp,value,timestamp,value,...]
stream_values = {}
for stream in streams:
values = []
for x in range(0,int(len(activityData[stream])/2)):
#.........这里部分代码省略.........
示例2: _downloadActivity
# 需要导入模块: from tapiriik.services.interchange import Lap [as 别名]
# 或者: from tapiriik.services.interchange.Lap import Intensity [as 别名]
def _downloadActivity(self, serviceRecord, activity, returnFirstLocation=False):
activityURI = activity.ServiceData["ActivityURI"]
cookies = self._get_cookies(record=serviceRecord)
activityData = requests.get(activityURI, cookies=cookies)
activityData = activityData.json()
if "clock_duration" in activityData:
activity.EndTime = activity.StartTime + timedelta(seconds=float(activityData["clock_duration"]))
activity.Private = "sharing" in activityData and activityData["sharing"] != "public"
if "notes" in activityData:
activity.Notes = activityData["notes"]
activity.Stats.Energy = ActivityStatistic(ActivityStatisticUnit.Kilojoules, value=float(activityData["calories"]))
activity.Stats.Elevation = ActivityStatistic(ActivityStatisticUnit.Meters, gain=float(activityData["elevation_gain"]) if "elevation_gain" in activityData else None, loss=float(activityData["elevation_loss"]) if "elevation_loss" in activityData else None)
activity.Stats.HR = ActivityStatistic(ActivityStatisticUnit.BeatsPerMinute, avg=activityData["avg_heartrate"] if "avg_heartrate" in activityData else None, max=activityData["max_heartrate"] if "max_heartrate" in activityData else None)
activity.Stats.Cadence = ActivityStatistic(ActivityStatisticUnit.RevolutionsPerMinute, avg=activityData["avg_cadence"] if "avg_cadence" in activityData else None, max=activityData["max_cadence"] if "max_cadence" in activityData else None)
activity.Stats.Power = ActivityStatistic(ActivityStatisticUnit.Watts, avg=activityData["avg_power"] if "avg_power" in activityData else None, max=activityData["max_power"] if "max_power" in activityData else None)
laps_info = []
laps_starts = []
if "laps" in activityData:
laps_info = activityData["laps"]
for lap in activityData["laps"]:
laps_starts.append(dateutil.parser.parse(lap["start_time"]))
lap = None
for lapinfo in laps_info:
lap = Lap()
activity.Laps.append(lap)
lap.StartTime = dateutil.parser.parse(lapinfo["start_time"])
lap.EndTime = lap.StartTime + timedelta(seconds=lapinfo["clock_duration"])
if "type" in lapinfo:
lap.Intensity = LapIntensity.Active if lapinfo["type"] == "ACTIVE" else LapIntensity.Rest
if "distance" in lapinfo:
lap.Stats.Distance = ActivityStatistic(ActivityStatisticUnit.Meters, value=float(lapinfo["distance"]))
if "duration" in lapinfo:
lap.Stats.MovingTime = ActivityStatistic(ActivityStatisticUnit.Time, value=timedelta(seconds=lapinfo["duration"]))
if "calories" in lapinfo:
lap.Stats.Energy = ActivityStatistic(ActivityStatisticUnit.Kilojoules, value=lapinfo["calories"])
if "elevation_gain" in lapinfo:
lap.Stats.Elevation.update(ActivityStatistic(ActivityStatisticUnit.Meters, gain=float(lapinfo["elevation_gain"])))
if "elevation_loss" in lapinfo:
lap.Stats.Elevation.update(ActivityStatistic(ActivityStatisticUnit.Meters, loss=float(lapinfo["elevation_loss"])))
if "max_speed" in lapinfo:
lap.Stats.Speed.update(ActivityStatistic(ActivityStatisticUnit.MetersPerSecond, max=float(lapinfo["max_speed"])))
if "max_speed" in lapinfo:
lap.Stats.Speed.update(ActivityStatistic(ActivityStatisticUnit.MetersPerSecond, max=float(lapinfo["max_speed"])))
if "avg_speed" in lapinfo:
lap.Stats.Speed.update(ActivityStatistic(ActivityStatisticUnit.MetersPerSecond, avg=float(lapinfo["avg_speed"])))
if "max_heartrate" in lapinfo:
lap.Stats.HR.update(ActivityStatistic(ActivityStatisticUnit.BeatsPerMinute, max=float(lapinfo["max_heartrate"])))
if "avg_heartrate" in lapinfo:
lap.Stats.HR.update(ActivityStatistic(ActivityStatisticUnit.BeatsPerMinute, avg=float(lapinfo["avg_heartrate"])))
if lap is None: # No explicit laps => make one that encompasses the entire activity
lap = Lap()
activity.Laps.append(lap)
lap.Stats = activity.Stats
lap.StartTime = activity.StartTime
lap.EndTime = activity.EndTime
if "location" not in activityData:
activity.Stationary = True
else:
activity.Stationary = False
timerStops = []
if "timer_stops" in activityData:
for stop in activityData["timer_stops"]:
timerStops.append([dateutil.parser.parse(stop[0]), dateutil.parser.parse(stop[1])])
def isInTimerStop(timestamp):
for stop in timerStops:
if timestamp >= stop[0] and timestamp < stop[1]:
return True
if timestamp >= stop[1]:
return False
return False
# Collate the individual streams into our waypoints.
# Everything is resampled by nearest-neighbour to the rate of the location stream.
parallel_indices = {}
parallel_stream_lengths = {}
for secondary_stream in ["elevation", "heartrate", "power", "cadence", "distance"]:
if secondary_stream in activityData:
parallel_indices[secondary_stream] = 0
parallel_stream_lengths[secondary_stream] = len(activityData[secondary_stream])
wasInPause = False
currentLapIdx = 0
lap = activity.Laps[currentLapIdx]
for idx in range(0, len(activityData["location"]), 2):
# Pick the nearest indices in the parallel streams
for parallel_stream, parallel_index in parallel_indices.items():
if parallel_index + 2 == parallel_stream_lengths[parallel_stream]:
continue # We're at the end of this stream
# Is the next datapoint a better choice than the current?
if abs(activityData["location"][idx] - activityData[parallel_stream][parallel_index + 2]) < abs(activityData["location"][idx] - activityData[parallel_stream][parallel_index]):
parallel_indices[parallel_stream] += 2
#.........这里部分代码省略.........