diff --git a/rowers/dataprep.py b/rowers/dataprep.py index 0059162f..a68e288e 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -428,7 +428,8 @@ def save_workout_database(f2,r,dosmooth=True,workouttype='rower', isbreakthrough = False if workouttype == 'water': delta,cpvalues,avgpower = datautils.getsinglecp(row.df) - if utils.isbreakthrough(delta,cpvalues,r.p0,r.p1,r.p2,r.p3,r.cpratio): + res,btvalues = utils.isbreakthrough(delta,cpvalues,r.p0,r.p1,r.p2,r.p3,r.cpratio) + if res: isbreakthrough = True res = datautils.updatecp(delta,cpvalues,r) @@ -595,14 +596,16 @@ def save_workout_database(f2,r,dosmooth=True,workouttype='rower', if settings.DEBUG and r.getemailnotifications: res = handle_sendemail_breakthrough.delay(w.id,r.user.email, r.user.first_name, - r.user.last_name) + r.user.last_name, + btvalues=btvalues.to_json()) elif r.getemailnotifications: try: res = queuehigh.enqueue( handle_sendemail_breakthrough(w.id, r.user.email, r.user.first_name, - r.user.last_name)) + r.user.last_name, + btvalues=btvalues.to_json())) except AttributeError: pass else: diff --git a/rowers/datautils.py b/rowers/datautils.py index ca4cbff1..8cdde524 100644 --- a/rowers/datautils.py +++ b/rowers/datautils.py @@ -77,8 +77,8 @@ def cpfit(powerdf): def getlogarr(maxt): maxlog10 = np.log10(maxt-5) - logarr = np.log10(5.)+np.arange(50)*maxlog10/50. - logarr = [int(10.**(la)) for la in logarr] + logarr = np.arange(50)*maxlog10/50. + logarr = [5+int(10.**(la)) for la in logarr] logarr = pd.Series(logarr) logarr.drop_duplicates(keep='first',inplace=True) @@ -88,7 +88,7 @@ def getlogarr(maxt): def getsinglecp(df): thesecs = df['TimeStamp (sec)'].max()-df['TimeStamp (sec)'].min() if thesecs != 0: - maxt = 2*thesecs + maxt = 1.05*thesecs else: maxt = 1000. @@ -152,7 +152,6 @@ def getcp(dfgrouped,logarr): dt = pd.Series(dt) cpw = pd.Series(cpw) if len(dt): - cpvalues = griddata(dt.values, cpw.values, logarr,method='linear', diff --git a/rowers/tasks.py b/rowers/tasks.py index 50277880..9b98a4e8 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -52,7 +52,7 @@ def handle_new_workout_from_file(r,f2, @app.task def handle_sendemail_breakthrough(workoutid,useremail, userfirstname,userlastname, - btvalues = pd.DataFrame()): + btvalues = pd.DataFrame().to_json()): # send email with attachment subject = "A breakthrough workout on rowsandall.com" @@ -63,7 +63,7 @@ def handle_sendemail_breakthrough(workoutid,useremail, message += " Critical Power (CP) is the power that you can " message += "sustain for a given duration. For more, see this " message += " article in the analytics blog:\n\n" - message += " [link to article to be written]\n\n" + message += " http://analytics.rowsandall.com/2017/06/17/how-do-we-calculate-critical-power/ \n\n" message += "Link to the workout http://rowsandall.com/rowers/workout/" message += str(workoutid) message +="/edit\n\n" @@ -72,6 +72,9 @@ def handle_sendemail_breakthrough(workoutid,useremail, message += str(workoutid) message += "/updatecp\n\n" + btvalues = pd.read_json(btvalues) + btvalues.sort_values('delta',axis=0,inplace=True) + if not btvalues.empty: message += "These were the breakthrough values:\n" for t in btvalues.itertuples(): @@ -79,9 +82,15 @@ def handle_sendemail_breakthrough(workoutid,useremail, cpvalue = t.cpvalues pwr = t.pwr - message += "Time: "+str(delta)+" seconds\n" - message += "New: "+str(cpvalue)+" Watt\n" - message += "Old: "+str(pwr)+" Watt\n\n" + message += "Time: {delta} seconds\n".format( + delta=delta + ) + message += "New: {cpvalue:.0f} Watt\n".format( + cpvalue=cpvalue + ) + message += "Old: {pwr:.0f} Watt\n\n".format( + pwr=pwr + ) message += "To opt out of these email notifications, deselect the checkbox on your Profile page under Account Information.\n\n" @@ -237,11 +246,11 @@ def handle_otwsetpower(f1,boattype,weightvalue, update_strokedata(workoutid,rowdata.df,debug=debug) delta,cpvalues,avgpower = datautils.getsinglecp(rowdata.df) - res,deltas = utils.isbreakthrough(delta,cpvalues,ps[0],ps[1],ps[2],ps[3],ratio) + res,btvalues = utils.isbreakthrough(delta,cpvalues,ps[0],ps[1],ps[2],ps[3],ratio) if res: handle_sendemail_breakthrough(workoutid,email, first_name, - last_name,deltas) + last_name,btvalues=btvalues.to_json()) # send email fullemail = first_name + " " + last_name + " " + "<" + email + ">" diff --git a/rowers/utils.py b/rowers/utils.py index 5036dac2..6e788b7c 100644 --- a/rowers/utils.py +++ b/rowers/utils.py @@ -77,7 +77,6 @@ def geo_distance(lat1,lon1,lat2,lon2): def isbreakthrough(delta,cpvalues,p0,p1,p2,p3,ratio): - pwr = p0/(1+delta/p2) pwr += p1/(1+delta/p3) @@ -92,4 +91,8 @@ def isbreakthrough(delta,cpvalues,p0,p1,p2,p3,ratio): 'pwr':pwr[cpvalues>pwr], } ) + + btdf.sort_values('delta',axis=0,inplace=True) + + return res>1,btdf diff --git a/rowsanda_107501 b/rowsanda_107501 index f2be9658..c0aaa646 100644 Binary files a/rowsanda_107501 and b/rowsanda_107501 differ