Merge tag 'v3.53' into develop
hotfix lbstoN
This commit is contained in:
@@ -988,7 +988,7 @@ def testdata(time,distance,pace,spm):
|
|||||||
|
|
||||||
# Get data from DB for one workout (fetches all data). If data
|
# Get data from DB for one workout (fetches all data). If data
|
||||||
# is not in DB, read from CSV file (and create DB entry)
|
# is not in DB, read from CSV file (and create DB entry)
|
||||||
def getrowdata_db(id=0,doclean=False):
|
def getrowdata_db(id=0,doclean=False,convertnewtons=True):
|
||||||
data = read_df_sql(id)
|
data = read_df_sql(id)
|
||||||
data['x_right'] = data['x_right']/1.0e6
|
data['x_right'] = data['x_right']/1.0e6
|
||||||
|
|
||||||
@@ -1034,7 +1034,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):
|
def getrowdata(id=0,convertnewtons=True):
|
||||||
|
|
||||||
# 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)
|
||||||
@@ -1086,7 +1086,7 @@ def prepmultipledata(ids,verbose=False):
|
|||||||
|
|
||||||
# Read a set of columns for a set of workout ids, returns data as a
|
# Read a set of columns for a set of workout ids, returns data as a
|
||||||
# pandas dataframe
|
# pandas dataframe
|
||||||
def read_cols_df_sql(ids,columns):
|
def read_cols_df_sql(ids,columns,convertnewtons=True):
|
||||||
# drop columns that are not in offical list
|
# drop columns that are not in offical list
|
||||||
# axx = [ax[0] for ax in axes]
|
# axx = [ax[0] for ax in axes]
|
||||||
axx = [f.name for f in StrokeData._meta.get_fields()]
|
axx = [f.name for f in StrokeData._meta.get_fields()]
|
||||||
@@ -1124,22 +1124,23 @@ def read_cols_df_sql(ids,columns):
|
|||||||
df = pd.read_sql_query(query,engine)
|
df = pd.read_sql_query(query,engine)
|
||||||
|
|
||||||
df = df.fillna(value=0)
|
df = df.fillna(value=0)
|
||||||
|
|
||||||
try:
|
|
||||||
df['peakforce'] = df['peakforce']*lbstoN
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
if convertnewtons:
|
||||||
df['averageforce'] = df['averageforce']*lbstoN
|
try:
|
||||||
except KeyError:
|
df['peakforce'] = df['peakforce']*lbstoN
|
||||||
pass
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
df['averageforce'] = df['averageforce']*lbstoN
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
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):
|
def read_df_sql(id,convertnewtons=True):
|
||||||
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(
|
||||||
@@ -1147,21 +1148,22 @@ def read_df_sql(id):
|
|||||||
|
|
||||||
engine.dispose()
|
engine.dispose()
|
||||||
df = df.fillna(value=0)
|
df = df.fillna(value=0)
|
||||||
try:
|
if convertnewtons:
|
||||||
df['peakforce'] = df['peakforce']*lbstoN
|
try:
|
||||||
except KeyError:
|
df['peakforce'] = df['peakforce']*lbstoN
|
||||||
pass
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
df['averageforce'] = df['averageforce']*lbstoN
|
df['averageforce'] = df['averageforce']*lbstoN
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return df
|
return df
|
||||||
|
|
||||||
# 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):
|
def smalldataprep(therows,xparam,yparam1,yparam2,convertnewtons=True):
|
||||||
df = pd.DataFrame()
|
df = pd.DataFrame()
|
||||||
if yparam2 == 'None':
|
if yparam2 == 'None':
|
||||||
yparam2 = 'power'
|
yparam2 = 'power'
|
||||||
@@ -1198,15 +1200,16 @@ def smalldataprep(therows,xparam,yparam1,yparam2):
|
|||||||
except IOError:
|
except IOError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
if convertnewtons:
|
||||||
df['peakforce'] = df['peakforce']*lbstoN
|
try:
|
||||||
except KeyError:
|
df['peakforce'] = df['peakforce']*lbstoN
|
||||||
pass
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
df['averageforce'] = df['averageforce']*lbstoN
|
df['averageforce'] = df['averageforce']*lbstoN
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return df
|
return df
|
||||||
|
|
||||||
@@ -1266,8 +1269,23 @@ def datafusion(id1,id2,columns,offset):
|
|||||||
|
|
||||||
return df
|
return df
|
||||||
|
|
||||||
|
def fix_newtons(id=0):
|
||||||
|
# rowdata,row = getrowdata_db(id=id,doclean=False,convertnewtons=False)
|
||||||
|
rowdata = getsmallrowdata_db(['peakforce'],ids=[id],doclean=False)
|
||||||
|
try:
|
||||||
|
avgforce = rowdata['averageforce']
|
||||||
|
peakforce = rowdata['peakforce']
|
||||||
|
if peakforce.mean() > 3000:
|
||||||
|
w = Workout.objects.get(id=id)
|
||||||
|
print "fixing ",id
|
||||||
|
rowdata = rdata(w.csvfilename)
|
||||||
|
if rowdata and len(rowdata.df):
|
||||||
|
update_strokedata(w.id,rowdata.df)
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
def add_efficiency(id=0):
|
def add_efficiency(id=0):
|
||||||
rowdata,row = getrowdata_db(id=id,doclean=False)
|
rowdata,row = getrowdata_db(id=id,doclean=False,convertnewtons=False)
|
||||||
power = rowdata['power']
|
power = rowdata['power']
|
||||||
pace = rowdata['pace']/1.0e3
|
pace = rowdata['pace']/1.0e3
|
||||||
velo = 500./pace
|
velo = 500./pace
|
||||||
|
|||||||
Reference in New Issue
Block a user