added notification to rowing physics
This commit is contained in:
@@ -36,7 +36,7 @@ import pandas as pd
|
||||
import numpy as np
|
||||
import itertools
|
||||
import math
|
||||
from tasks import handle_sendemail_unrecognized
|
||||
from tasks import handle_sendemail_unrecognized,handle_sendemail_breakthrough
|
||||
|
||||
from django.conf import settings
|
||||
from sqlalchemy import create_engine
|
||||
@@ -44,6 +44,7 @@ import sqlalchemy as sa
|
||||
import sys
|
||||
|
||||
import utils
|
||||
import datautils
|
||||
from utils import lbstoN
|
||||
from scipy.interpolate import griddata
|
||||
|
||||
@@ -140,107 +141,6 @@ def filter_df(datadf,fieldname,value,largerthan=True):
|
||||
|
||||
return datadf
|
||||
|
||||
def getsinglecp(df):
|
||||
thesecs = df['TimeStamp (sec)'].max()-df['TimeStamp (sec)'].min()
|
||||
if thesecs != 0:
|
||||
maxt = 2*thesecs
|
||||
else:
|
||||
maxt = 1000.
|
||||
|
||||
maxlog10 = np.log10(maxt)
|
||||
logarr = np.arange(50)*maxlog10/50.
|
||||
logarr = [int(10.**(la)) for la in logarr]
|
||||
logarr = pd.Series(logarr)
|
||||
logarr.drop_duplicates(keep='first',inplace=True)
|
||||
|
||||
logarr = logarr.values
|
||||
|
||||
|
||||
dfnew = pd.DataFrame({
|
||||
'time':df['TimeStamp (sec)']-df.ix[0,'TimeStamp (sec)'],
|
||||
'power':df[' Power (watts)']
|
||||
})
|
||||
|
||||
dfnew['workoutid'] = 0
|
||||
|
||||
dfgrouped = dfnew.groupby(['workoutid'])
|
||||
delta,cpvalue,avgpower = getcp(dfgrouped,logarr)
|
||||
|
||||
return delta,cpvalue,avgpower
|
||||
|
||||
def getcp(dfgrouped,logarr):
|
||||
delta = []
|
||||
cpvalue = []
|
||||
avgpower = {}
|
||||
#avgpower[0] = 0
|
||||
|
||||
for id,group in dfgrouped:
|
||||
tt = group['time'].copy()
|
||||
ww = group['power'].copy()
|
||||
|
||||
tmax = tt.max()
|
||||
newlen = int(tmax/5000.)
|
||||
if newlen < len(tt):
|
||||
newt = np.arange(newlen)*tmax/float(newlen)
|
||||
ww = griddata(tt.values,
|
||||
ww.values,
|
||||
newt,method='linear',
|
||||
rescale=True)
|
||||
|
||||
tt = pd.Series(newt)
|
||||
ww = pd.Series(ww)
|
||||
|
||||
try:
|
||||
avgpower[id] = int(ww.mean())
|
||||
except ValueError:
|
||||
avgpower[id] = '---'
|
||||
if not np.isnan(ww.mean()):
|
||||
length = len(ww)
|
||||
dt = []
|
||||
cpw = []
|
||||
for i in xrange(length-2):
|
||||
deltat,wmax = getmaxwattinterval(tt,ww,i)
|
||||
if not np.isnan(deltat) and not np.isnan(wmax):
|
||||
dt.append(deltat)
|
||||
cpw.append(wmax)
|
||||
|
||||
|
||||
|
||||
dt = pd.Series(dt)
|
||||
cpw = pd.Series(cpw)
|
||||
if len(dt):
|
||||
|
||||
cpvalues = griddata(dt.values,
|
||||
cpw.values,
|
||||
logarr,method='linear',
|
||||
rescale=True)
|
||||
|
||||
for cpv in cpvalues:
|
||||
cpvalue.append(cpv)
|
||||
for d in logarr:
|
||||
delta.append(d)
|
||||
|
||||
delta = pd.Series(delta,name='Delta')
|
||||
cpvalue = pd.Series(cpvalue,name='CP')
|
||||
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):
|
||||
# time stamps must be in seconds
|
||||
@@ -527,7 +427,7 @@ def save_workout_database(f2,r,dosmooth=True,workouttype='rower',
|
||||
|
||||
isbreakthrough = False
|
||||
if workouttype == 'water':
|
||||
delta,cpvalues,avgpower = getsinglecp(row.df)
|
||||
delta,cpvalues,avgpower = datautils.getsinglecp(row.df)
|
||||
if utils.isbreakthrough(delta,cpvalues,r.p0,r.p1,r.p2,r.p3):
|
||||
isbreakthrough = True
|
||||
|
||||
@@ -689,16 +589,21 @@ def save_workout_database(f2,r,dosmooth=True,workouttype='rower',
|
||||
# submit email task to send email about breakthrough workout
|
||||
if isbreakthrough:
|
||||
a_messages.info(r.user,'It looks like you have a new breakthrough workout')
|
||||
if settings.DEBUG:
|
||||
res = handle_sendemail_breakthrough(w.id,r.user.email,
|
||||
if settings.DEBUG and r.getemailnotifications:
|
||||
res = handle_sendemail_breakthrough.delay(w.id,r.user.email,
|
||||
r.user.first_name,
|
||||
r.user.last_name)
|
||||
elif r.getemailnotifications:
|
||||
try:
|
||||
res = queuehigh.enqueue(
|
||||
handle_sendemail_breakthrough(w.id,
|
||||
r.user.email,
|
||||
r.user.first_name,
|
||||
r.user.last_name))
|
||||
except AttributeError:
|
||||
pass
|
||||
else:
|
||||
res = queuehigh.enqueue(
|
||||
handle_sendemail_breakthrough(w.id,
|
||||
r.user.email,
|
||||
r.user.first_name,
|
||||
r.user.last_name))
|
||||
pass
|
||||
|
||||
if privacy == 'visible':
|
||||
ts = Team.objects.filter(rower=r)
|
||||
|
||||
Reference in New Issue
Block a user