Merge branch 'develop' into feature/restapi
This commit is contained in:
@@ -8,6 +8,7 @@ from pandas import DataFrame,Series
|
||||
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import itertools
|
||||
|
||||
from django.conf import settings
|
||||
from sqlalchemy import create_engine
|
||||
@@ -84,9 +85,33 @@ def rdata(file,rower=rrower()):
|
||||
|
||||
def getrowdata_db(id=0):
|
||||
data = read_df_sql(id)
|
||||
data['pace'] = data['pace']/1.0e6
|
||||
data['ergpace'] = data['ergpace']/1.0e6
|
||||
data['nowindpace'] = data['nowindpace']/1.0e6
|
||||
data['time'] = data['time']/1.0e6
|
||||
data['x_right'] = data['x_right']/1.0e6
|
||||
if data.empty:
|
||||
rowdata,row = getrowdata(id=id)
|
||||
data = dataprep(rowdata.df,id=id,bands=True,barchart=True,otwpower=True)
|
||||
if rowdata:
|
||||
data = dataprep(rowdata.df,id=id,bands=True,barchart=True,otwpower=True)
|
||||
else:
|
||||
data = pd.DataFrame() # returning empty dataframe
|
||||
else:
|
||||
row = Workout.objects.get(id=id)
|
||||
|
||||
return data,row
|
||||
|
||||
def getsmallrowdata_db(xparam,yparam1,yparam2,ids=[]):
|
||||
if yparam2 == 'None':
|
||||
yparam2 = yparam1
|
||||
prepmultipledata(ids)
|
||||
data = read_cols_df_sql(ids,xparam,yparam1,yparam2)
|
||||
if xparam == 'time':
|
||||
data['time'] = data['time']/1.0e6
|
||||
if yparam1 == 'pace':
|
||||
data['pace'] = data['pace']/1.0e6
|
||||
if yparam2 == 'pace':
|
||||
data['pace'] = data['pace']/1.0e6
|
||||
|
||||
return data
|
||||
|
||||
@@ -110,7 +135,34 @@ def getrowdata(id=0):
|
||||
|
||||
return rowdata,row
|
||||
|
||||
# temporary
|
||||
def prepmultipledata(ids):
|
||||
query = sa.text('SELECT DISTINCT workoutid FROM strokedata')
|
||||
with engine.connect() as conn, conn.begin():
|
||||
res = conn.execute(query)
|
||||
res = list(itertools.chain.from_iterable(res.fetchall()))
|
||||
|
||||
res = list(set(ids)-set(res))
|
||||
|
||||
for id in res:
|
||||
rowdata,row = getrowdata(id=id)
|
||||
if rowdata:
|
||||
data = dataprep(rowdata.df,id=id,bands=True,barchart=True,otwpower=True)
|
||||
return res
|
||||
|
||||
def read_cols_df_sql(ids,col1,col2,col3):
|
||||
columns = list(set((col1,col2,col3,'distance','spm')))
|
||||
cls = ''
|
||||
for column in columns:
|
||||
cls += column+', '
|
||||
cls = cls[:-2]
|
||||
query = sa.text('SELECT {columns} FROM strokedata WHERE workoutid IN {ids}'.format(
|
||||
columns = cls,
|
||||
ids = tuple(ids),
|
||||
))
|
||||
df = pd.read_sql_query(query,engine)
|
||||
return df
|
||||
|
||||
|
||||
def read_df_sql(id):
|
||||
df = pd.read_sql_query(sa.text('SELECT * FROM strokedata WHERE workoutid={id}'.format(
|
||||
id=id)), engine)
|
||||
@@ -118,6 +170,37 @@ def read_df_sql(id):
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def smalldataprep(therows,xparam,yparam1,yparam2):
|
||||
df = pd.DataFrame()
|
||||
if yparam2 == 'None':
|
||||
yparam2 = 'power'
|
||||
df[xparam] = []
|
||||
df[yparam1] = []
|
||||
df[yparam2] = []
|
||||
df['distance'] = []
|
||||
df['spm'] = []
|
||||
for workout in therows:
|
||||
f1 = workout.csvfilename
|
||||
|
||||
try:
|
||||
rowdata = dataprep(rrdata(f1).df)
|
||||
|
||||
rowdata = pd.DataFrame({xparam: rowdata[xparam],
|
||||
yparam1: rowdata[yparam1],
|
||||
yparam2: rowdata[yparam2],
|
||||
'distance': rowdata['distance'],
|
||||
'spm': rowdata['spm'],
|
||||
}
|
||||
)
|
||||
df = pd.concat([df,rowdata],ignore_index=True)
|
||||
except IOError:
|
||||
pass
|
||||
|
||||
return df
|
||||
|
||||
|
||||
def dataprep(rowdatadf,id=0,bands=False,barchart=False,otwpower=False):
|
||||
rowdatadf.set_index([range(len(rowdatadf))],inplace=True)
|
||||
t = rowdatadf.ix[:,'TimeStamp (sec)']
|
||||
@@ -134,8 +217,11 @@ def dataprep(rowdatadf,id=0,bands=False,barchart=False,otwpower=False):
|
||||
power = rowdatadf.ix[:,' Power (watts)']
|
||||
averageforce = rowdatadf.ix[:,' AverageDriveForce (lbs)']
|
||||
drivelength = rowdatadf.ix[:,' DriveLength (meters)']
|
||||
|
||||
|
||||
try:
|
||||
workoutstate = rowdatadf.ix[:,' WorkoutState']
|
||||
except KeyError:
|
||||
workoutstate = 0*hr
|
||||
|
||||
peakforce = rowdatadf.ix[:,' PeakDriveForce (lbs)']
|
||||
|
||||
forceratio = averageforce/peakforce
|
||||
@@ -152,7 +238,10 @@ def dataprep(rowdatadf,id=0,bands=False,barchart=False,otwpower=False):
|
||||
drivelength = savgol_filter(drivelength,windowsize,3)
|
||||
forceratio = savgol_filter(forceratio,windowsize,3)
|
||||
|
||||
t2 = t.fillna(method='ffill').apply(lambda x: timedeltaconv(x))
|
||||
try:
|
||||
t2 = t.fillna(method='ffill').apply(lambda x: timedeltaconv(x))
|
||||
except TypeError:
|
||||
t2 = 0*t
|
||||
|
||||
|
||||
p2 = p.fillna(method='ffill').apply(lambda x: timedeltaconv(x))
|
||||
@@ -179,6 +268,7 @@ def dataprep(rowdatadf,id=0,bands=False,barchart=False,otwpower=False):
|
||||
fpace = nicepaceformat(p2),
|
||||
driveenergy=driveenergy,
|
||||
power=power,
|
||||
workoutstate=workoutstate,
|
||||
averageforce=averageforce,
|
||||
drivelength=drivelength,
|
||||
peakforce=peakforce,
|
||||
|
||||
Reference in New Issue
Block a user