Private
Public Access
1
0

more autopep

This commit is contained in:
Sander Roosendaal
2022-03-10 17:16:31 +01:00
parent 8070a68931
commit a0223bec24
5 changed files with 32 additions and 60 deletions

View File

@@ -25,7 +25,7 @@ from django.conf import settings
import geocoder
from matplotlib import path
# from matplotlib import path
import xml.etree.ElementTree as et
from xml.etree.ElementTree import Element, SubElement, Comment, tostring
@@ -42,10 +42,6 @@ def howfaris(lat_lon, course):
return distance
#whatisnear = 150
# get nearest races
def getnearestraces(lat_lon, races, whatisnear=150):
newlist = []
@@ -55,7 +51,6 @@ def getnearestraces(lat_lon, races, whatisnear=150):
newlist.append(race)
else:
c = race.course
coords = c.coord
distance = howfaris(lat_lon, c)
if distance < whatisnear:
newlist.append(race)
@@ -84,7 +79,6 @@ def getnearestcourses(lat_lon, courses, whatisnear=150, strict=False):
newlist = []
counter = 0
for c in courses:
coords = c.coord
distance = howfaris(lat_lon, c)
if distance < whatisnear:
@@ -199,8 +193,6 @@ def coursetokml(course):
polygons = GeoPolygon.objects.filter(
course=course).order_by("order_in_course")
polygonsxml = []
for polygon in polygons:
placemark = SubElement(folder2, 'Placemark')
polygonname = SubElement(placemark, 'name')

View File

@@ -6,7 +6,6 @@ from scipy import optimize
from rowers.mytypes import otwtypes, otetypes, rowtypes
#p0 = [500,350,10,8000]
p0 = [190, 200, 33, 16000]
# 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):
# Fit the data to thee parameter CP model
def fitfunc(pars, x): return abs(
pars[0])/(1+(x/abs(pars[2]))) + abs(pars[1])/(1+(x/abs(pars[3])))
def fitfunc(pars, x):
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
@@ -235,8 +236,6 @@ def getcp_new(dfgrouped, logarr): # pragma: no cover
restime = np.array(restime)
power = np.array(power)
#power[0] = power[1]
cpvalues = griddata(restime, power,
logarr, method='linear', fill_value=0)
@@ -264,7 +263,6 @@ def getcp(dfgrouped, logarr):
delta = []
cpvalue = []
avgpower = {}
#avgpower[0] = 0
for id, group in dfgrouped:
tt = group['time'].copy()
@@ -273,7 +271,7 @@ def getcp(dfgrouped, logarr):
# Remove data where PM is repeating final power value
# of an interval during the rest
rolling_std = ww.rolling(window=4).std()
deltas = tt.diff()
# deltas = tt.diff()
mask = rolling_std == 0
ww.loc[mask] = 0
@@ -281,7 +279,7 @@ def getcp(dfgrouped, logarr):
mask = ww > 2000
ww.loc[mask] = 0
tmax = tt.max()
# tmax = tt.max()
try:
avgpower[id] = int(ww.mean())
@@ -389,13 +387,13 @@ def getfastest(df, thevalue, mode='distance'):
dd = pd.Series(dd, dtype='float')
G = 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]
distances = pd.DataFrame(h[1]-h[0])
# T = pd.concat([pd.Series([0]), dd])
# h = np.mgrid[0:len(tt)+1:1, 0:len(tt)+1:1]
# distances = pd.DataFrame(h[1]-h[0])
ones = 1+np.zeros(len(G))
Ghor = np.outer(ones, G)
Thor = np.outer(ones, T)
Tver = np.outer(T, ones)
# Thor = np.outer(ones, T)
# Tver = np.outer(T, ones)
Gver = np.outer(G, ones)
Gdif = Ghor-Gver
Gdif = np.tril(Gdif.T).T
@@ -428,8 +426,6 @@ def getfastest(df, thevalue, mode='distance'):
# if restime[i]<thevalue*60*1000:
# print(i,restime[i],distance[i],60*1000*thevalue)
d2 = 0
if mode == 'distance':
duration = griddata(distance, restime, [
thevalue], method='linear', rescale=True)

View File

