Private
Public Access
1
0

Merge branch 'release/v3.77'

This commit is contained in:
Sander Roosendaal
2017-09-19 09:46:39 +02:00
6 changed files with 89 additions and 54 deletions
+62 -40
View File
@@ -433,6 +433,7 @@ def save_workout_database(f2,r,dosmooth=True,workouttype='rower',
summary='', summary='',
makeprivate=False, makeprivate=False,
oarlength=2.89,inboard=0.88, oarlength=2.89,inboard=0.88,
forceunit='lbs',
consistencychecks=False): consistencychecks=False):
message = None message = None
powerperc = 100*np.array([r.pw_ut2, powerperc = 100*np.array([r.pw_ut2,
@@ -447,7 +448,6 @@ def save_workout_database(f2,r,dosmooth=True,workouttype='rower',
powerperc=powerperc,powerzones=r.powerzones) powerperc=powerperc,powerzones=r.powerzones)
row = rdata(f2,rower=rr) row = rdata(f2,rower=rr)
dtavg = row.df['TimeStamp (sec)'].diff().mean() dtavg = row.df['TimeStamp (sec)'].diff().mean()
if dtavg < 1: if dtavg < 1:
@@ -640,6 +640,7 @@ def save_workout_database(f2,r,dosmooth=True,workouttype='rower',
weightcategory=r.weightcategory, weightcategory=r.weightcategory,
starttime=workoutstarttime, starttime=workoutstarttime,
workoutsource=workoutsource, workoutsource=workoutsource,
forceunit=forceunit,
csvfilename=f2,notes=notes,summary=summary, csvfilename=f2,notes=notes,summary=summary,
maxhr=maxhr,averagehr=averagehr, maxhr=maxhr,averagehr=averagehr,
startdatetime=workoutstartdatetime, startdatetime=workoutstartdatetime,
@@ -925,7 +926,8 @@ def split_workout(r,parent,splitsecond,splitmode):
id,message = new_workout_from_df(r,data1, id,message = new_workout_from_df(r,data1,
title=parent.name+' (1)', title=parent.name+' (1)',
parent=parent, parent=parent,
setprivate=setprivate) setprivate=setprivate,
forceunit='N')
messages.append(message) messages.append(message)
ids.append(id) ids.append(id)
if 'keep second' in splitmode: if 'keep second' in splitmode:
@@ -943,7 +945,7 @@ def split_workout(r,parent,splitsecond,splitmode):
title=parent.name+' (2)', title=parent.name+' (2)',
parent=parent, parent=parent,
setprivate=setprivate, setprivate=setprivate,
dt=dt) dt=dt,forceunit='N')
messages.append(message) messages.append(message)
ids.append(id) ids.append(id)
@@ -968,6 +970,7 @@ def new_workout_from_df(r,df,
title='New Workout', title='New Workout',
parent=None, parent=None,
setprivate=False, setprivate=False,
forceunit='lbs',
dt=datetime.timedelta()): dt=datetime.timedelta()):
message = None message = None
@@ -1001,7 +1004,10 @@ def new_workout_from_df(r,df,
timestr = strftime("%Y%m%d-%H%M%S") timestr = strftime("%Y%m%d-%H%M%S")
csvfilename ='media/df_'+timestr+'.csv' csvfilename ='media/df_'+timestr+'.csv'
if forceunit == 'N':
# change to lbs for now
df['peakforce'] /= lbstoN
df['averageforce'] /= lbstoN
df.rename(columns = columndict,inplace=True) df.rename(columns = columndict,inplace=True)
@@ -1166,23 +1172,17 @@ def getrowdata_db(id=0,doclean=False,convertnewtons=True):
if doclean: if doclean:
data = clean_df_stats(data,ignorehr=True) data = clean_df_stats(data,ignorehr=True)
# these two lines seem redundant ??
#data['averageforce'] = data['averageforce']
#data['peakforce'] = data['peakforce']
return data,row return data,row
# Fetch a subset of the data from the DB # Fetch a subset of the data from the DB
def getsmallrowdata_db(columns,ids=[],doclean=True,workstrokesonly=True, def getsmallrowdata_db(columns,ids=[],doclean=True,workstrokesonly=True):
convertnewtons=False):
prepmultipledata(ids) prepmultipledata(ids)
data = read_cols_df_sql(ids,columns) data = read_cols_df_sql(ids,columns)
if convertnewtons: # convert newtons
if 'peakforce' in columns:
data['peakforce'] = data['peakforce']*lbstoN
if 'averageforce' in columns:
data['averageforce'] = data['averageforce']*lbstoN
if doclean: if doclean:
data = clean_df_stats(data,ignorehr=True, data = clean_df_stats(data,ignorehr=True,
@@ -1193,7 +1193,7 @@ def getsmallrowdata_db(columns,ids=[],doclean=True,workstrokesonly=True,
return data return data
# Fetch both the workout and the workout stroke data (from CSV file) # Fetch both the workout and the workout stroke data (from CSV file)
def getrowdata(id=0,convertnewtons=True): def getrowdata(id=0):
# check if valid ID exists (workout exists) # check if valid ID exists (workout exists)
row = Workout.objects.get(id=id) row = Workout.objects.get(id=id)
@@ -1254,7 +1254,7 @@ def read_cols_df_sql(ids,columns,convertnewtons=True):
if not c in axx: if not c in axx:
columns.remove(c) columns.remove(c)
columns = list(columns)+['distance','spm'] columns = list(columns)+['distance','spm','workoutid']
columns = [x for x in columns if x != 'None'] columns = [x for x in columns if x != 'None']
columns = list(set(columns)) columns = list(set(columns))
cls = '' cls = ''
@@ -1284,22 +1284,24 @@ def read_cols_df_sql(ids,columns,convertnewtons=True):
df = df.fillna(value=0) df = df.fillna(value=0)
if convertnewtons: if 'peakforce' in columns:
try: funits = ((w.id,w.forceunit) for w in Workout.objects.filter(id__in=ids))
df['peakforce'] = df['peakforce']*lbstoN for id,u in funits:
except KeyError: if u=='lbs':
pass mask = df['workoutid']==id
df.loc[mask,'peakforce'] = df.loc[mask,'peakforce']*lbstoN
try: if 'averageforce' in columns:
df['averageforce'] = df['averageforce']*lbstoN funits = ((w.id,w.forceunit) for w in Workout.objects.filter(id__in=ids))
except KeyError: for id,u in funits:
pass if u=='lbs':
mask = df['workoutid']==id
df.loc[mask,'averageforce'] = df.loc[mask,'averageforce']*lbstoN
engine.dispose() engine.dispose()
return df return df
# Read stroke data from the DB for a Workout ID. Returns a pandas dataframe # Read stroke data from the DB for a Workout ID. Returns a pandas dataframe
def read_df_sql(id,convertnewtons=True): def read_df_sql(id):
engine = create_engine(database_url, echo=False) engine = create_engine(database_url, echo=False)
df = pd.read_sql_query(sa.text('SELECT * FROM strokedata WHERE workoutid={id}'.format( df = pd.read_sql_query(sa.text('SELECT * FROM strokedata WHERE workoutid={id}'.format(
@@ -1307,7 +1309,10 @@ def read_df_sql(id,convertnewtons=True):
engine.dispose() engine.dispose()
df = df.fillna(value=0) df = df.fillna(value=0)
if convertnewtons:
funit = Workout.objects.get(id=id).forceunit
if funit=='lbs':
try: try:
df['peakforce'] = df['peakforce']*lbstoN df['peakforce'] = df['peakforce']*lbstoN
except KeyError: except KeyError:
@@ -1322,7 +1327,7 @@ def read_df_sql(id,convertnewtons=True):
# Get the necessary data from the strokedata table in the DB. # Get the necessary data from the strokedata table in the DB.
# For the flex plot # For the flex plot
def smalldataprep(therows,xparam,yparam1,yparam2,convertnewtons=True): def smalldataprep(therows,xparam,yparam1,yparam2):
df = pd.DataFrame() df = pd.DataFrame()
if yparam2 == 'None': if yparam2 == 'None':
yparam2 = 'power' yparam2 = 'power'
@@ -1344,6 +1349,17 @@ def smalldataprep(therows,xparam,yparam1,yparam2,convertnewtons=True):
'spm': rowdata['spm'], 'spm': rowdata['spm'],
} }
) )
if workout.forceunit == 'lbs':
try:
rowdata['peakforce'] *= lbstoN
except KeyError:
pass
try:
rowdata['averageforce'] *= lbstoN
except KeyError:
pass
df = pd.concat([df,rowdata],ignore_index=True) df = pd.concat([df,rowdata],ignore_index=True)
except IOError: except IOError:
try: try:
@@ -1355,25 +1371,28 @@ def smalldataprep(therows,xparam,yparam1,yparam2,convertnewtons=True):
'spm': rowdata['spm'], 'spm': rowdata['spm'],
} }
) )
if workout.forceunit == 'lbs':
try:
rowdata['peakforce'] *= lbstoN
except KeyError:
pass
try:
rowdata['averageforce'] *= lbstoN
except KeyError:
pass
df = pd.concat([df,rowdata],ignore_index=True) df = pd.concat([df,rowdata],ignore_index=True)
except IOError: except IOError:
pass pass
if convertnewtons:
try:
df['peakforce'] = df['peakforce']*lbstoN
except KeyError:
pass
try:
df['averageforce'] = df['averageforce']*lbstoN
except KeyError:
pass
return df return df
# data fusion # data fusion
def datafusion(id1,id2,columns,offset): def datafusion(id1,id2,columns,offset):
workout1 = Workout.objects.get(id=id1)
workout2 = Workout.objects.get(id=id2)
df1,w1 = getrowdata_db(id=id1) df1,w1 = getrowdata_db(id=id1)
df1 = df1.drop([#'cumdist', df1 = df1.drop([#'cumdist',
'hr_ut2', 'hr_ut2',
@@ -1396,6 +1415,9 @@ def datafusion(id1,id2,columns,offset):
df2 = getsmallrowdata_db(['time']+columns,ids=[id2],doclean=False) df2 = getsmallrowdata_db(['time']+columns,ids=[id2],doclean=False)
forceunit = 'N'
offsetmillisecs = offset.seconds*1000+offset.microseconds/1000. offsetmillisecs = offset.seconds*1000+offset.microseconds/1000.
offsetmillisecs += offset.days*(3600*24*1000) offsetmillisecs += offset.days*(3600*24*1000)
df2['time'] = df2['time']+offsetmillisecs df2['time'] = df2['time']+offsetmillisecs
@@ -1426,7 +1448,7 @@ def datafusion(id1,id2,columns,offset):
df['pace'] = df['pace']/1000. df['pace'] = df['pace']/1000.
df['cum_dist'] = df['cumdist'] df['cum_dist'] = df['cumdist']
return df return df,forceunit
def fix_newtons(id=0,limit=3000): def fix_newtons(id=0,limit=3000):
# rowdata,row = getrowdata_db(id=id,doclean=False,convertnewtons=False) # rowdata,row = getrowdata_db(id=id,doclean=False,convertnewtons=False)
+2 -1
View File
@@ -88,6 +88,7 @@ def processattachments():
wid = [make_new_workout_from_email(rr,a.document,name)] wid = [make_new_workout_from_email(rr,a.document,name)]
res += wid res += wid
link = 'https://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit' link = 'https://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit'
if wid != 1:
dd = send_confirm(u,name,link) dd = send_confirm(u,name,link)
except: except:
# replace with code to process error # replace with code to process error
@@ -138,8 +139,8 @@ def processattachments_debug():
print name print name
wid = [make_new_workout_from_email(rr,a.document,name)] wid = [make_new_workout_from_email(rr,a.document,name)]
res += wid res += wid
print wid
link = 'https://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit' link = 'https://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit'
if wid != 1:
dd = send_confirm(u,name,link) dd = send_confirm(u,name,link)
@@ -70,11 +70,13 @@ class Command(BaseCommand):
res += wid res += wid
link = 'http://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit' link = 'http://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit'
try: try:
if wid != 1:
dd = send_confirm(rr.user,title,link) dd = send_confirm(rr.user,title,link)
time.sleep(10) time.sleep(10)
except: except:
try: try:
time.sleep(10) time.sleep(10)
if wid != 1:
dd = send_confirm(rr.user,title,link) dd = send_confirm(rr.user,title,link)
except: except:
pass pass
@@ -94,7 +96,9 @@ class Command(BaseCommand):
# replace with code to process error # replace with code to process error
res += ['fail: '+name] res += ['fail: '+name]
donotdelete = 1 donotdelete = 1
wid = 1
try: try:
if wid != 1:
dd = send_confirm(rr.user,name,link) dd = send_confirm(rr.user,name,link)
time.sleep(10) time.sleep(10)
except: except:
+6
View File
@@ -429,6 +429,12 @@ class Workout(models.Model):
uploadedtounderarmour = models.IntegerField(default=0) uploadedtounderarmour = models.IntegerField(default=0)
uploadedtotp = models.IntegerField(default=0) uploadedtotp = models.IntegerField(default=0)
uploadedtorunkeeper = models.IntegerField(default=0) uploadedtorunkeeper = models.IntegerField(default=0)
forceunit = models.CharField(default='lbs',
choices = (
('lbs','lbs'),
('N','N')
),
max_length=100)
# empower stuff # empower stuff
inboard = models.FloatField(default=0.88) inboard = models.FloatField(default=0.88)
+4 -2
View File
@@ -8393,11 +8393,13 @@ def workout_fusion_view(request,id1=0,id2=1):
timeoffset = -timeoffset timeoffset = -timeoffset
# Create DataFrame # Create DataFrame
df = dataprep.datafusion(id1,id2,columns,timeoffset) df,forceunit = dataprep.datafusion(id1,id2,columns,timeoffset)
idnew,message = dataprep.new_workout_from_df(r,df, idnew,message = dataprep.new_workout_from_df(r,df,
title='Fused data', title='Fused data',
parent=w1) parent=w1,
forceunit=forceunit)
if message != None: if message != None:
messages.error(request,message) messages.error(request,message)
else: else:
+1 -1
View File
@@ -176,7 +176,7 @@ AUTH_PASSWORD_VALIDATORS = [
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/ # https://docs.djangoproject.com/en/1.9/topics/i18n/
#TIME_ZONE = 'UTC' TIME_ZONE = 'UTC'
USE_I18N = True USE_I18N = True