sort of gets CP data
This commit is contained in:
@@ -1016,6 +1016,68 @@ def fetchcperg(rower,theworkouts):
|
||||
|
||||
return cpdf
|
||||
|
||||
def fetchcp_new(rower,workouts):
|
||||
|
||||
data = []
|
||||
for workout in workouts:
|
||||
cpfile = 'media/cpdata_{id}.parquet.gz'.format(id=workout.id)
|
||||
try:
|
||||
df = pd.read_parquet(cpfile)
|
||||
data.append(df)
|
||||
except OSError:
|
||||
# CP data file doesn't exist yet. has to be created
|
||||
strokesdf = getsmallrowdata_db(['power','workoutid','time'],ids = [workout.id])
|
||||
if not strokesdf.empty:
|
||||
totaltime = strokesdf['time'].max()
|
||||
try:
|
||||
powermean = strokesdf['power'].mean()
|
||||
except KeyError:
|
||||
powermean = 0
|
||||
|
||||
|
||||
if powermean != 0:
|
||||
thesecs = totaltime
|
||||
maxt = 1.05 * thesecs
|
||||
if maxt > 0:
|
||||
logarr = datautils.getlogarr(maxt)
|
||||
dfgrouped = strokesdf.groupby(['workoutid'])
|
||||
delta, cpvalues, avgpower = datautils.getcp(dfgrouped, logarr)
|
||||
filename = 'media/cpdata_{id}.parquet.gz'.format(id=workout.id)
|
||||
df = pd.DataFrame({
|
||||
'delta':delta,
|
||||
'cp':cpvalues,
|
||||
'id':workout.id,
|
||||
})
|
||||
df.to_parquet(filename,engine='fastparquet',compression='GZIP')
|
||||
data.append(df)
|
||||
|
||||
|
||||
if len(data)>1:
|
||||
df = pd.concat(data,axis=0)
|
||||
|
||||
df = df.groupby(['delta']).max()
|
||||
|
||||
|
||||
df = df.sort_values(['delta']).reset_index()
|
||||
dindex = df['id'].shift(1)-df['id']
|
||||
dpowerplus = df['cp'].shift(1)-df['cp']
|
||||
dpowermin = df['cp'].shift(-1)-df['cp']
|
||||
badrows = []
|
||||
badid = 0
|
||||
for index,row in df.iterrows():
|
||||
if dindex[index] != 0 and dpowermin[index] > 0:
|
||||
badrows.append(index)
|
||||
badid = row['id']
|
||||
elif row['id'] == badid:
|
||||
badrows.append(index)
|
||||
else:
|
||||
badid = 0
|
||||
|
||||
|
||||
df = df.drop(index = badrows)
|
||||
|
||||
|
||||
return df['delta'],df['cp'],0
|
||||
|
||||
def fetchcp(rower,theworkouts,table='cpdata'):
|
||||
# get all power data from database (plus workoutid)
|
||||
@@ -1449,7 +1511,12 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
|
||||
dfgrouped = df.groupby(['workoutid'])
|
||||
delta, cpvalues, avgpower = datautils.getcp(dfgrouped, logarr)
|
||||
filename = 'media/cpdata_{id}.parquet.gz'.format(id=w.id)
|
||||
df.to_parquet(filename,engine='fastparquet',compression='GZIP')
|
||||
cpdf = pd.DataFrame({
|
||||
'delta':delta,
|
||||
'cp':cpvalues,
|
||||
'id':w.id,
|
||||
})
|
||||
cpdf.to_parquet(filename,engine='fastparquet',compression='GZIP')
|
||||
|
||||
if workouttype in otwtypes:
|
||||
res, btvalues, res2 = utils.isbreakthrough(
|
||||
|
||||
Reference in New Issue
Block a user