some optimizations
This commit is contained in:
@@ -179,16 +179,16 @@ def getcp(dfgrouped,logarr):
|
|||||||
ww = group['power'].copy()
|
ww = group['power'].copy()
|
||||||
|
|
||||||
tmax = tt.max()
|
tmax = tt.max()
|
||||||
newlen = int(tmax/2000.)
|
newlen = int(tmax/5000.)
|
||||||
print newlen,len(ww)
|
if newlen < len(tt):
|
||||||
newt = np.arange(newlen)*tmax/float(newlen)
|
newt = np.arange(newlen)*tmax/float(newlen)
|
||||||
neww = griddata(tt.values,
|
ww = griddata(tt.values,
|
||||||
ww.values,
|
ww.values,
|
||||||
newt,method='linear',
|
newt,method='linear',
|
||||||
rescale=True)
|
rescale=True)
|
||||||
|
|
||||||
#tt = pd.Series(newt)
|
tt = pd.Series(newt)
|
||||||
#ww = pd.Series(neww)
|
ww = pd.Series(ww)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
avgpower[id] = int(ww.mean())
|
avgpower[id] = int(ww.mean())
|
||||||
@@ -198,41 +198,49 @@ def getcp(dfgrouped,logarr):
|
|||||||
length = len(ww)
|
length = len(ww)
|
||||||
dt = []
|
dt = []
|
||||||
cpw = []
|
cpw = []
|
||||||
for i in range(length-2):
|
for i in xrange(length-2):
|
||||||
w_roll = ww.rolling(i+2).mean().dropna()
|
deltat,wmax = getmaxwattinterval(tt,ww,i)
|
||||||
if len(w_roll):
|
if not np.isnan(deltat) and not np.isnan(wmax):
|
||||||
# now goes with # data points - should be fixed seconds
|
dt.append(deltat)
|
||||||
indexmax = w_roll.idxmax(axis=1)
|
cpw.append(wmax)
|
||||||
try:
|
|
||||||
t_0 = tt.ix[indexmax]
|
|
||||||
t_1 = tt.ix[indexmax-i]
|
|
||||||
deltat = 1.0e-3*(t_0-t_1)
|
|
||||||
wmax = w_roll.ix[indexmax]
|
|
||||||
if not np.isnan(deltat) and not np.isnan(wmax):
|
|
||||||
dt.append(deltat)
|
|
||||||
cpw.append(wmax)
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
dt = pd.Series(dt)
|
dt = pd.Series(dt)
|
||||||
cpw = pd.Series(cpw)
|
cpw = pd.Series(cpw)
|
||||||
|
if len(dt):
|
||||||
|
|
||||||
|
cpvalues = griddata(dt.values,
|
||||||
|
cpw.values,
|
||||||
|
logarr,method='linear',
|
||||||
|
rescale=True)
|
||||||
|
|
||||||
cpvalues = griddata(dt.values,
|
for cpv in cpvalues:
|
||||||
cpw.values,
|
cpvalue.append(cpv)
|
||||||
logarr,method='linear',
|
for d in logarr:
|
||||||
rescale=True)
|
delta.append(d)
|
||||||
|
|
||||||
for cpv in cpvalues:
|
|
||||||
cpvalue.append(cpv)
|
|
||||||
for d in logarr:
|
|
||||||
delta.append(d)
|
|
||||||
|
|
||||||
delta = pd.Series(delta,name='Delta')
|
delta = pd.Series(delta,name='Delta')
|
||||||
cpvalue = pd.Series(cpvalue,name='CP')
|
cpvalue = pd.Series(cpvalue,name='CP')
|
||||||
return delta,cpvalue,avgpower
|
return delta,cpvalue,avgpower
|
||||||
|
|
||||||
|
def getmaxwattinterval(tt,ww,i):
|
||||||
|
w_roll = ww.rolling(i+2).mean().dropna()
|
||||||
|
if len(w_roll):
|
||||||
|
# now goes with # data points - should be fixed seconds
|
||||||
|
indexmax = w_roll.idxmax(axis=1)
|
||||||
|
try:
|
||||||
|
t_0 = tt.ix[indexmax]
|
||||||
|
t_1 = tt.ix[indexmax-i]
|
||||||
|
deltat = 1.0e-3*(t_0-t_1)
|
||||||
|
wmax = w_roll.ix[indexmax]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
wmax = 0
|
||||||
|
deltat = 0
|
||||||
|
|
||||||
|
return deltat,wmax
|
||||||
|
|
||||||
def df_resample(datadf):
|
def df_resample(datadf):
|
||||||
# time stamps must be in seconds
|
# time stamps must be in seconds
|
||||||
|
|||||||
@@ -7409,7 +7409,7 @@ def workout_summary_edit_view(request,id,message="",successmessage=""
|
|||||||
iunits = []
|
iunits = []
|
||||||
itypes = []
|
itypes = []
|
||||||
iresults = []
|
iresults = []
|
||||||
for i in range(nrintervals):
|
for i in xrange(nrintervals):
|
||||||
try:
|
try:
|
||||||
t = datetime.datetime.strptime(request.POST['intervalt_%s' % i],"%H:%M:%S.%f")
|
t = datetime.datetime.strptime(request.POST['intervalt_%s' % i],"%H:%M:%S.%f")
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@@ -7462,7 +7462,7 @@ def workout_summary_edit_view(request,id,message="",successmessage=""
|
|||||||
iunits = []
|
iunits = []
|
||||||
itypes = []
|
itypes = []
|
||||||
iresults = []
|
iresults = []
|
||||||
for i in range(nrintervals):
|
for i in xrange(nrintervals):
|
||||||
t = cd['intervalt_%s' % i]
|
t = cd['intervalt_%s' % i]
|
||||||
timesecs = t.total_seconds()
|
timesecs = t.total_seconds()
|
||||||
itime += [timesecs]
|
itime += [timesecs]
|
||||||
@@ -7496,7 +7496,7 @@ def workout_summary_edit_view(request,id,message="",successmessage=""
|
|||||||
form = SummaryStringForm()
|
form = SummaryStringForm()
|
||||||
|
|
||||||
initial = {}
|
initial = {}
|
||||||
for i in range(nrintervals):
|
for i in xrange(nrintervals):
|
||||||
initial['intervald_%s' % i] = idist[i]
|
initial['intervald_%s' % i] = idist[i]
|
||||||
initial['intervalt_%s' % i] = get_time(itime[i])
|
initial['intervalt_%s' % i] = get_time(itime[i])
|
||||||
initial['type_%s' % i] = itype[i]
|
initial['type_%s' % i] = itype[i]
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ INSTALLED_APPS = [
|
|||||||
'django_rq',
|
'django_rq',
|
||||||
'django_rq_dashboard',
|
'django_rq_dashboard',
|
||||||
'translation_manager',
|
'translation_manager',
|
||||||
# 'debug_toolbar',
|
|
||||||
'django_mailbox',
|
'django_mailbox',
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
'rest_framework_swagger',
|
'rest_framework_swagger',
|
||||||
@@ -90,7 +89,6 @@ MIDDLEWARE_CLASSES = [
|
|||||||
'django.contrib.messages.middleware.MessageMiddleware',
|
'django.contrib.messages.middleware.MessageMiddleware',
|
||||||
'async_messages.middleware.AsyncMiddleware',
|
'async_messages.middleware.AsyncMiddleware',
|
||||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||||
# 'debug_toolbar.middleware.DebugToolbarMiddleware',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
ROOT_URLCONF = 'rowsandall_app.urls'
|
ROOT_URLCONF = 'rowsandall_app.urls'
|
||||||
|
|||||||
@@ -50,6 +50,10 @@ TEMPLATES[0]['OPTIONS']['debug'] = DEBUG
|
|||||||
|
|
||||||
ALLOWED_HOSTS = ['localhost']
|
ALLOWED_HOSTS = ['localhost']
|
||||||
|
|
||||||
|
INSTALLED_APPS += ['debug_toolbar',]
|
||||||
|
|
||||||
|
MIDDLEWARE_CLASSES += ['debug_toolbar.middleware.DebugToolbarMiddleware',]
|
||||||
|
|
||||||
CACHES = {
|
CACHES = {
|
||||||
'default': {
|
'default': {
|
||||||
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
|
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
|
||||||
|
|||||||
Reference in New Issue
Block a user