diff --git a/rowers/dataprep.py b/rowers/dataprep.py index da4ca849..22bd7a7b 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -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') diff --git a/rowers/datautils.py b/rowers/datautils.py index 8489af1f..ede1bfd3 100644 --- a/rowers/datautils.py +++ b/rowers/datautils.py @@ -285,26 +285,8 @@ def getcp(dfgrouped,logarr): mask = ww > 2000 ww.loc[mask] = 0 - - tmax = tt.max() - -# if tmax > 3600000: -# newlen = int(tmax/10000.) -# else: -# newlen = len(tt) -# if newlen < len(tt): -# newt = np.arange(newlen)*tmax/float(newlen) -# ww = griddata(tt.values, -# ww.values, -# newt,method='nearest', -# rescale=True) -# -# tt = pd.Series(newt) -# ww = pd.Series(ww) - - try: avgpower[id] = int(ww.mean()) except ValueError: # pragma: no cover diff --git a/rowers/forms.py b/rowers/forms.py index 1ee14629..01039f61 100644 --- a/rowers/forms.py +++ b/rowers/forms.py @@ -58,6 +58,14 @@ class FlexibleDecimalField(forms.DecimalField): value = value.replace('.', '').replace(',', '.') return super(FlexibleDecimalField, self).to_python(value) +class ResampleForm(forms.Form): + resamplechoices = ( + ('overwrite','Overwrite Workout'), + ('copy','Create a Duplicate Workout') + ) + + resamplechoice = forms.ChoiceField(initial='copy',choices=resamplechoices,label='Copy behavior') + class TrainingZonesForm(forms.Form): zoneschoices = ( ('power','Power Zones'), diff --git a/rowers/templates/menu_workout.html b/rowers/templates/menu_workout.html index 16b38908..da4f6a19 100644 --- a/rowers/templates/menu_workout.html +++ b/rowers/templates/menu_workout.html @@ -285,6 +285,12 @@ Explore Raw Data + +
This functionality resamples the data to 1 second intervals. This can be useful in + case there are gaps larger than 30 seconds in the data, which prevent the creation + of a correct CP chart. +
++
+ +