dataprep partially done - continue on line 1400
This commit is contained in:
@@ -1173,16 +1173,25 @@ def getrowdata_db(id=0,doclean=False,convertnewtons=True):
|
|||||||
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 'peakforce' in columns:
|
||||||
if 'averageforce' in columns:
|
funits = ((w.id,w.forceunit) for Workout.objects.filter(id__in=ids))
|
||||||
data['averageforce'] = data['averageforce']*lbstoN
|
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:
|
if doclean:
|
||||||
data = clean_df_stats(data,ignorehr=True,
|
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)
|
df = df.fillna(value=0)
|
||||||
|
|
||||||
if convertnewtons:
|
if 'peakforce' in columns:
|
||||||
try:
|
funits = ((w.id,w.forceunit) for Workout.objects.filter(id__in=ids))
|
||||||
df['peakforce'] = df['peakforce']*lbstoN
|
for id,u in funits:
|
||||||
except KeyError:
|
if u=='lbs':
|
||||||
pass
|
mask = data['workoutid']==id
|
||||||
|
df.loc[mask,'peakforce'] = data.loc[mask,'peakforce']*lbstoN
|
||||||
try:
|
if 'averageforce' in columns:
|
||||||
df['averageforce'] = df['averageforce']*lbstoN
|
funits = ((w.id,w.forceunit) for Workout.objects.filter(id__in=ids))
|
||||||
except KeyError:
|
for id,u in funits:
|
||||||
pass
|
if u=='lbs':
|
||||||
|
mask = data['workoutid']==id
|
||||||
|
df.loc[mask,'averageforce'] = data.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 +1318,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 +1336,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 +1358,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,20 +1380,20 @@ 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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user