more pep
This commit is contained in:
@@ -11,7 +11,7 @@ import requests
|
||||
from requests import Session, Request
|
||||
from requests_oauthlib import OAuth1, OAuth1Session
|
||||
from requests_oauthlib.oauth1_session import TokenRequestDenied
|
||||
from requests import Request, Session
|
||||
|
||||
import rowers.mytypes as mytypes
|
||||
from rowers.mytypes import otwtypes
|
||||
from rowers.rower_rules import is_workout_user, ispromember
|
||||
@@ -35,13 +35,6 @@ from rowsandall_app.settings import (
|
||||
|
||||
from pytz import timezone as tz, utc
|
||||
|
||||
# You must initialize logging, otherwise you'll not see debug output.
|
||||
# logging.basicConfig()
|
||||
# logging.getLogger().setLevel(logging.DEBUG)
|
||||
#requests_log = logging.getLogger("requests.packages.urllib3")
|
||||
# requests_log.setLevel(logging.DEBUG)
|
||||
#requests_log.propagate = True
|
||||
|
||||
|
||||
from rowers.tasks import handle_get_garmin_file
|
||||
import django_rq
|
||||
@@ -100,18 +93,15 @@ repeattypes = {
|
||||
"RepeatUntilDistance": "REPEAT_UNTIL_TIME",
|
||||
"RepeatUntilCalories": "REPEAT_UNTIL_CALORIES",
|
||||
"RepeatUntilHrLessThan": "REPEAT_UNTIL_HR_LESS_THAN",
|
||||
"RepeatUntilHrGreaterThan": "REPEAT_UNTIL_HR_GREATER_THAN",
|
||||
"RepeatUntilPowerLessThan": "REPEAT_UNTIL_POWER_LESS_THAN",
|
||||
"RepeatUntilHrGreaterThan": "REPEAT_UNTIL_HR_GREATER_THAN",
|
||||
"RepeatUntilPowerLessThan": "REPEAT_UNTIL_POWER_LESS_THAN",
|
||||
"RepeatUntilPowerGreaterThan": "REPEAT_UNTIL_POWER_GREATER_THAN",
|
||||
"RepeatUntilPowerLapLessThan": "REPEAT_UNTIL_POWER_LAP_LESS_THAN",
|
||||
"RepeatUntilPowerLapLessThan": "REPEAT_UNTIL_POWER_LAP_LESS_THAN",
|
||||
"RepeatUntilPowerLapGreaterThan": "REPEAT_UNTIL_POWER_LAP_GREATER_THAN",
|
||||
}
|
||||
|
||||
|
||||
def garmin_authorize(): # pragma: no cover
|
||||
redirect_uri = oauth_data['redirect_uri']
|
||||
client_secret = oauth_data['client_secret']
|
||||
client_id = oauth_data['client_id']
|
||||
base_uri = oauth_data['base_url']
|
||||
|
||||
garmin = OAuth1Session(oauth_data['client_id'],
|
||||
@@ -133,7 +123,7 @@ def garmin_processcallback(redirect_response, resource_owner_key, resource_owner
|
||||
oauth_response = garmin.parse_authorization_response(redirect_response)
|
||||
|
||||
verifier = oauth_response.get('oauth_verifier')
|
||||
token = oauth_response.get('oauth_token')
|
||||
# token = oauth_response.get('oauth_token')
|
||||
access_token_url = 'https://connectapi.garmin.com/oauth-service/oauth/access_token'
|
||||
|
||||
# Using OAuth1Session
|
||||
@@ -155,7 +145,7 @@ def garmin_processcallback(redirect_response, resource_owner_key, resource_owner
|
||||
|
||||
def garmin_open(user): # pragma: no cover
|
||||
r = Rower.objects.get(user=user)
|
||||
token = Rower.garmintoken
|
||||
token = r.garmintoken
|
||||
|
||||
if (token == '') or (token is None):
|
||||
raise NoTokenError("User has no garmin token")
|
||||
@@ -191,7 +181,8 @@ def get_garmin_workout_list(user): # pragma: no cover
|
||||
resource_owner_secret=r.garminrefreshtoken,
|
||||
)
|
||||
|
||||
url = 'https://healthapi.garmin.com/wellness-api/rest/activities?uploadStartTimeInSeconds=1593113760&uploadEndTimeInSeconds=1593279360'
|
||||
url = 'https://healthapi.garmin.com/wellness-api/rest/' \
|
||||
'activities?uploadStartTimeInSeconds=1593113760&uploadEndTimeInSeconds=1593279360'
|
||||
|
||||
result = garmin.get(url)
|
||||
|
||||
@@ -218,7 +209,7 @@ def step_to_garmin(step, order=0):
|
||||
intensity = 'INTERVAL'
|
||||
except KeyError:
|
||||
intensity = None
|
||||
#durationvaluetype = ''
|
||||
# durationvaluetype = ''
|
||||
if durationtype == 'Time':
|
||||
durationtype = 'TIME'
|
||||
durationvalue = int(durationvalue/1000.)
|
||||
@@ -272,11 +263,11 @@ def step_to_garmin(step, order=0):
|
||||
|
||||
if targetType is not None and targetType.lower() == "power":
|
||||
targetType = 'POWER'
|
||||
if targetValue is not None and targetValue <= 1000:
|
||||
targetValueType = 'PERCENT' # pragma: no cover
|
||||
else:
|
||||
targetValueType = None
|
||||
targetValue -= 1000
|
||||
# if targetValue is not None and targetValue <= 1000:
|
||||
# targetValueType = 'PERCENT' # pragma: no cover
|
||||
# else:
|
||||
# # targetValueType = None
|
||||
# targetValue -= 1000
|
||||
|
||||
try:
|
||||
targetValueLow = step['dict']['targetValueLow']
|
||||
@@ -285,8 +276,8 @@ def step_to_garmin(step, order=0):
|
||||
targetValue = None
|
||||
elif targetValueLow == 0: # pragma: no cover
|
||||
targetValueLow = None
|
||||
elif targetValueLow <= 1000 and targetType == 'POWER': # pragma: no cover
|
||||
targetValueType = 'PERCENT'
|
||||
# elif targetValueLow <= 1000 and targetType == 'POWER': # pragma: no cover
|
||||
# targetValueType = 'PERCENT'
|
||||
elif targetValueLow > 1000 and targetType == 'POWER': # pragma: no cover
|
||||
targetValueLow -= 1000
|
||||
except KeyError:
|
||||
@@ -296,8 +287,8 @@ def step_to_garmin(step, order=0):
|
||||
if targetValue is not None and targetValue > 0 and targetValueHigh == 0: # pragma: no cover
|
||||
targetValueHigh = targetValue
|
||||
targetValue = 0
|
||||
elif targetValueHigh <= 1000 and targetType == 'POWER': # pragma: no cover
|
||||
targetValueType = 'PERCENT'
|
||||
# elif targetValueHigh <= 1000 and targetType == 'POWER': # pragma: no cover
|
||||
# targetValueType = 'PERCENT'
|
||||
elif targetValueHigh > 1000 and targetType == 'POWER': # pragma: no cover
|
||||
targetValueHigh -= 1000
|
||||
elif targetValueHigh == 0: # pragma: no cover
|
||||
@@ -477,12 +468,6 @@ def garmin_getworkout(garminid, r, activity):
|
||||
distance = activity['distanceInMeters']
|
||||
except KeyError:
|
||||
distance = 0
|
||||
try:
|
||||
averagehr = activity['averageHeartRateInBeatsPerMinute']
|
||||
maxhr = activity['maxHeartRateInBeatsPerMinute']
|
||||
except KeyError: # pragma: no cover
|
||||
averagehr = 0
|
||||
maxhr = 0
|
||||
try:
|
||||
w = Workout.objects.get(uploadedtogarmin=garminid)
|
||||
except Workout.DoesNotExist:
|
||||
@@ -494,7 +479,7 @@ def garmin_getworkout(garminid, r, activity):
|
||||
|
||||
utc_offset = datetime.timedelta(seconds=offset)
|
||||
now = datetime.datetime.now(pytz.utc)
|
||||
zones = [tz.zone for tz in map(pytz.timezone, pytz.all_timezones_set)
|
||||
zones = [ttz.zone for ttz in map(pytz.timezone, pytz.all_timezones_set)
|
||||
if now.astimezone(tz).utcoffset() == utc_offset]
|
||||
if r.defaulttimezone in zones: # pragma: no cover
|
||||
thetimezone = r.defaulttimezone
|
||||
@@ -557,12 +542,12 @@ def garmin_workouts_from_details(data):
|
||||
df[' AverageBoatSpeed (m/s)'] = 0
|
||||
df[' Stroke500mPace (sec/500m)'] = pace
|
||||
try:
|
||||
spm = df[' Cadence (stokes/min)']
|
||||
_ = df[' Cadence (stokes/min)']
|
||||
except KeyError:
|
||||
df[' Cadence (stokes/min)'] = 0
|
||||
df['cum_dist'] = df[' Horizontal (meters)']
|
||||
try:
|
||||
power = df[' Power (watts)']
|
||||
_ = df[' Power (watts)']
|
||||
except KeyError:
|
||||
df[' Power (watts)'] = 0
|
||||
df[' AverageDriveForce (lbs)'] = 0
|
||||
@@ -591,7 +576,7 @@ def garmin_workouts_from_summaries(activities):
|
||||
try:
|
||||
r = Rower.objects.get(garmintoken=garmintoken)
|
||||
id = activity['summaryId']
|
||||
w = garmin_getworkout(id, r, activity)
|
||||
_ = garmin_getworkout(id, r, activity)
|
||||
except Rower.DoesNotExist: # pragma: no cover
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user