本文整理汇总了Python中tapiriik.services.interchange.UploadedActivity.Distance方法的典型用法代码示例。如果您正苦于以下问题:Python UploadedActivity.Distance方法的具体用法?Python UploadedActivity.Distance怎么用?Python UploadedActivity.Distance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tapiriik.services.interchange.UploadedActivity
的用法示例。
在下文中一共展示了UploadedActivity.Distance方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DownloadActivityList
# 需要导入模块: from tapiriik.services.interchange import UploadedActivity [as 别名]
# 或者: from tapiriik.services.interchange.UploadedActivity import Distance [as 别名]
def DownloadActivityList(self, serviceRecord, exhaustive=False):
cookies = self._get_cookies(serviceRecord)
activities = []
exclusions = []
pageUri = self.OpenFitEndpoint + "/fitnessActivities.json"
while True:
logger.debug("Req against " + pageUri)
res = requests.get(pageUri, cookies=cookies)
res = res.json()
for act in res["items"]:
activity = UploadedActivity()
if len(act["name"].strip()):
activity.Name = act["name"]
activity.StartTime = dateutil.parser.parse(act["start_time"])
activity.TZ = pytz.FixedOffset(activity.StartTime.tzinfo._offset.total_seconds() / 60) # Convert the dateutil lame timezones into pytz awesome timezones.
activity.StartTime = activity.StartTime.replace(tzinfo=activity.TZ)
activity.EndTime = activity.StartTime + timedelta(seconds=float(act["duration"]))
logger.debug("Activity s/t " + str(activity.StartTime))
activity.Distance = float(act["total_distance"])
activity.Type = self._activityMappings[act["type"].lower()]
activity.CalculateUID()
activity.UploadedTo = [{"Connection": serviceRecord, "ActivityURI": act["uri"]}]
activities.append(activity)
if not exhaustive or "next" not in res or not len(res["next"]):
break
else:
pageUri = res["next"]
return activities, exclusions
示例2: DownloadActivityList
# 需要导入模块: from tapiriik.services.interchange import UploadedActivity [as 别名]
# 或者: from tapiriik.services.interchange.UploadedActivity import Distance [as 别名]
def DownloadActivityList(self, serviceRecord, exhaustive=False):
cookies = self._get_cookies(record=serviceRecord)
activities = []
exclusions = []
pageUri = self.OpenFitEndpoint + "/fitnessActivities.json"
while True:
logger.debug("Req against " + pageUri)
res = requests.get(pageUri, cookies=cookies)
res = res.json()
for act in res["items"]:
activity = UploadedActivity()
activity.UploadedTo = [{"Connection": serviceRecord, "ActivityURI": act["uri"]}]
if len(act["name"].strip()):
activity.Name = act["name"]
activity.StartTime = dateutil.parser.parse(act["start_time"])
if isinstance(activity.StartTime.tzinfo, tzutc):
activity.TZ = pytz.utc # The dateutil tzutc doesn't have an _offset value.
else:
activity.TZ = pytz.FixedOffset(activity.StartTime.tzinfo._offset.total_seconds() / 60) # Convert the dateutil lame timezones into pytz awesome timezones.
activity.StartTime = activity.StartTime.replace(tzinfo=activity.TZ)
activity.EndTime = activity.StartTime + timedelta(seconds=float(act["duration"]))
# Sometimes activities get returned with a UTC timezone even when they are clearly not in UTC.
if activity.TZ == pytz.utc:
# So, we get the first location in the activity and calculate the TZ from that.
try:
firstLocation = self._downloadActivity(serviceRecord, activity, returnFirstLocation=True)
except APIExcludeActivity:
pass
else:
activity.CalculateTZ(firstLocation)
activity.AdjustTZ()
logger.debug("Activity s/t " + str(activity.StartTime))
activity.Distance = float(act["total_distance"])
types = [x.strip().lower() for x in act["type"].split(":")]
types.reverse() # The incoming format is like "walking: hiking" and we want the most specific first
activity.Type = None
for type_key in types:
if type_key in self._activityMappings:
activity.Type = self._activityMappings[type_key]
break
if not activity.Type:
exclusions.append(APIExcludeActivity("Unknown activity type %s" % act["type"], activityId=act["uri"]))
continue
activity.CalculateUID()
activities.append(activity)
if not exhaustive or "next" not in res or not len(res["next"]):
break
else:
pageUri = res["next"]
return activities, exclusions
示例3: DownloadActivityList
# 需要导入模块: from tapiriik.services.interchange import UploadedActivity [as 别名]
# 或者: from tapiriik.services.interchange.UploadedActivity import Distance [as 别名]
def DownloadActivityList(self, svcRecord, exhaustive=False):
activities = []
exclusions = []
before = earliestDate = None
while True:
logger.debug("Req with before=" + str(before) + "/" + str(earliestDate))
resp = requests.get("https://www.strava.com/api/v3/athletes/" + str(svcRecord.ExternalID) + "/activities", headers=self._apiHeaders(svcRecord), params={"before": before})
self._logAPICall("list", (svcRecord.ExternalID, str(earliestDate)), resp.status_code == 401)
if resp.status_code == 401:
raise APIException("No authorization to retrieve activity list", block=True, user_exception=UserException(UserExceptionType.Authorization, intervention_required=True))
earliestDate = None
reqdata = resp.json()
if not len(reqdata):
break # No more activities to see
for ride in reqdata:
activity = UploadedActivity()
activity.TZ = pytz.timezone(re.sub("^\([^\)]+\)\s*", "", ride["timezone"])) # Comes back as "(GMT -13:37) The Stuff/We Want""
activity.StartTime = pytz.utc.localize(datetime.strptime(ride["start_date"], "%Y-%m-%dT%H:%M:%SZ"))
logger.debug("\tActivity s/t " + str(activity.StartTime))
if not earliestDate or activity.StartTime < earliestDate:
earliestDate = activity.StartTime
before = calendar.timegm(activity.StartTime.astimezone(pytz.utc).timetuple())
if ride["start_latlng"] is None or ride["end_latlng"] is None or ride["distance"] is None or ride["distance"] == 0:
exclusions.append(APIExcludeActivity("No path", activityId=ride["id"]))
logger.debug("\t\tNo pts")
continue # stationary activity - no syncing for now
activity.EndTime = activity.StartTime + timedelta(0, ride["elapsed_time"])
activity.UploadedTo = [{"Connection": svcRecord, "ActivityID": ride["id"]}]
actType = [k for k, v in self._reverseActivityTypeMappings.items() if v == ride["type"]]
if not len(actType):
exclusions.append(APIExcludeActivity("Unsupported activity type %s" % ride["type"], activityId=ride["id"]))
logger.debug("\t\tUnknown activity")
continue
activity.Type = actType[0]
activity.Distance = ride["distance"]
activity.Name = ride["name"]
activity.Private = ride["private"]
activity.AdjustTZ()
activity.CalculateUID()
activities.append(activity)
if not exhaustive or not earliestDate:
break
return activities, exclusions
示例4: DownloadActivityList
# 需要导入模块: from tapiriik.services.interchange import UploadedActivity [as 别名]
# 或者: from tapiriik.services.interchange.UploadedActivity import Distance [as 别名]
def DownloadActivityList(self, serviceRecord, exhaustive=False):
#http://connect.garmin.com/proxy/activity-search-service-1.0/json/activities?&start=0&limit=50
cookies = self._get_cookies(record=serviceRecord)
page = 1
pageSz = 50
activities = []
exclusions = []
while True:
logger.debug("Req with " + str({"start": (page - 1) * pageSz, "limit": pageSz}))
res = requests.get("http://connect.garmin.com/proxy/activity-search-service-1.0/json/activities", params={"start": (page - 1) * pageSz, "limit": pageSz}, cookies=cookies)
res = res.json()["results"]
if "activities" not in res:
break # No activities on this page - empty account.
for act in res["activities"]:
act = act["activity"]
if "beginLatitude" not in act or "endLatitude" not in act or (act["beginLatitude"] is act["endLatitude"] and act["beginLongitude"] is act["endLongitude"]):
exclusions.append(APIExcludeActivity("No points", activityId=act["activityId"]))
continue
if "sumDistance" not in act:
exclusions.append(APIExcludeActivity("No distance", activityId=act["activityId"]))
continue
activity = UploadedActivity()
try:
activity.TZ = pytz.timezone(act["activityTimeZone"]["key"])
except pytz.exceptions.UnknownTimeZoneError:
activity.TZ = pytz.FixedOffset(float(act["activityTimeZone"]["offset"]) * 60)
logger.debug("Name " + act["activityName"]["value"] + ":")
if len(act["activityName"]["value"].strip()) and act["activityName"]["value"] != "Untitled":
activity.Name = act["activityName"]["value"]
# beginTimestamp/endTimestamp is in UTC
activity.StartTime = pytz.utc.localize(datetime.utcfromtimestamp(float(act["beginTimestamp"]["millis"])/1000))
if "sumElapsedDuration" in act:
activity.EndTime = activity.StartTime + timedelta(0, round(float(act["sumElapsedDuration"]["value"])))
elif "sumDuration" in act:
activity.EndTime = activity.StartTime + timedelta(minutes=float(act["sumDuration"]["minutesSeconds"].split(":")[0]), seconds=float(act["sumDuration"]["minutesSeconds"].split(":")[1]))
else:
activity.EndTime = pytz.utc.localize(datetime.utcfromtimestamp(float(act["endTimestamp"]["millis"])/1000))
logger.debug("Activity s/t " + str(activity.StartTime) + " on page " + str(page))
activity.AdjustTZ()
# TODO: fix the distance stats to account for the fact that this incorrectly reported km instead of meters for the longest time.
activity.Distance = float(act["sumDistance"]["value"]) * (1.60934 if act["sumDistance"]["uom"] == "mile" else 1) * 1000 # In meters...
activity.Type = self._resolveActivityType(act["activityType"]["key"])
activity.CalculateUID()
activity.UploadedTo = [{"Connection": serviceRecord, "ActivityID": act["activityId"]}]
activities.append(activity)
logger.debug("Finished page " + str(page) + " of " + str(res["search"]["totalPages"]))
if not exhaustive or int(res["search"]["totalPages"]) == page:
break
else:
page += 1
return activities, exclusions
示例5: DownloadActivityList
# 需要导入模块: from tapiriik.services.interchange import UploadedActivity [as 别名]
# 或者: from tapiriik.services.interchange.UploadedActivity import Distance [as 别名]
def DownloadActivityList(self, svcRecord, exhaustive=False):
# grumble grumble strava api sucks grumble grumble
# http://app.strava.com/api/v1/rides?athleteId=id
activities = []
exclusions = []
before = earliestDate = None
while True:
resp = requests.get("https://www.strava.com/api/v3/athletes/" + str(svcRecord.ExternalID) + "/activities", headers=self._apiHeaders(svcRecord), params={"before": before})
logger.debug("Req with before=" + str(before) + "/" + str(earliestDate))
earliestDate = None
reqdata = resp.json()
if not len(reqdata):
break # No more activities to see
for ride in reqdata:
activity = UploadedActivity()
activity.TZ = pytz.timezone(re.sub("^\([^\)]+\)\s*", "", ride["timezone"])) # Comes back as "(GMT -13:37) The Stuff/We Want""
activity.StartTime = pytz.utc.localize(datetime.strptime(ride["start_date"], "%Y-%m-%dT%H:%M:%SZ"))
logger.debug("\tActivity s/t " + str(activity.StartTime))
if not earliestDate or activity.StartTime < earliestDate:
earliestDate = activity.StartTime
before = calendar.timegm(activity.StartTime.astimezone(pytz.utc).timetuple())
if ride["start_latlng"] is None or ride["end_latlng"] is None or ride["distance"] is None or ride["distance"] == 0:
exclusions.append(APIExcludeActivity("No path", activityId=ride["id"]))
continue # stationary activity - no syncing for now
if ride["start_latlng"] == ride["end_latlng"]:
exclusions.append(APIExcludeActivity("Only one waypoint", activityId=ride["id"]))
continue # Only one waypoint, one would assume.
activity.EndTime = activity.StartTime + timedelta(0, ride["elapsed_time"])
activity.UploadedTo = [{"Connection": svcRecord, "ActivityID": ride["id"]}]
actType = [k for k, v in self._reverseActivityTypeMappings.items() if v == ride["type"]]
if not len(actType):
exclusions.append(APIExcludeActivity("Unsupported activity type", activityId=ride["id"]))
continue
activity.Type = actType[0]
activity.Distance = ride["distance"]
activity.Name = ride["name"]
activity.AdjustTZ()
activity.CalculateUID()
activities.append(activity)
if not exhaustive or not earliestDate:
break
return activities, exclusions
示例6: _populateActivity
# 需要导入模块: from tapiriik.services.interchange import UploadedActivity [as 别名]
# 或者: from tapiriik.services.interchange.UploadedActivity import Distance [as 别名]
def _populateActivity(self, rawRecord):
''' Populate the 1st level of the activity object with all details required for UID from RK API data '''
activity = UploadedActivity()
# can stay local + naive here, recipient services can calculate TZ as required
activity.StartTime = datetime.strptime(rawRecord["start_time"], "%a, %d %b %Y %H:%M:%S")
activity.EndTime = activity.StartTime + timedelta(0, round(rawRecord["duration"])) # this is inaccurate with pauses - excluded from hash
activity.Distance = rawRecord["total_distance"]
if rawRecord["type"] in self._activityMappings:
activity.Type = self._activityMappings[rawRecord["type"]]
activity.CalculateUID()
return activity
示例7: DownloadActivityList
# 需要导入模块: from tapiriik.services.interchange import UploadedActivity [as 别名]
# 或者: from tapiriik.services.interchange.UploadedActivity import Distance [as 别名]
def DownloadActivityList(self, serviceRecord, exhaustive=False):
# http://ridewithgps.com/users/1/trips.json?limit=200&order_by=created_at&order_dir=asc
# offset also supported
page = 1
pageSz = 50
activities = []
exclusions = []
while True:
logger.debug("Req with " + str({"start": (page - 1) * pageSz, "limit": pageSz}))
# TODO: take advantage of their nice ETag support
params = {"offset": (page - 1) * pageSz, "limit": pageSz}
params = self._add_auth_params(params, record=serviceRecord)
res = requests.get("http://ridewithgps.com/users/{}/trips.json".format(serviceRecord.ExternalID), params=params)
res = res.json()
total_pages = math.ceil(int(res["results_count"]) / pageSz)
for act in res["results"]:
if "first_lat" not in act or "last_lat" not in act:
exclusions.append(APIExcludeActivity("No points", activityId=act["activityId"]))
continue
if "distance" not in act:
exclusions.append(APIExcludeActivity("No distance", activityId=act["activityId"]))
continue
activity = UploadedActivity()
activity.TZ = pytz.timezone(act["time_zone"])
logger.debug("Name " + act["name"] + ":")
if len(act["name"].strip()):
activity.Name = act["name"]
activity.StartTime = pytz.utc.localize(datetime.strptime(act["departed_at"], "%Y-%m-%dT%H:%M:%SZ"))
activity.EndTime = activity.StartTime + timedelta(seconds=self._duration_to_seconds(act["duration"]))
logger.debug("Activity s/t " + str(activity.StartTime) + " on page " + str(page))
activity.AdjustTZ()
activity.Distance = float(act["distance"]) # This value is already in meters...
# Activity type is not implemented yet in RWGPS results; we will assume cycling, though perhaps "OTHER" wouuld be correct
activity.Type = ActivityType.Cycling
activity.CalculateUID()
activity.UploadedTo = [{"Connection": serviceRecord, "ActivityID": act["id"]}]
activities.append(activity)
logger.debug("Finished page {} of {}".format(page, total_pages))
if not exhaustive or total_pages == page or total_pages == 0:
break
else:
page += 1
return activities, exclusions