@@ -70,10 +70,6 @@ def splitstdata(lijst):
def imports_open(user, oauth_data):
r = Rower.objects.get(user=user)
token = getattr(r, oauth_data['tokenname'])
try:
refreshtoken = getattr(r, oauth_data['refreshtokenname'])
except (TypeError, AttributeError, KeyError): # pragma: no cover
refreshtoken = None
try:
tokenexpirydate = getattr(r, oauth_data['expirydatename'])
@@ -81,7 +77,6 @@ def imports_open(user, oauth_data):
tokenexpirydate = None
if (token == '') or (token is None):
s = "Token doesn't exist. Need to authorize"
raise NoTokenError("User has no token")
else:
tokenname = oauth_data['tokenname']
@@ -109,10 +104,10 @@ def imports_open(user, oauth_data):
# Refresh token using refresh token
def imports_do_refresh_token(refreshtoken, oauth_data, access_token=''):
client_auth = requests.auth.HTTPBasicAuth(
oauth_data['client_id'],
oauth_data['client_secret']
)
# client_auth = requests.auth.HTTPBasicAuth(
# oauth_data['client_id'],
# oauth_data['client_secret']
# )
post_data = {"grant_type": "refresh_token",
"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 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']:
headers['authorization'] = 'Bearer %s' % access_token
@@ -192,9 +185,9 @@ def imports_get_token(
client_id = oauth_data['client_id']
base_uri = oauth_data['base_url']
client_auth = requests.auth.HTTPBasicAuth(
client_id, client_secret
)
# client_auth = requests.auth.HTTPBasicAuth(
# client_id, client_secret
# )
post_data = {"grant_type": "authorization_code",
"code": code,
@@ -216,8 +209,6 @@ def imports_get_token(
post_data['grant_type'] = oauth_data['grant_type']
if 'strava' in oauth_data['autorization_uri']:
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']:
response = requests.post(
@@ -268,7 +259,6 @@ def imports_make_authorization_url(oauth_data): # pragma: no cover
"scope": oauth_data['scope'],
"state": state}
import urllib
url = oauth_data['authorizaton_uri']+urllib.parse.urlencode(params)
return HttpResponseRedirect(url)

View File

@@ -21,8 +21,6 @@ from rowsandall_app.settings import (
tpapilocation = "https://api.trainingpeaks.com"
#from async_messages import message_user,messages
oauth_data = {
'client_id': TP_CLIENT_ID,
'client_secret': TP_CLIENT_SECRET,
@@ -53,7 +51,7 @@ def do_refresh_token(refreshtoken):
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 = {
"client_id": TP_CLIENT_KEY,
"grant_type": "authorization_code",
@@ -61,9 +59,6 @@ def get_token(code):
"redirect_uri": TP_REDIRECT_URI,
"client_secret": TP_CLIENT_SECRET,
}
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
}
response = requests.post(
"https://oauth.trainingpeaks.com/oauth/token",

View File

@@ -87,7 +87,7 @@ def make_plot(r, w, f1, f2, plottype, title, imagename='', plotnr=0):
}
axis = r.staticgrids
if axis == None: # pragma: no cover
if axis is None: # pragma: no cover
gridtrue = False
axis = 'both'
else:
@@ -133,14 +133,14 @@ def do_sync(w, options, quick=False):
do_strava_export = w.user.strava_auto_export
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:
upload_to_strava = False
pass
try:
if options['stravaid'] != 0 and options['stravaid'] != '': # pragma: no cover
w.uploadedtostrava = options['stravaid']
upload_to_strava = False
# upload_to_strava = False
do_strava_export = False
w.save()
except KeyError:
@@ -174,14 +174,14 @@ def do_sync(w, options, quick=False):
do_c2_export = w.user.c2_auto_export
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:
upload_to_c2 = False
pass
try:
if options['c2id'] != 0 and options['c2id'] != '': # pragma: no cover
w.uploadedtoc2 = options['c2id']
upload_to_c2 = False
# upload_to_c2 = False
do_c2_export = False
w.save()
except KeyError:
@@ -250,16 +250,15 @@ def do_sync(w, options, quick=False):
with open('st_export.log', 'a') as logfile:
logfile.write(str(timezone.now())+': ')
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
try:
message, id = tpstuff.workout_tp_upload(
_, id = tpstuff.workout_tp_upload(
w.user.user, w
)
except NoTokenError:
message = "Please connect to TrainingPeaks first"
id = 0
return 0
return 1