data fusion now working ...
This commit is contained in:
@@ -959,35 +959,41 @@ def smalldataprep(therows,xparam,yparam1,yparam2):
|
||||
# data fusion
|
||||
def datafusion(id1,id2,columns,offset):
|
||||
df1,w1 = getrowdata_db(id=id1)
|
||||
df1 = df1.drop(['cumdist',
|
||||
df1 = df1.drop([#'cumdist',
|
||||
'hr_ut2',
|
||||
'hr_ut1',
|
||||
'hr_at',
|
||||
'hr_tr',
|
||||
'hr_an',
|
||||
'hr_max',],
|
||||
'hr_max',
|
||||
'ftime',
|
||||
'fpace',
|
||||
'workoutid',
|
||||
'id'],
|
||||
1,errors='ignore')
|
||||
columns = ['time']+columns
|
||||
df2 = getsmallrowdata_db(columns,ids=[id2],doclean=False)
|
||||
|
||||
print df1['pace'].mean()/1000.,'mies'
|
||||
|
||||
df2 = getsmallrowdata_db(['time']+columns,ids=[id2],doclean=False)
|
||||
offsetmillisecs = offset.seconds*1000+offset.microseconds/1000.
|
||||
offsetmillisecs += offset.days*(3600*24*1000)
|
||||
df2['time'] = df2['time']+offsetmillisecs
|
||||
|
||||
keep1 = {c:c for c in set(df1.columns)}
|
||||
for c in columns:
|
||||
keep1.pop(c)
|
||||
|
||||
|
||||
for c in df1.columns:
|
||||
if not c in keep1:
|
||||
df1 = df1.drop(c,1,errors='ignore')
|
||||
|
||||
df = pd.concat([df1,df2],ignore_index=True)
|
||||
df = df.sort_values(['time'])
|
||||
df = df.interpolate(method='linear',axis=0,limit_direction='both')
|
||||
df = df.interpolate(method='linear',axis=0,limit_direction='both',
|
||||
limit=10)
|
||||
df.fillna(method='bfill',inplace=True)
|
||||
|
||||
df['time'] = df['time']/1000.
|
||||
df['pace'] = df['pace']/1000.
|
||||
print df['pace'].mean(),'noot'
|
||||
df['cum_dist'] = df['cumdist']
|
||||
|
||||
return df
|
||||
|
||||
@@ -1005,7 +1011,6 @@ def dataprep(rowdatadf,id=0,bands=True,barchart=True,otwpower=True,
|
||||
rowdatadf.loc[row_index,' Stroke500mPace (sec/500m)'] = 3000.
|
||||
|
||||
p = rowdatadf.ix[:,' Stroke500mPace (sec/500m)']
|
||||
print p.mean(),'aap'
|
||||
hr = rowdatadf.ix[:,' HRCur (bpm)']
|
||||
spm = rowdatadf.ix[:,' Cadence (stokes/min)']
|
||||
cumdist = rowdatadf.ix[:,'cum_dist']
|
||||
|
||||
@@ -259,7 +259,8 @@ class WorkoutMultipleCompareForm(forms.Form):
|
||||
|
||||
from rowers.interactiveplots import axlabels
|
||||
|
||||
axlabels.pop('None')
|
||||
formaxlabels = axlabels.copy()
|
||||
formaxlabels.pop('None')
|
||||
parchoices = list(sorted(axlabels.items(), key = lambda x:x[1]))
|
||||
|
||||
|
||||
@@ -273,10 +274,16 @@ class ChartParamChoiceForm(forms.Form):
|
||||
plottype = forms.ChoiceField(choices=plotchoices,initial='scatter')
|
||||
teamid = forms.IntegerField(widget=forms.HiddenInput())
|
||||
|
||||
axlabels.pop('time')
|
||||
formaxlabels.pop('time')
|
||||
metricchoices = list(sorted(axlabels.items(), key = lambda x:x[1]))
|
||||
|
||||
class FusionMetricChoiceForm(forms.Form):
|
||||
posneg = (
|
||||
('pos','Workout 2 starts after Workout 1'),
|
||||
('neg','Workout 2 starts before Workout 1'),
|
||||
)
|
||||
columns = forms.MultipleChoiceField(choices=metricchoices,
|
||||
initial=[],
|
||||
widget=forms.CheckboxSelectMultiple())
|
||||
posneg = forms.ChoiceField(choices=posneg,initial='pos')
|
||||
offset = forms.DurationField(label='Time Offset',initial=datetime.timedelta())
|
||||
|
||||
@@ -1291,10 +1291,10 @@ def interactive_flex_chart2(id=0,promember=0,
|
||||
y2means = y1means
|
||||
|
||||
xlabel = Label(x=100,y=130,x_units='screen',y_units='screen',
|
||||
text=axlabels[xparam]+": {x1mean:6.2f}".format(x1mean=x1mean),
|
||||
background_fill_alpha=.7,
|
||||
text_color='green',
|
||||
)
|
||||
text=axlabels[xparam]+": {x1mean:6.2f}".format(x1mean=x1mean),
|
||||
background_fill_alpha=.7,
|
||||
text_color='green',
|
||||
)
|
||||
|
||||
if (xparam != 'time') and (xparam != 'distance') and (xparam != 'cumdist'):
|
||||
plot.add_layout(x1means)
|
||||
@@ -1325,6 +1325,7 @@ def interactive_flex_chart2(id=0,promember=0,
|
||||
|
||||
plot.title.text = row.name
|
||||
plot.title.text_font_size=value("1.0em")
|
||||
|
||||
plot.xaxis.axis_label = axlabels[xparam]
|
||||
plot.yaxis.axis_label = axlabels[yparam1]
|
||||
|
||||
|
||||
@@ -5017,15 +5017,27 @@ def workout_fusion_view(request,id1=0,id2=1):
|
||||
form = FusionMetricChoiceForm(request.POST)
|
||||
if form.is_valid():
|
||||
cd = form.cleaned_data
|
||||
columns = cd['columns']
|
||||
columns = cd['columns']
|
||||
timeoffset = cd['offset']
|
||||
posneg = cd['posneg']
|
||||
if posneg == 'neg':
|
||||
timeoffset = -timeoffset
|
||||
df = dataprep.datafusion(id1,id2,columns,timeoffset)
|
||||
idnew,message = dataprep.new_workout_from_df(r,df,
|
||||
title='Fused data',
|
||||
parent=w1)
|
||||
url = reverse(workout_edit_view,
|
||||
kwargs={
|
||||
'message':message,
|
||||
'id':idnew,
|
||||
parent=w1)
|
||||
if message != None:
|
||||
url = reverse(workout_edit_view,
|
||||
kwargs={
|
||||
'message':message,
|
||||
'id':idnew,
|
||||
})
|
||||
else:
|
||||
successmessage = 'Data fused'
|
||||
url = reverse(workout_edit_view,
|
||||
kwargs={
|
||||
'successmessage':successmessage,
|
||||
'id':idnew,
|
||||
})
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
Reference in New Issue
Block a user