Private
Public Access
1
0

setcp function

This commit is contained in:
Sander Roosendaal
2020-10-16 18:52:05 +02:00
parent 33156ce13c
commit ee4ee05f33

View File

@@ -1026,6 +1026,22 @@ def fetchcp_new(rower,workouts):
data.append(df) data.append(df)
except OSError: except OSError:
# CP data file doesn't exist yet. has to be created # CP data file doesn't exist yet. has to be created
data.append(setcp(workout)[0])
if len(data) == 0:
return pd.Series(),pd.Series(),0
if len(data)>1:
df = pd.concat(data,axis=0)
df = df.groupby(['delta']).max()
df = df.sort_values(['delta']).reset_index()
return df['delta'],df['cp'],0
def setcp(workout):
strokesdf = getsmallrowdata_db(['power','workoutid','time'],ids = [workout.id]) strokesdf = getsmallrowdata_db(['power','workoutid','time'],ids = [workout.id])
if not strokesdf.empty: if not strokesdf.empty:
totaltime = strokesdf['time'].max() totaltime = strokesdf['time'].max()
@@ -1049,20 +1065,10 @@ def fetchcp_new(rower,workouts):
'id':workout.id, 'id':workout.id,
}) })
df.to_parquet(filename,engine='fastparquet',compression='GZIP') df.to_parquet(filename,engine='fastparquet',compression='GZIP')
data.append(df) return df,delta,cpvalues
return pd.DataFrame(),pd.Series(),pd.Series()
if len(data) == 0:
return pd.Series(),pd.Series(),0
if len(data)>1:
df = pd.concat(data,axis=0)
df = df.groupby(['delta']).max()
df = df.sort_values(['delta']).reset_index()
return df['delta'],df['cp'],0
def fetchcp(rower,theworkouts,table='cpdata'): def fetchcp(rower,theworkouts,table='cpdata'):
# get all power data from database (plus workoutid) # get all power data from database (plus workoutid)
@@ -1482,27 +1488,8 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
isbreakthrough = False isbreakthrough = False
ishard = False ishard = False
if workouttype in rowtypes: if workouttype in rowtypes:
df = getsmallrowdata_db(['power', 'workoutid', 'time'], ids=[w.id]) cpdf,delta,cpvalues = setcp(w)
try: if not cpdf.empty:
powermean = df['power'].mean()
except KeyError:
powermean = 0
if powermean != 0:
thesecs = totaltime
maxt = 1.05 * thesecs
if maxt > 0:
logarr = datautils.getlogarr(maxt)
dfgrouped = df.groupby(['workoutid'])
delta, cpvalues, avgpower = datautils.getcp(dfgrouped, logarr)
filename = 'media/cpdata_{id}.parquet.gz'.format(id=w.id)
cpdf = pd.DataFrame({
'delta':delta,
'cp':cpvalues,
'id':w.id,
})
cpdf.to_parquet(filename,engine='fastparquet',compression='GZIP')
if workouttype in otwtypes: if workouttype in otwtypes:
res, btvalues, res2 = utils.isbreakthrough( res, btvalues, res2 = utils.isbreakthrough(
delta, cpvalues, r.p0, r.p1, r.p2, r.p3, r.cpratio) delta, cpvalues, r.p0, r.p1, r.p2, r.p3, r.cpratio)