more autopep
This commit is contained in:
@@ -31,7 +31,6 @@ from zipfile import BadZipFile
|
||||
import zipfile
|
||||
import os
|
||||
from rowers.models import strokedatafields
|
||||
from rowingdata.csvparsers import HumonParser
|
||||
|
||||
from rowingdata import (
|
||||
KinoMapParser,
|
||||
@@ -56,8 +55,7 @@ from rowingdata import (
|
||||
ETHParser,
|
||||
NKLiNKLogbookParser,
|
||||
HeroParser,
|
||||
SmartRowParser,
|
||||
)
|
||||
SmartRowParser,)
|
||||
|
||||
# All the data preparation, data cleaning and data mangling should
|
||||
# be defined here
|
||||
@@ -111,13 +109,8 @@ import arrow
|
||||
|
||||
thetimezone = get_current_timezone()
|
||||
|
||||
|
||||
#allowedcolumns = [item[0] for item in rowingmetrics]
|
||||
allowedcolumns = [key for key, value in strokedatafields.items()]
|
||||
|
||||
#from async_messages import messages as a_messages
|
||||
|
||||
|
||||
queue = django_rq.get_queue('default')
|
||||
queuelow = django_rq.get_queue('low')
|
||||
queuehigh = django_rq.get_queue('default')
|
||||
@@ -169,8 +162,6 @@ def get_video_data(w, groups=['basic'], mode='water'):
|
||||
p = nicepaceformat(p)
|
||||
df2['pace'] = p
|
||||
|
||||
#mask = df2['time'] < delay
|
||||
#df2 = df2.mask(mask).dropna()
|
||||
df2['time'] = (df2['time']-df2['time'].min())
|
||||
|
||||
df2 = df2.round(decimals=2)
|
||||
@@ -190,8 +181,6 @@ def get_video_data(w, groups=['basic'], mode='water'):
|
||||
coordinates.set_index(pd.to_timedelta(
|
||||
coordinates['time'], unit='s'), inplace=True)
|
||||
coordinates = coordinates.resample('1s').mean().interpolate()
|
||||
#mask = coordinates['time'] < delay
|
||||
#coordinates = coordinates.mask(mask).dropna()
|
||||
coordinates['time'] = coordinates['time']-coordinates['time'].min()
|
||||
latitude = coordinates['latitude']
|
||||
longitude = coordinates['longitude']
|
||||
@@ -295,11 +284,11 @@ def get_latlon_time(id):
|
||||
|
||||
try:
|
||||
try:
|
||||
latitude = rowdata.df.loc[:, ' latitude']
|
||||
longitude = rowdata.df.loc[:, ' longitude']
|
||||
_ = rowdata.df.loc[:, ' latitude']
|
||||
_ = rowdata.df.loc[:, ' longitude']
|
||||
except KeyError: # pragma: no cover
|
||||
latitude = 0 * rowdata.df.loc[:, 'TimeStamp (sec)']
|
||||
longitude = 0 * rowdata.df.loc[:, 'TimeStamp (sec)']
|
||||
rowdata.df['latitude'] = 0 * rowdata.df.loc[:, 'TimeStamp (sec)']
|
||||
rowdata.df['longitude'] = 0 * rowdata.df.loc[:, 'TimeStamp (sec)']
|
||||
except AttributeError: # pragma: no cover
|
||||
return pd.DataFrame()
|
||||
|
||||
@@ -438,7 +427,7 @@ def get_workouts(ids, userid): # pragma: no cover
|
||||
def filter_df(datadf, fieldname, value, largerthan=True):
|
||||
|
||||
try:
|
||||
x = datadf[fieldname]
|
||||
_ = datadf[fieldname]
|
||||
except KeyError:
|
||||
return datadf
|
||||
|
||||
@@ -486,9 +475,9 @@ def join_workouts(r, ids, title='Joined Workout',
|
||||
makeprivate = False
|
||||
startdatetime = timezone.now()
|
||||
|
||||
if setprivate == True and makeprivate == False: # pragma: no cover
|
||||
if setprivate is True and makeprivate is False: # pragma: no cover
|
||||
makeprivate = True
|
||||
elif setprivate == False and makeprivate == True: # pragma: no cover
|
||||
elif setprivate is False and makeprivate is True: # pragma: no cover
|
||||
makeprivate = False
|
||||
|
||||
# reorder in chronological order
|
||||
@@ -501,6 +490,11 @@ def join_workouts(r, ids, title='Joined Workout',
|
||||
workouttype = parent.workouttype
|
||||
notes = parent.notes
|
||||
summary = parent.summary
|
||||
if parent.privacy == 'hidden':
|
||||
makeprivate = True
|
||||
else:
|
||||
makeprivate = False
|
||||
startdatetime = parent.startdatetime
|
||||
|
||||
files = [w.csvfilename for w in ws]
|
||||
|
||||
@@ -524,7 +518,9 @@ def join_workouts(r, ids, title='Joined Workout',
|
||||
notes=notes,
|
||||
oarlength=oarlength,
|
||||
inboard=inboard,
|
||||
startdatetime=startdatetime,
|
||||
makeprivate=makeprivate,
|
||||
summary=summary,
|
||||
dosmooth=False,
|
||||
consistencychecks=False)
|
||||
|
||||
@@ -585,12 +581,12 @@ def resample(id, r, parent, overwrite='copy'):
|
||||
|
||||
row.write_csv(parent.csvfilename, gzip=True)
|
||||
|
||||
res = dataprep(row.df, id=parent.id, bands=True, barchart=True,
|
||||
otwpower=True, empower=True, inboard=parent.inboard)
|
||||
_ = dataprep(row.df, id=parent.id, bands=True, barchart=True,
|
||||
otwpower=True, empower=True, inboard=parent.inboard)
|
||||
isbreakthrough, ishard = checkbreakthrough(parent, r)
|
||||
marker = check_marker(parent)
|
||||
result = update_wps(r, mytypes.otwtypes)
|
||||
result = update_wps(r, mytypes.otetypes)
|
||||
_ = check_marker(parent)
|
||||
_ = update_wps(r, mytypes.otwtypes)
|
||||
_ = update_wps(r, mytypes.otetypes)
|
||||
|
||||
tss, normp = workout_rscore(parent)
|
||||
goldmedalstandard, goldmedalseconds = workout_goldmedalstandard(parent)
|
||||
@@ -607,7 +603,7 @@ def clean_df_stats(datadf, workstrokesonly=True, ignorehr=True,
|
||||
# clean data remove zeros and negative values
|
||||
|
||||
try:
|
||||
workoutids = datadf['workoutid'].unique()
|
||||
_ = datadf['workoutid'].unique()
|
||||
except KeyError:
|
||||
datadf['workoutid'] = 0
|
||||
|
||||
@@ -638,13 +634,13 @@ def clean_df_stats(datadf, workstrokesonly=True, ignorehr=True,
|
||||
# protect 0 spm values from being nulled
|
||||
try:
|
||||
datadf['spm'] = datadf['spm'] + 1.0
|
||||
except (KeyError, TypeError) as e:
|
||||
except (KeyError, TypeError):
|
||||
pass
|
||||
|
||||
# protect 0 workoutstate values from being nulled
|
||||
try:
|
||||
datadf['workoutstate'] = datadf['workoutstate'] + 1
|
||||
except (KeyError, TypeError) as e:
|
||||
except (KeyError, TypeError):
|
||||
pass
|
||||
|
||||
try:
|
||||
@@ -676,13 +672,13 @@ def clean_df_stats(datadf, workstrokesonly=True, ignorehr=True,
|
||||
# bring spm back to real values
|
||||
try:
|
||||
datadf['spm'] = datadf['spm'] - 1
|
||||
except (TypeError, KeyError) as e:
|
||||
except (TypeError, KeyError):
|
||||
pass
|
||||
|
||||
# bring workoutstate back to real values
|
||||
try:
|
||||
datadf['workoutstate'] = datadf['workoutstate'] - 1
|
||||
except (TypeError, KeyError) as e:
|
||||
except (TypeError, KeyError):
|
||||
pass
|
||||
|
||||
# return from positive domain to negative
|
||||
@@ -840,11 +836,11 @@ def clean_df_stats(datadf, workstrokesonly=True, ignorehr=True,
|
||||
except (KeyError, TypeError):
|
||||
pass
|
||||
|
||||
workoutstateswork = [1, 4, 5, 8, 9, 6, 7]
|
||||
# workoutstateswork = [1, 4, 5, 8, 9, 6, 7]
|
||||
workoutstatesrest = [3]
|
||||
workoutstatetransition = [0, 2, 10, 11, 12, 13]
|
||||
# workoutstatetransition = [0, 2, 10, 11, 12, 13]
|
||||
|
||||
if workstrokesonly == 'True' or workstrokesonly == True:
|
||||
if workstrokesonly == 'True' or workstrokesonly is True:
|
||||
try:
|
||||
datadf = datadf[~datadf['workoutstate'].isin(workoutstatesrest)]
|
||||
except:
|
||||
@@ -872,10 +868,10 @@ def getpartofday(row, r):
|
||||
timezone_str = tf.timezone_at(lng=lonavg, lat=latavg)
|
||||
except (ValueError, OverflowError): # pragma: no cover
|
||||
timezone_str = 'UTC'
|
||||
if timezone_str == None: # pragma: no cover
|
||||
if timezone_str is None: # pragma: no cover
|
||||
timezone_str = tf.closest_timezone_at(lng=lonavg,
|
||||
lat=latavg)
|
||||
if timezone_str == None:
|
||||
if timezone_str is None:
|
||||
timezone_str = r.defaulttimezone
|
||||
try:
|
||||
workoutstartdatetime = pytz.timezone(timezone_str).localize(
|
||||
@@ -1008,7 +1004,7 @@ def update_c2id_sql(id, c2id):
|
||||
table, c2id, id)
|
||||
|
||||
with engine.connect() as conn, conn.begin():
|
||||
result = conn.execute(query)
|
||||
_ = conn.execute(query)
|
||||
|
||||
conn.close()
|
||||
engine.dispose()
|
||||
@@ -1022,7 +1018,8 @@ def getcpdata_sql(rower_id, table='cpdata'):
|
||||
rower_id=rower_id,
|
||||
table=table,
|
||||
))
|
||||
connection = engine.raw_connection()
|
||||
|
||||
_ = engine.raw_connection()
|
||||
df = pd.read_sql_query(query, engine)
|
||||
|
||||
return df
|
||||
@@ -1036,7 +1033,7 @@ def deletecpdata_sql(rower_id, table='cpdata'): # pragma: no cover
|
||||
))
|
||||
with engine.connect() as conn, conn.begin():
|
||||
try:
|
||||
result = conn.execute(query)
|
||||
_ = conn.execute(query)
|
||||
except:
|
||||
print("Database locked")
|
||||
conn.close()
|
||||
@@ -1064,11 +1061,10 @@ def updatecpdata_sql(rower_id, delta, cp, table='cpdata', distance=[]): # pragm
|
||||
|
||||
|
||||
def fetchcperg(rower, theworkouts):
|
||||
theids = [int(w.id) for w in theworkouts]
|
||||
thefilenames = [w.csvfilename for w in theworkouts]
|
||||
cpdf = getcpdata_sql(rower.id, table='ergcpdata')
|
||||
|
||||
job = myqueue(
|
||||
_ = myqueue(
|
||||
queuelow,
|
||||
handle_updateergcp,
|
||||
rower.id,
|
||||
@@ -1138,7 +1134,7 @@ def check_marker(workout):
|
||||
theid = df.loc[indexmax, 'id']
|
||||
|
||||
wmax = Workout.objects.get(id=theid)
|
||||
gms_max = wmax.goldmedalstandard
|
||||
# gms_max = wmax.goldmedalstandard
|
||||
|
||||
# check if equal, bigger, or smaller than previous
|
||||
if not wmax.rankingpiece:
|
||||
@@ -1210,16 +1206,17 @@ def calculate_goldmedalstandard(rower, workout, recurrance=True):
|
||||
)
|
||||
)
|
||||
jsondf = df2.to_json()
|
||||
job = myqueue(queuelow, handle_getagegrouprecords,
|
||||
jsondf, distances, durations, age, rower.sex, rower.weightcategory)
|
||||
_ = myqueue(queuelow, handle_getagegrouprecords,
|
||||
jsondf, distances, durations, age, rower.sex, rower.weightcategory)
|
||||
|
||||
wcpower = pd.Series(wcpower, dtype='float')
|
||||
wcdurations = pd.Series(wcdurations, dtype='float')
|
||||
|
||||
def fitfunc(pars, x): return pars[0] / \
|
||||
(1+(x/pars[2])) + pars[1]/(1+(x/pars[3]))
|
||||
def fitfunc(pars, x):
|
||||
return pars[0] / (1+(x/pars[2])) + pars[1]/(1+(x/pars[3]))
|
||||
|
||||
def errfunc(pars, x, y): return fitfunc(pars, x)-y
|
||||
def errfunc(pars, x, y):
|
||||
return fitfunc(pars, x)-y
|
||||
|
||||
if len(wcdurations) >= 4: # pragma: no cover
|
||||
p1wc, success = optimize.leastsq(
|
||||
@@ -1227,7 +1224,7 @@ def calculate_goldmedalstandard(rower, workout, recurrance=True):
|
||||
else:
|
||||
factor = fitfunc(p0, wcdurations.mean()/wcpower.mean())
|
||||
p1wc = [p0[0]/factor, p0[1]/factor, p0[2], p0[3]]
|
||||
success = 0
|
||||
|
||||
return 0, 0
|
||||
|
||||
times = df['delta']
|
||||
@@ -1292,7 +1289,7 @@ def setcp(workout, background=False, recurrance=True):
|
||||
return pd.DataFrame(), pd.Series(dtype='float'), pd.Series(dtype='float')
|
||||
|
||||
if background: # pragma: no cover
|
||||
job = myqueue(queuelow, handle_setcp, strokesdf, filename, workout.id)
|
||||
_ = myqueue(queuelow, handle_setcp, strokesdf, filename, workout.id)
|
||||
return pd.DataFrame({'delta': [], 'cp': []}), pd.Series(dtype='float'), pd.Series(dtype='float')
|
||||
|
||||
if not strokesdf.empty:
|
||||
@@ -1339,7 +1336,7 @@ def update_wps(r, types, mode='water', asynchron=True):
|
||||
|
||||
ids = [w.id for w in workouts]
|
||||
if asynchron:
|
||||
job = myqueue(
|
||||
_ = myqueue(
|
||||
queue,
|
||||
handle_update_wps,
|
||||
r.id,
|
||||
@@ -1441,11 +1438,11 @@ def fetchcp(rower, theworkouts, table='cpdata'): # pragma: no cover
|
||||
if not cpdf.empty:
|
||||
return cpdf['delta'], cpdf['cp'], avgpower2
|
||||
else:
|
||||
job = myqueue(queuelow,
|
||||
handle_updatecp,
|
||||
rower.id,
|
||||
theids,
|
||||
table=table)
|
||||
_ = myqueue(queuelow,
|
||||
handle_updatecp,
|
||||
rower.id,
|
||||
theids,
|
||||
table=table)
|
||||
|
||||
return pd.Series([], dtype='float'), pd.Series([], dtype='float'), avgpower2
|
||||
|
||||
@@ -1489,11 +1486,11 @@ def create_row_df(r, distance, duration, startdatetime, workouttype='rower',
|
||||
else:
|
||||
spm = avgspm
|
||||
|
||||
step = totalseconds/float(nr_strokes)
|
||||
# step = totalseconds/float(nr_strokes)
|
||||
|
||||
elapsed = np.arange(nr_strokes)*totalseconds/(float(nr_strokes-1))
|
||||
|
||||
dstep = distance/float(nr_strokes)
|
||||
# dstep = distance/float(nr_strokes)
|
||||
|
||||
d = np.arange(nr_strokes)*distance/(float(nr_strokes-1))
|
||||
|
||||
@@ -1564,12 +1561,12 @@ def checkbreakthrough(w, r):
|
||||
if workouttype in otwtypes:
|
||||
res, btvalues, res2 = utils.isbreakthrough(
|
||||
delta, cpvalues, r.p0, r.p1, r.p2, r.p3, r.cpratio)
|
||||
success = update_rolling_cp(r, otwtypes, 'water')
|
||||
_ = update_rolling_cp(r, otwtypes, 'water')
|
||||
|
||||
elif workouttype in otetypes:
|
||||
res, btvalues, res2 = utils.isbreakthrough(
|
||||
delta, cpvalues, r.ep0, r.ep1, r.ep2, r.ep3, r.ecpratio)
|
||||
success = update_rolling_cp(r, otetypes, 'erg')
|
||||
_ = update_rolling_cp(r, otetypes, 'erg')
|
||||
else: # pragma: no cover
|
||||
res = 0
|
||||
res2 = 0
|
||||
@@ -1584,12 +1581,12 @@ def checkbreakthrough(w, r):
|
||||
w.rankingpiece = True
|
||||
w.save()
|
||||
if r.getemailnotifications and not r.emailbounced: # pragma: no cover
|
||||
job = myqueue(queuehigh, handle_sendemail_breakthrough,
|
||||
w.id,
|
||||
r.user.email,
|
||||
r.user.first_name,
|
||||
r.user.last_name,
|
||||
btvalues=btvalues.to_json())
|
||||
_ = myqueue(queuehigh, handle_sendemail_breakthrough,
|
||||
w.id,
|
||||
r.user.email,
|
||||
r.user.first_name,
|
||||
r.user.last_name,
|
||||
btvalues=btvalues.to_json())
|
||||
|
||||
# submit email task to send email about breakthrough workout
|
||||
if ishard: # pragma: no cover
|
||||
@@ -1597,12 +1594,12 @@ def checkbreakthrough(w, r):
|
||||
w.rankingpiece = True
|
||||
w.save()
|
||||
if r.getemailnotifications and not r.emailbounced:
|
||||
job = myqueue(queuehigh, handle_sendemail_hard,
|
||||
w.id,
|
||||
r.user.email,
|
||||
r.user.first_name,
|
||||
r.user.last_name,
|
||||
btvalues=btvalues.to_json())
|
||||
_ = myqueue(queuehigh, handle_sendemail_hard,
|
||||
w.id,
|
||||
r.user.email,
|
||||
r.user.first_name,
|
||||
r.user.last_name,
|
||||
btvalues=btvalues.to_json())
|
||||
|
||||
return isbreakthrough, ishard
|
||||
|
||||
@@ -1624,7 +1621,6 @@ def checkduplicates(r, workoutdate, workoutstartdatetime, workoutenddatetime):
|
||||
ws2.append(ww)
|
||||
|
||||
if (len(ws2) != 0):
|
||||
message = "Warning: This workout overlaps with an existing one and was marked as a duplicate"
|
||||
duplicate = True
|
||||
return duplicate
|
||||
|
||||
@@ -1724,7 +1720,7 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
|
||||
windowsize = 2 * (int(10. / (f))) + 1
|
||||
else: # pragma: no cover
|
||||
windowsize = 1
|
||||
if not 'originalvelo' in row.df:
|
||||
if 'originalvelo' not in row.df:
|
||||
row.df['originalvelo'] = velo
|
||||
|
||||
if windowsize > 3 and windowsize < len(velo):
|
||||
@@ -1861,16 +1857,16 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
|
||||
w.team.add(t)
|
||||
|
||||
# put stroke data in database
|
||||
res = dataprep(row.df, id=w.id, bands=True,
|
||||
barchart=True, otwpower=True, empower=True, inboard=inboard)
|
||||
_ = dataprep(row.df, id=w.id, bands=True,
|
||||
barchart=True, otwpower=True, empower=True, inboard=inboard)
|
||||
|
||||
isbreakthrough, ishard = checkbreakthrough(w, r)
|
||||
marker = check_marker(w)
|
||||
result = update_wps(r, mytypes.otwtypes)
|
||||
result = update_wps(r, mytypes.otetypes)
|
||||
_ = check_marker(w)
|
||||
_ = update_wps(r, mytypes.otwtypes)
|
||||
_ = update_wps(r, mytypes.otetypes)
|
||||
|
||||
job = myqueue(queuehigh, handle_calctrimp, w.id, f2,
|
||||
r.ftp, r.sex, r.hrftp, r.max, r.rest)
|
||||
_ = myqueue(queuehigh, handle_calctrimp, w.id, f2,
|
||||
r.ftp, r.sex, r.hrftp, r.max, r.rest)
|
||||
|
||||
return (w.id, message)
|
||||
|
||||
@@ -1914,7 +1910,7 @@ def get_startdate_time_zone(r, row, startdatetime=None):
|
||||
startdatetime = row.rowdatetime
|
||||
|
||||
try:
|
||||
tz = startdatetime.tzinfo
|
||||
_ = startdatetime.tzinfo
|
||||
except AttributeError: # pragma: no cover
|
||||
startdatetime = row.rowdatetime
|
||||
|
||||
@@ -1987,7 +1983,6 @@ def parsenonpainsled(fileformat, f2, summary, startdatetime='', empowerfirmware=
|
||||
|
||||
s = 'Parsenonpainsled, start date time = {startdatetime}'.format(
|
||||
startdatetime=startdatetime,
|
||||
#rowdatetime = row.rowdatetime
|
||||
)
|
||||
dologging('debuglog.log', s)
|
||||
|
||||
@@ -2158,11 +2153,10 @@ def new_workout_from_file(r, f2,
|
||||
uploadoptions['file'] = datafile
|
||||
url = settings.UPLOAD_SERVICE_URL
|
||||
|
||||
job = myqueue(queuehigh,
|
||||
handle_request_post,
|
||||
url,
|
||||
uploadoptions
|
||||
)
|
||||
_ = myqueue(queuehigh,
|
||||
handle_request_post,
|
||||
url,
|
||||
uploadoptions)
|
||||
|
||||
except BadZipFile: # pragma: no cover
|
||||
pass
|
||||
@@ -2227,10 +2221,10 @@ def new_workout_from_file(r, f2,
|
||||
extension = extension2
|
||||
f4 = filename+'a'+extension
|
||||
copyfile(f2, f4)
|
||||
job = myqueue(queuehigh,
|
||||
handle_sendemail_unrecognized,
|
||||
f4,
|
||||
r.user.email)
|
||||
_ = myqueue(queuehigh,
|
||||
handle_sendemail_unrecognized,
|
||||
f4,
|
||||
r.user.email)
|
||||
|
||||
return (0, message, f2)
|
||||
|
||||
@@ -2377,7 +2371,7 @@ def split_workout(r, parent, splitsecond, splitmode):
|
||||
messages.append(message)
|
||||
ids.append(encoder.encode_hex(id))
|
||||
|
||||
if not 'keep original' in splitmode: # pragma: no cover
|
||||
if 'keep original' not in splitmode: # pragma: no cover
|
||||
if 'keep second' in splitmode or 'keep first' in splitmode:
|
||||
parent.delete()
|
||||
messages.append('Deleted Workout: ' + parent.name)
|
||||
@@ -2448,7 +2442,6 @@ def new_workout_from_df(r, df,
|
||||
|
||||
df.rename(columns=columndict, inplace=True)
|
||||
|
||||
#starttimeunix = mktime(startdatetime.utctimetuple())
|
||||
starttimeunix = arrow.get(startdatetime).timestamp()
|
||||
df[' ElapsedTime (sec)'] = df['TimeStamp (sec)']
|
||||
|
||||
@@ -2458,15 +2451,13 @@ def new_workout_from_df(r, df,
|
||||
|
||||
row.write_csv(csvfilename, gzip=True)
|
||||
|
||||
# res = df.to_csv(csvfilename+'.gz',index_label='index',
|
||||
# compression='gzip')
|
||||
|
||||
id, message = save_workout_database(csvfilename, r,
|
||||
workouttype=workouttype,
|
||||
boattype=boattype,
|
||||
title=title,
|
||||
workoutsource=workoutsource,
|
||||
notes=notes,
|
||||
summary=summary,
|
||||
oarlength=oarlength,
|
||||
inboard=inboard,
|
||||
makeprivate=makeprivate,
|
||||
@@ -2474,8 +2465,8 @@ def new_workout_from_df(r, df,
|
||||
rpe=rpe,
|
||||
consistencychecks=False)
|
||||
|
||||
job = myqueue(queuehigh, handle_calctrimp, id, csvfilename,
|
||||
r.ftp, r.sex, r.hrftp, r.max, r.rest)
|
||||
_ = myqueue(queuehigh, handle_calctrimp, id, csvfilename,
|
||||
r.ftp, r.sex, r.hrftp, r.max, r.rest)
|
||||
|
||||
return (id, message)
|
||||
|
||||
@@ -2520,7 +2511,7 @@ def delete_strokedata(id):
|
||||
|
||||
def update_strokedata(id, df):
|
||||
delete_strokedata(id)
|
||||
rowdata = dataprep(df, id=id, bands=True, barchart=True, otwpower=True)
|
||||
_ = dataprep(df, id=id, bands=True, barchart=True, otwpower=True)
|
||||
|
||||
# Test that all data are of a numerical time
|
||||
|
||||
@@ -2555,7 +2546,7 @@ def getrowdata_db(id=0, doclean=False, convertnewtons=True,
|
||||
else:
|
||||
row = Workout.objects.get(id=id)
|
||||
|
||||
if checkefficiency == True and not data.empty:
|
||||
if checkefficiency is True and not data.empty:
|
||||
try:
|
||||
if data['efficiency'].mean() == 0 and data['power'].mean() != 0: # pragma: no cover
|
||||
data = add_efficiency(id=id)
|
||||
@@ -2586,15 +2577,13 @@ def getsmallrowdata_db(columns, ids=[], doclean=True, workstrokesonly=True, comp
|
||||
if len(ids) > 1:
|
||||
for id, f in zip(ids, csvfilenames):
|
||||
try:
|
||||
#df = dd.read_parquet(f,columns=columns,engine='pyarrow')
|
||||
df = pd.read_parquet(f, columns=columns)
|
||||
data.append(df)
|
||||
except (OSError, ArrowInvalid, IndexError): # pragma: no cover
|
||||
rowdata, row = getrowdata(id=id)
|
||||
if rowdata and len(rowdata.df):
|
||||
datadf = dataprep(rowdata.df, id=id,
|
||||
bands=True, otwpower=True, barchart=True)
|
||||
# df = dd.read_parquet(f,columns=columns,engine='pyarrow')
|
||||
_ = dataprep(rowdata.df, id=id,
|
||||
bands=True, otwpower=True, barchart=True)
|
||||
df = pd.read_parquet(f, columns=columns)
|
||||
data.append(df)
|
||||
|
||||
@@ -2649,7 +2638,6 @@ def getrowdata(id=0):
|
||||
# get user
|
||||
|
||||
r = row.user
|
||||
u = r.user
|
||||
|
||||
rr = rrower(hrmax=r.max, hrut2=r.ut2,
|
||||
hrut1=r.ut1, hrat=r.at,
|
||||
@@ -2677,8 +2665,8 @@ def prepmultipledata(ids, verbose=False): # pragma: no cover
|
||||
if verbose:
|
||||
print(id)
|
||||
if rowdata and len(rowdata.df):
|
||||
data = dataprep(rowdata.df, id=id, bands=True,
|
||||
barchart=True, otwpower=True)
|
||||
_ = dataprep(rowdata.df, id=id, bands=True,
|
||||
barchart=True, otwpower=True)
|
||||
return ids
|
||||
|
||||
# Read a set of columns for a set of workout ids, returns data as a
|
||||
@@ -2707,8 +2695,8 @@ def read_cols_df_sql(ids, columns, convertnewtons=True):
|
||||
except OSError:
|
||||
rowdata, row = getrowdata(id=ids[0])
|
||||
if rowdata and len(rowdata.df):
|
||||
datadf = dataprep(
|
||||
rowdata.df, id=ids[0], bands=True, otwpower=True, barchart=True)
|
||||
_ = dataprep(rowdata.df,
|
||||
id=ids[0], bands=True, otwpower=True, barchart=True)
|
||||
df = pd.read_parquet(filename, columns=columns)
|
||||
else:
|
||||
data = []
|
||||
@@ -2721,8 +2709,8 @@ def read_cols_df_sql(ids, columns, convertnewtons=True):
|
||||
except (OSError, IndexError, ArrowInvalid):
|
||||
rowdata, row = getrowdata(id=id)
|
||||
if rowdata and len(rowdata.df): # pragma: no cover
|
||||
datadf = dataprep(rowdata.df, id=id,
|
||||
bands=True, otwpower=True, barchart=True)
|
||||
_ = dataprep(rowdata.df, id=id,
|
||||
bands=True, otwpower=True, barchart=True)
|
||||
df = pd.read_parquet(f, columns=columns)
|
||||
data.append(df)
|
||||
|
||||
@@ -2753,8 +2741,8 @@ def read_cols_df_sql(ids, columns, convertnewtons=True):
|
||||
|
||||
|
||||
def initiate_cp(r):
|
||||
success = update_rolling_cp(r, otwtypes, 'water')
|
||||
success = update_rolling_cp(r, otetypes, 'erg')
|
||||
_ = update_rolling_cp(r, otwtypes, 'water')
|
||||
_ = update_rolling_cp(r, otetypes, 'erg')
|
||||
|
||||
# Read stroke data from the DB for a Workout ID. Returns a pandas dataframe
|
||||
|
||||
@@ -2784,9 +2772,6 @@ def read_df_sql(id):
|
||||
|
||||
|
||||
def datafusion(id1, id2, columns, offset):
|
||||
workout1 = Workout.objects.get(id=id1)
|
||||
workout2 = Workout.objects.get(id=id2)
|
||||
|
||||
df1, w1 = getrowdata_db(id=id1)
|
||||
df1 = df1.drop([ # 'cumdist',
|
||||
'hr_ut2',
|
||||
@@ -2821,7 +2806,7 @@ def datafusion(id1, id2, columns, offset):
|
||||
keep1.pop(c)
|
||||
|
||||
for c in df1.columns:
|
||||
if not c in keep1:
|
||||
if c not in keep1:
|
||||
df1 = df1.drop(c, 1, errors='ignore')
|
||||
|
||||
df = pd.concat([df1, df2], ignore_index=True)
|
||||
@@ -2846,7 +2831,6 @@ def fix_newtons(id=0, limit=3000): # pragma: no cover
|
||||
# rowdata,row = getrowdata_db(id=id,doclean=False,convertnewtons=False)
|
||||
rowdata = getsmallrowdata_db(['peakforce'], ids=[id], doclean=False)
|
||||
try:
|
||||
#avgforce = rowdata['averageforce']
|
||||
peakforce = rowdata['peakforce']
|
||||
if peakforce.mean() > limit:
|
||||
w = Workout.objects.get(id=id)
|
||||
@@ -2860,7 +2844,7 @@ def fix_newtons(id=0, limit=3000): # pragma: no cover
|
||||
|
||||
def remove_invalid_columns(df): # pragma: no cover
|
||||
for c in df.columns:
|
||||
if not c in allowedcolumns:
|
||||
if c not in allowedcolumns:
|
||||
df.drop(labels=c, axis=1, inplace=True)
|
||||
|
||||
return df
|
||||
@@ -2907,7 +2891,6 @@ def dataprep(rowdatadf, id=0, bands=True, barchart=True, otwpower=True,
|
||||
if rowdatadf.empty:
|
||||
return 0
|
||||
|
||||
#rowdatadf.set_index([range(len(rowdatadf))], inplace=True)
|
||||
t = rowdatadf.loc[:, 'TimeStamp (sec)']
|
||||
t = pd.Series(t - rowdatadf.loc[:, 'TimeStamp (sec)'].iloc[0])
|
||||
|
||||
@@ -2981,7 +2964,7 @@ def dataprep(rowdatadf, id=0, bands=True, barchart=True, otwpower=True,
|
||||
if forceunit == 'lbs':
|
||||
driveenergy = drivelength * averageforce * lbstoN
|
||||
else:
|
||||
drivenergy = drivelength * averageforce
|
||||
driveenergy = drivelength * averageforce
|
||||
|
||||
if forceunit == 'lbs':
|
||||
averageforce *= lbstoN
|
||||
@@ -3034,7 +3017,7 @@ def dataprep(rowdatadf, id=0, bands=True, barchart=True, otwpower=True,
|
||||
data['hr_bottom'] = 0.0 * data['hr']
|
||||
|
||||
try:
|
||||
tel = rowdatadf.loc[:, ' ElapsedTime (sec)']
|
||||
_ = rowdatadf.loc[:, ' ElapsedTime (sec)']
|
||||
except KeyError: # pragma: no cover
|
||||
rowdatadf[' ElapsedTime (sec)'] = rowdatadf['TimeStamp (sec)']
|
||||
|
||||
@@ -3218,7 +3201,7 @@ def workout_trimp(w, reset=False):
|
||||
w.maxhr = maxhr
|
||||
w.save()
|
||||
|
||||
job = myqueue(
|
||||
_ = myqueue(
|
||||
queuehigh,
|
||||
handle_calctrimp,
|
||||
w.id,
|
||||
@@ -3246,7 +3229,7 @@ def workout_rscore(w, reset=False):
|
||||
r.hrftp = int(hrftp)
|
||||
r.save()
|
||||
|
||||
job = myqueue(
|
||||
_ = myqueue(
|
||||
queuehigh,
|
||||
handle_calctrimp,
|
||||
w.id,
|
||||
@@ -3274,7 +3257,7 @@ def workout_normv(w, pp=4.0):
|
||||
r.hrftp = int(hrftp)
|
||||
r.save()
|
||||
|
||||
job = myqueue(
|
||||
_ = myqueue(
|
||||
queuehigh,
|
||||
handle_calctrimp,
|
||||
w.id,
|
||||
|
||||
Reference in New Issue
Block a user