more autopep
This commit is contained in:
@@ -25,7 +25,7 @@ from django.conf import settings
|
|||||||
|
|
||||||
import geocoder
|
import geocoder
|
||||||
|
|
||||||
from matplotlib import path
|
# from matplotlib import path
|
||||||
import xml.etree.ElementTree as et
|
import xml.etree.ElementTree as et
|
||||||
|
|
||||||
from xml.etree.ElementTree import Element, SubElement, Comment, tostring
|
from xml.etree.ElementTree import Element, SubElement, Comment, tostring
|
||||||
@@ -42,10 +42,6 @@ def howfaris(lat_lon, course):
|
|||||||
|
|
||||||
return distance
|
return distance
|
||||||
|
|
||||||
#whatisnear = 150
|
|
||||||
|
|
||||||
# get nearest races
|
|
||||||
|
|
||||||
|
|
||||||
def getnearestraces(lat_lon, races, whatisnear=150):
|
def getnearestraces(lat_lon, races, whatisnear=150):
|
||||||
newlist = []
|
newlist = []
|
||||||
@@ -55,7 +51,6 @@ def getnearestraces(lat_lon, races, whatisnear=150):
|
|||||||
newlist.append(race)
|
newlist.append(race)
|
||||||
else:
|
else:
|
||||||
c = race.course
|
c = race.course
|
||||||
coords = c.coord
|
|
||||||
distance = howfaris(lat_lon, c)
|
distance = howfaris(lat_lon, c)
|
||||||
if distance < whatisnear:
|
if distance < whatisnear:
|
||||||
newlist.append(race)
|
newlist.append(race)
|
||||||
@@ -84,7 +79,6 @@ def getnearestcourses(lat_lon, courses, whatisnear=150, strict=False):
|
|||||||
newlist = []
|
newlist = []
|
||||||
counter = 0
|
counter = 0
|
||||||
for c in courses:
|
for c in courses:
|
||||||
coords = c.coord
|
|
||||||
distance = howfaris(lat_lon, c)
|
distance = howfaris(lat_lon, c)
|
||||||
|
|
||||||
if distance < whatisnear:
|
if distance < whatisnear:
|
||||||
@@ -199,8 +193,6 @@ def coursetokml(course):
|
|||||||
polygons = GeoPolygon.objects.filter(
|
polygons = GeoPolygon.objects.filter(
|
||||||
course=course).order_by("order_in_course")
|
course=course).order_by("order_in_course")
|
||||||
|
|
||||||
polygonsxml = []
|
|
||||||
|
|
||||||
for polygon in polygons:
|
for polygon in polygons:
|
||||||
placemark = SubElement(folder2, 'Placemark')
|
placemark = SubElement(folder2, 'Placemark')
|
||||||
polygonname = SubElement(placemark, 'name')
|
polygonname = SubElement(placemark, 'name')
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ from scipy import optimize
|
|||||||
|
|
||||||
from rowers.mytypes import otwtypes, otetypes, rowtypes
|
from rowers.mytypes import otwtypes, otetypes, rowtypes
|
||||||
|
|
||||||
#p0 = [500,350,10,8000]
|
|
||||||
p0 = [190, 200, 33, 16000]
|
p0 = [190, 200, 33, 16000]
|
||||||
|
|
||||||
# RPE to TSS
|
# RPE to TSS
|
||||||
@@ -73,10 +72,12 @@ def updatecp(delta, cpvalues, r, workouttype='water'): # pragma: no cover
|
|||||||
|
|
||||||
def cpfit(powerdf, fraclimit=0.0001, nmax=1000):
|
def cpfit(powerdf, fraclimit=0.0001, nmax=1000):
|
||||||
# Fit the data to thee parameter CP model
|
# Fit the data to thee parameter CP model
|
||||||
def fitfunc(pars, x): return abs(
|
def fitfunc(pars, x):
|
||||||
pars[0])/(1+(x/abs(pars[2]))) + abs(pars[1])/(1+(x/abs(pars[3])))
|
return abs(
|
||||||
|
pars[0])/(1+(x/abs(pars[2]))) + abs(pars[1])/(1+(x/abs(pars[3])))
|
||||||
|
|
||||||
def errfunc(pars, x, y): return fitfunc(pars, x)-y
|
def errfunc(pars, x, y):
|
||||||
|
return fitfunc(pars, x)-y
|
||||||
|
|
||||||
p1 = p0
|
p1 = p0
|
||||||
|
|
||||||
@@ -235,8 +236,6 @@ def getcp_new(dfgrouped, logarr): # pragma: no cover
|
|||||||
restime = np.array(restime)
|
restime = np.array(restime)
|
||||||
power = np.array(power)
|
power = np.array(power)
|
||||||
|
|
||||||
#power[0] = power[1]
|
|
||||||
|
|
||||||
cpvalues = griddata(restime, power,
|
cpvalues = griddata(restime, power,
|
||||||
logarr, method='linear', fill_value=0)
|
logarr, method='linear', fill_value=0)
|
||||||
|
|
||||||
@@ -264,7 +263,6 @@ def getcp(dfgrouped, logarr):
|
|||||||
delta = []
|
delta = []
|
||||||
cpvalue = []
|
cpvalue = []
|
||||||
avgpower = {}
|
avgpower = {}
|
||||||
#avgpower[0] = 0
|
|
||||||
|
|
||||||
for id, group in dfgrouped:
|
for id, group in dfgrouped:
|
||||||
tt = group['time'].copy()
|
tt = group['time'].copy()
|
||||||
@@ -273,7 +271,7 @@ def getcp(dfgrouped, logarr):
|
|||||||
# Remove data where PM is repeating final power value
|
# Remove data where PM is repeating final power value
|
||||||
# of an interval during the rest
|
# of an interval during the rest
|
||||||
rolling_std = ww.rolling(window=4).std()
|
rolling_std = ww.rolling(window=4).std()
|
||||||
deltas = tt.diff()
|
# deltas = tt.diff()
|
||||||
|
|
||||||
mask = rolling_std == 0
|
mask = rolling_std == 0
|
||||||
ww.loc[mask] = 0
|
ww.loc[mask] = 0
|
||||||
@@ -281,7 +279,7 @@ def getcp(dfgrouped, logarr):
|
|||||||
mask = ww > 2000
|
mask = ww > 2000
|
||||||
ww.loc[mask] = 0
|
ww.loc[mask] = 0
|
||||||
|
|
||||||
tmax = tt.max()
|
# tmax = tt.max()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
avgpower[id] = int(ww.mean())
|
avgpower[id] = int(ww.mean())
|
||||||
@@ -389,13 +387,13 @@ def getfastest(df, thevalue, mode='distance'):
|
|||||||
dd = pd.Series(dd, dtype='float')
|
dd = pd.Series(dd, dtype='float')
|
||||||
|
|
||||||
G = pd.concat([pd.Series([0]), dd])
|
G = pd.concat([pd.Series([0]), dd])
|
||||||
T = pd.concat([pd.Series([0]), dd])
|
# T = pd.concat([pd.Series([0]), dd])
|
||||||
h = np.mgrid[0:len(tt)+1:1, 0:len(tt)+1:1]
|
# h = np.mgrid[0:len(tt)+1:1, 0:len(tt)+1:1]
|
||||||
distances = pd.DataFrame(h[1]-h[0])
|
# distances = pd.DataFrame(h[1]-h[0])
|
||||||
ones = 1+np.zeros(len(G))
|
ones = 1+np.zeros(len(G))
|
||||||
Ghor = np.outer(ones, G)
|
Ghor = np.outer(ones, G)
|
||||||
Thor = np.outer(ones, T)
|
# Thor = np.outer(ones, T)
|
||||||
Tver = np.outer(T, ones)
|
# Tver = np.outer(T, ones)
|
||||||
Gver = np.outer(G, ones)
|
Gver = np.outer(G, ones)
|
||||||
Gdif = Ghor-Gver
|
Gdif = Ghor-Gver
|
||||||
Gdif = np.tril(Gdif.T).T
|
Gdif = np.tril(Gdif.T).T
|
||||||
@@ -428,8 +426,6 @@ def getfastest(df, thevalue, mode='distance'):
|
|||||||
# if restime[i]<thevalue*60*1000:
|
# if restime[i]<thevalue*60*1000:
|
||||||
# print(i,restime[i],distance[i],60*1000*thevalue)
|
# print(i,restime[i],distance[i],60*1000*thevalue)
|
||||||
|
|
||||||
d2 = 0
|
|
||||||
|
|
||||||
if mode == 'distance':
|
if mode == 'distance':
|
||||||
duration = griddata(distance, restime, [
|
duration = griddata(distance, restime, [
|
||||||
thevalue], method='linear', rescale=True)
|
thevalue], method='linear', rescale=True)
|
||||||
|
|||||||
@@ -70,10 +70,6 @@ def splitstdata(lijst):
|
|||||||
def imports_open(user, oauth_data):
|
def imports_open(user, oauth_data):
|
||||||
r = Rower.objects.get(user=user)
|
r = Rower.objects.get(user=user)
|
||||||
token = getattr(r, oauth_data['tokenname'])
|
token = getattr(r, oauth_data['tokenname'])
|
||||||
try:
|
|
||||||
refreshtoken = getattr(r, oauth_data['refreshtokenname'])
|
|
||||||
except (TypeError, AttributeError, KeyError): # pragma: no cover
|
|
||||||
refreshtoken = None
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
tokenexpirydate = getattr(r, oauth_data['expirydatename'])
|
tokenexpirydate = getattr(r, oauth_data['expirydatename'])
|
||||||
@@ -81,7 +77,6 @@ def imports_open(user, oauth_data):
|
|||||||
tokenexpirydate = None
|
tokenexpirydate = None
|
||||||
|
|
||||||
if (token == '') or (token is None):
|
if (token == '') or (token is None):
|
||||||
s = "Token doesn't exist. Need to authorize"
|
|
||||||
raise NoTokenError("User has no token")
|
raise NoTokenError("User has no token")
|
||||||
else:
|
else:
|
||||||
tokenname = oauth_data['tokenname']
|
tokenname = oauth_data['tokenname']
|
||||||
@@ -109,10 +104,10 @@ def imports_open(user, oauth_data):
|
|||||||
|
|
||||||
# Refresh token using refresh token
|
# Refresh token using refresh token
|
||||||
def imports_do_refresh_token(refreshtoken, oauth_data, access_token=''):
|
def imports_do_refresh_token(refreshtoken, oauth_data, access_token=''):
|
||||||
client_auth = requests.auth.HTTPBasicAuth(
|
# client_auth = requests.auth.HTTPBasicAuth(
|
||||||
oauth_data['client_id'],
|
# oauth_data['client_id'],
|
||||||
oauth_data['client_secret']
|
# oauth_data['client_secret']
|
||||||
)
|
# )
|
||||||
|
|
||||||
post_data = {"grant_type": "refresh_token",
|
post_data = {"grant_type": "refresh_token",
|
||||||
"client_secret": oauth_data['client_secret'],
|
"client_secret": oauth_data['client_secret'],
|
||||||
@@ -127,8 +122,6 @@ def imports_do_refresh_token(refreshtoken, oauth_data, access_token=''):
|
|||||||
if 'grant_type' in oauth_data:
|
if 'grant_type' in oauth_data:
|
||||||
if oauth_data['grant_type']:
|
if oauth_data['grant_type']:
|
||||||
post_data['grant_type'] = oauth_data['grant_type']
|
post_data['grant_type'] = oauth_data['grant_type']
|
||||||
else: # pragma: no cover
|
|
||||||
grant_type = post_data.pop('grant_type', None)
|
|
||||||
|
|
||||||
if oauth_data['bearer_auth']:
|
if oauth_data['bearer_auth']:
|
||||||
headers['authorization'] = 'Bearer %s' % access_token
|
headers['authorization'] = 'Bearer %s' % access_token
|
||||||
@@ -192,9 +185,9 @@ def imports_get_token(
|
|||||||
client_id = oauth_data['client_id']
|
client_id = oauth_data['client_id']
|
||||||
base_uri = oauth_data['base_url']
|
base_uri = oauth_data['base_url']
|
||||||
|
|
||||||
client_auth = requests.auth.HTTPBasicAuth(
|
# client_auth = requests.auth.HTTPBasicAuth(
|
||||||
client_id, client_secret
|
# client_id, client_secret
|
||||||
)
|
# )
|
||||||
|
|
||||||
post_data = {"grant_type": "authorization_code",
|
post_data = {"grant_type": "authorization_code",
|
||||||
"code": code,
|
"code": code,
|
||||||
@@ -216,8 +209,6 @@ def imports_get_token(
|
|||||||
post_data['grant_type'] = oauth_data['grant_type']
|
post_data['grant_type'] = oauth_data['grant_type']
|
||||||
if 'strava' in oauth_data['autorization_uri']:
|
if 'strava' in oauth_data['autorization_uri']:
|
||||||
post_data['grant_type'] = "authorization_code"
|
post_data['grant_type'] = "authorization_code"
|
||||||
else: # pragma: no cover
|
|
||||||
grant_type = post_data.pop('grant_type', None)
|
|
||||||
|
|
||||||
if 'json' in oauth_data['content_type']:
|
if 'json' in oauth_data['content_type']:
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
@@ -268,7 +259,6 @@ def imports_make_authorization_url(oauth_data): # pragma: no cover
|
|||||||
"scope": oauth_data['scope'],
|
"scope": oauth_data['scope'],
|
||||||
"state": state}
|
"state": state}
|
||||||
|
|
||||||
import urllib
|
|
||||||
url = oauth_data['authorizaton_uri']+urllib.parse.urlencode(params)
|
url = oauth_data['authorizaton_uri']+urllib.parse.urlencode(params)
|
||||||
|
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ from rowsandall_app.settings import (
|
|||||||
|
|
||||||
tpapilocation = "https://api.trainingpeaks.com"
|
tpapilocation = "https://api.trainingpeaks.com"
|
||||||
|
|
||||||
#from async_messages import message_user,messages
|
|
||||||
|
|
||||||
oauth_data = {
|
oauth_data = {
|
||||||
'client_id': TP_CLIENT_ID,
|
'client_id': TP_CLIENT_ID,
|
||||||
'client_secret': TP_CLIENT_SECRET,
|
'client_secret': TP_CLIENT_SECRET,
|
||||||
@@ -53,7 +51,7 @@ def do_refresh_token(refreshtoken):
|
|||||||
|
|
||||||
|
|
||||||
def get_token(code):
|
def get_token(code):
|
||||||
client_auth = requests.auth.HTTPBasicAuth(TP_CLIENT_KEY, TP_CLIENT_SECRET)
|
# client_auth = requests.auth.HTTPBasicAuth(TP_CLIENT_KEY, TP_CLIENT_SECRET)
|
||||||
post_data = {
|
post_data = {
|
||||||
"client_id": TP_CLIENT_KEY,
|
"client_id": TP_CLIENT_KEY,
|
||||||
"grant_type": "authorization_code",
|
"grant_type": "authorization_code",
|
||||||
@@ -61,9 +59,6 @@ def get_token(code):
|
|||||||
"redirect_uri": TP_REDIRECT_URI,
|
"redirect_uri": TP_REDIRECT_URI,
|
||||||
"client_secret": TP_CLIENT_SECRET,
|
"client_secret": TP_CLIENT_SECRET,
|
||||||
}
|
}
|
||||||
headers = {
|
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
|
||||||
}
|
|
||||||
|
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
"https://oauth.trainingpeaks.com/oauth/token",
|
"https://oauth.trainingpeaks.com/oauth/token",
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ def make_plot(r, w, f1, f2, plottype, title, imagename='', plotnr=0):
|
|||||||
}
|
}
|
||||||
|
|
||||||
axis = r.staticgrids
|
axis = r.staticgrids
|
||||||
if axis == None: # pragma: no cover
|
if axis is None: # pragma: no cover
|
||||||
gridtrue = False
|
gridtrue = False
|
||||||
axis = 'both'
|
axis = 'both'
|
||||||
else:
|
else:
|
||||||
@@ -133,14 +133,14 @@ def do_sync(w, options, quick=False):
|
|||||||
|
|
||||||
do_strava_export = w.user.strava_auto_export
|
do_strava_export = w.user.strava_auto_export
|
||||||
try:
|
try:
|
||||||
upload_to_strava = options['upload_to_Strava'] or do_strava_export
|
do_strava_export = options['upload_to_Strava'] or do_strava_export
|
||||||
except KeyError:
|
except KeyError:
|
||||||
upload_to_strava = False
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if options['stravaid'] != 0 and options['stravaid'] != '': # pragma: no cover
|
if options['stravaid'] != 0 and options['stravaid'] != '': # pragma: no cover
|
||||||
w.uploadedtostrava = options['stravaid']
|
w.uploadedtostrava = options['stravaid']
|
||||||
upload_to_strava = False
|
# upload_to_strava = False
|
||||||
do_strava_export = False
|
do_strava_export = False
|
||||||
w.save()
|
w.save()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@@ -174,14 +174,14 @@ def do_sync(w, options, quick=False):
|
|||||||
|
|
||||||
do_c2_export = w.user.c2_auto_export
|
do_c2_export = w.user.c2_auto_export
|
||||||
try:
|
try:
|
||||||
upload_to_c2 = options['upload_to_C2'] or do_c2_export
|
do_c2_export = options['upload_to_C2'] or do_c2_export
|
||||||
except KeyError:
|
except KeyError:
|
||||||
upload_to_c2 = False
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if options['c2id'] != 0 and options['c2id'] != '': # pragma: no cover
|
if options['c2id'] != 0 and options['c2id'] != '': # pragma: no cover
|
||||||
w.uploadedtoc2 = options['c2id']
|
w.uploadedtoc2 = options['c2id']
|
||||||
upload_to_c2 = False
|
# upload_to_c2 = False
|
||||||
do_c2_export = False
|
do_c2_export = False
|
||||||
w.save()
|
w.save()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@@ -250,16 +250,15 @@ def do_sync(w, options, quick=False):
|
|||||||
with open('st_export.log', 'a') as logfile:
|
with open('st_export.log', 'a') as logfile:
|
||||||
logfile.write(str(timezone.now())+': ')
|
logfile.write(str(timezone.now())+': ')
|
||||||
logfile.write(str(w.user)+' NoTokenError\n')
|
logfile.write(str(w.user)+' NoTokenError\n')
|
||||||
message = "Please connect to SportTracks first"
|
|
||||||
id = 0
|
return 0
|
||||||
|
|
||||||
if ('upload_to_TrainingPeaks' in options and options['upload_to_TrainingPeaks']) or (w.user.trainingpeaks_auto_export): # pragma: no cover
|
if ('upload_to_TrainingPeaks' in options and options['upload_to_TrainingPeaks']) or (w.user.trainingpeaks_auto_export): # pragma: no cover
|
||||||
try:
|
try:
|
||||||
message, id = tpstuff.workout_tp_upload(
|
_, id = tpstuff.workout_tp_upload(
|
||||||
w.user.user, w
|
w.user.user, w
|
||||||
)
|
)
|
||||||
except NoTokenError:
|
except NoTokenError:
|
||||||
message = "Please connect to TrainingPeaks first"
|
return 0
|
||||||
id = 0
|
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
Reference in New Issue
Block a user