adding resample function
This commit is contained in:
@@ -547,6 +547,49 @@ def df_resample(datadf):
|
||||
newdf = datadf.groupby(['timestamps']).mean()
|
||||
return newdf
|
||||
|
||||
def resample(id,r,parent,overwrite='copy'):
|
||||
data, row = getrowdata_db(id=id)
|
||||
messages = []
|
||||
|
||||
# resample
|
||||
startdatetime = row.startdatetime
|
||||
data['datetime'] = data['time'].apply(lambda x:startdatetime+datetime.timedelta(seconds=x/1000.))
|
||||
|
||||
data = data.resample('S',on='datetime').mean()
|
||||
data.interpolate(method='linear',inplace=True)
|
||||
data.reset_index(drop=True,inplace=True)
|
||||
|
||||
#data.drop('datetime',inplace=True)
|
||||
data['pace'] = data['pace'] / 1000.
|
||||
data['time'] = data['time'] / 1000.
|
||||
|
||||
if overwrite=='overwrite':
|
||||
# remove CP data
|
||||
try:
|
||||
cpfile = 'media/cpdata_{id}.parquet.gz'.format(id=parent.id)
|
||||
os.remove(cpfile)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
# save
|
||||
data.rename(columns=columndict,inplace=True)
|
||||
|
||||
starttimeunix = arrow.get(startdatetime).timestamp()
|
||||
data[' ElapsedTime (sec)'] = data['TimeStamp (sec)']
|
||||
|
||||
data['TimeStamp (sec)'] = data['TimeStamp (sec)'] + starttimeunix
|
||||
|
||||
row = rrdata(df=data)
|
||||
|
||||
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)
|
||||
else:
|
||||
id, message = new_workout_from_df(r, data, title=parent.name + '(Resampled)',
|
||||
parent=parent,forceunit='N')
|
||||
messages.append(message)
|
||||
|
||||
return data, id, messages
|
||||
|
||||
|
||||
def clean_df_stats(datadf, workstrokesonly=True, ignorehr=True,
|
||||
ignoreadvanced=False):
|
||||
@@ -1239,6 +1282,7 @@ def setcp(workout,background=False,recurrance=True):
|
||||
|
||||
strokesdf = getsmallrowdata_db(['power','workoutid','time'],ids = [workout.id])
|
||||
|
||||
|
||||
try:
|
||||
if strokesdf['power'].std()==0:
|
||||
return pd.DataFrame(),pd.Series(dtype='float'),pd.Series(dtype='float')
|
||||
|
||||
Reference in New Issue
Block a user