Private
Public Access
1
0

dataprep partially done - continue on line 1400

This commit is contained in:
Sander Roosendaal
2017-09-15 15:31:13 +02:00
parent 89e843bd34
commit 7d6e778625

View File

@@ -1173,16 +1173,25 @@ def getrowdata_db(id=0,doclean=False,convertnewtons=True):
return data,row
# Fetch a subset of the data from the DB
def getsmallrowdata_db(columns,ids=[],doclean=True,workstrokesonly=True,
convertnewtons=False):
def getsmallrowdata_db(columns,ids=[],doclean=True,workstrokesonly=True):
prepmultipledata(ids)
data = read_cols_df_sql(ids,columns)
if convertnewtons:
if 'peakforce' in columns:
data['peakforce'] = data['peakforce']*lbstoN
if 'averageforce' in columns:
data['averageforce'] = data['averageforce']*lbstoN
# convert newtons
if 'peakforce' in columns:
funits = ((w.id,w.forceunit) for Workout.objects.filter(id__in=ids))
for id,u in funits:
if u=='lbs':
mask = data['workoutid']==id
data.loc[mask,'peakforce'] = data.loc[mask,'peakforce']*lbstoN
if 'averageforce' in columns:
funits = ((w.id,w.forceunit) for Workout.objects.filter(id__in=ids))
for id,u in funits:
if u=='lbs':
mask = data['workoutid']==id
data.loc[mask,'averageforce'] = data.loc[mask,'averageforce']*lbstoN
if doclean:
data = clean_df_stats(data,ignorehr=True,
@@ -1284,22 +1293,24 @@ def read_cols_df_sql(ids,columns,convertnewtons=True):
df = df.fillna(value=0)
if convertnewtons:
try:
df['peakforce'] = df['peakforce']*lbstoN
except KeyError:
pass
try:
df['averageforce'] = df['averageforce']*lbstoN
except KeyError:
pass
if 'peakforce' in columns:
funits = ((w.id,w.forceunit) for Workout.objects.filter(id__in=ids))
for id,u in funits:
if u=='lbs':
mask = data['workoutid']==id
df.loc[mask,'peakforce'] = data.loc[mask,'peakforce']*lbstoN
if 'averageforce' in columns:
funits = ((w.id,w.forceunit) for Workout.objects.filter(id__in=ids))
for id,u in funits:
if u=='lbs':
mask = data['workoutid']==id
df.loc[mask,'averageforce'] = data.loc[mask,'averageforce']*lbstoN
engine.dispose()
return df
# 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)
df = pd.read_sql_query(sa.text('SELECT * FROM strokedata WHERE workoutid={id}'.format(
@@ -1307,7 +1318,10 @@ def read_df_sql(id,convertnewtons=True):
engine.dispose()
df = df.fillna(value=0)
if convertnewtons:
funit = Workout.objects.get(id=id).forceunit
if funit=='lbs':
try:
df['peakforce'] = df['peakforce']*lbstoN
except KeyError:
@@ -1322,7 +1336,7 @@ def read_df_sql(id,convertnewtons=True):
# Get the necessary data from the strokedata table in the DB.
# For the flex plot
def smalldataprep(therows,xparam,yparam1,yparam2,convertnewtons=True):
def smalldataprep(therows,xparam,yparam1,yparam2):
df = pd.DataFrame()
if yparam2 == 'None':
yparam2 = 'power'
@@ -1344,6 +1358,17 @@ def smalldataprep(therows,xparam,yparam1,yparam2,convertnewtons=True):
'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)
except IOError:
try:
@@ -1355,20 +1380,20 @@ def smalldataprep(therows,xparam,yparam1,yparam2,convertnewtons=True):
'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)
except IOError:
pass
if convertnewtons:
try:
df['peakforce'] = df['peakforce']*lbstoN
except KeyError:
pass
try:
df['averageforce'] = df['averageforce']*lbstoN
except KeyError:
pass
return df