Private
Public Access
1
0

Merge branch 'feature/betterbreaktrhoughs' into develop

This commit is contained in:
Sander Roosendaal
2017-10-10 14:52:29 +02:00
5 changed files with 71 additions and 8 deletions

View File

@@ -38,7 +38,10 @@ import pandas as pd
import numpy as np
import itertools
import math
from tasks import handle_sendemail_unrecognized,handle_sendemail_breakthrough
from tasks import (
handle_sendemail_unrecognized,handle_sendemail_breakthrough,
handle_sendemail_hard
)
from django.conf import settings
from sqlalchemy import create_engine
@@ -654,6 +657,7 @@ def save_workout_database(f2,r,dosmooth=True,workouttype='rower',
w.save()
isbreakthrough = False
ishard = False
if workouttype == 'water':
df = getsmallrowdata_db(['power','workoutid','time'],ids=[w.id])
# delta,cpvalues,avgpower = datautils.getsinglecp(row.df)
@@ -664,12 +668,15 @@ def save_workout_database(f2,r,dosmooth=True,workouttype='rower',
dfgrouped = df.groupby(['workoutid'])
delta,cpvalues,avgpower = datautils.getcp(dfgrouped,logarr)
res,btvalues = utils.isbreakthrough(delta,cpvalues,r.p0,r.p1,r.p2,r.p3,r.cpratio)
res,btvalues,res2 = utils.isbreakthrough(delta,cpvalues,r.p0,r.p1,r.p2,r.p3,r.cpratio)
else:
res = 0
res2 = 0
if res:
isbreakthrough = True
res = datautils.updatecp(delta,cpvalues,r)
if res2 and not isbreakthrough:
ishard = True
# submit email task to send email about breakthrough workout
if isbreakthrough:
@@ -691,6 +698,26 @@ def save_workout_database(f2,r,dosmooth=True,workouttype='rower',
pass
else:
pass
# submit email task to send email about breakthrough workout
if ishard:
a_messages.info(r.user,'That was a pretty hard workout')
if settings.DEBUG and r.getemailnotifications:
res = handle_sendemail_hard.delay(w.id,r.user.email,
r.user.first_name,
r.user.last_name,
btvalues=btvalues.to_json())
elif r.getemailnotifications:
try:
res = queuehigh.enqueue(
handle_sendemail_hard(w.id,
r.user.email,
r.user.first_name,
r.user.last_name,
btvalues=btvalues.to_json()))
except AttributeError:
pass
else:
pass
if privacy == 'visible':
ts = Team.objects.filter(rower=r)

View File

@@ -139,6 +139,40 @@ def handle_sendemail_breakthrough(workoutid,useremail,
# remove tcx file
return 1
# send email when a breakthrough workout is uploaded
@app.task
def handle_sendemail_hard(workoutid,useremail,
userfirstname,userlastname,
btvalues = pd.DataFrame().to_json()):
# send email with attachment
subject = "That was a pretty hard workout on rowsandall.com"
message = "Dear "+userfirstname+",\n"
message += "Congratulations! Your recent workout has been analyzed"
message += " by Rowsandall.com and it appears that it was pretty hard work."
message += " You were working pretty close to your Critical Power\n\n"
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 += " 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"
message += "To opt out of these email notifications, deselect the checkbox on your Profile page under Account Information.\n\n"
message += "Best Regards, the Rowsandall Team"
email = EmailMessage(subject, message,
'Rowsandall <info@rowsandall.com>',
[useremail])
res = email.send()
# remove tcx file
return 1
# send email to me when an unrecognized file is uploaded
@app.task

View File

@@ -10,9 +10,7 @@
{{ workout.date }} - {{ workout.distance }}m - {{ workout.duration |durationprint:"%H:%M:%S.%f" }}{% endblock %}
{% block og_image %}
<meta property="og:image" content="http://rowsandall.com/{{ graph.filename |spacetohtml }}" />
<meta property="og:image:width" content="{{ graph.width }}" />
<meta property="og:image:height" content="{{ graph.height }}" />
<meta property="og:image:secure_url" content="https://rowsandall.com/{{ graph.filename |spacetohtml }}" />
<meta property="og:image:secure_url" content="https://rowsandall.com/{{ graph.filename |spacetohtml }}" />
<meta property="og:image:width" content="{{ graph.width }}" />
<meta property="og:image:height" content="{{ graph.height }}" />
{% endblock %}

View File

@@ -15,8 +15,6 @@
{% if graphs1 %}
{% for graph in graphs1 %}
<meta property="og:image" content="http://rowsandall.com/{{ graph.filename |spacetohtml }}" />
<meta property="og:image:width" content="{{ graph.width }}" />
<meta property="og:image:height" content="{{ graph.height }}" />
<meta property="og:image:secure_url" content="https://rowsandall.com/{{ graph.filename |spacetohtml }}" />
<meta property="og:image:width" content="{{ graph.width }}" />
<meta property="og:image:height" content="{{ graph.height }}" />

View File

@@ -139,13 +139,19 @@ def isbreakthrough(delta,cpvalues,p0,p1,p2,p3,ratio):
pwr = abs(p0)/(1+(delta/abs(p2)))
pwr += abs(p1)/(1+(delta/abs(p3)))
dd = 0.25*(ratio-1)
pwr2 = pwr*(1+dd)
pwr *= ratio
delta = delta.values
cpvalues = cpvalues.values
res = np.sum(cpvalues>pwr)
res2 = np.sum(cpvalues>pwr2)
btdf = pd.DataFrame(
{
'delta':delta[cpvalues>pwr],
@@ -158,4 +164,4 @@ def isbreakthrough(delta,cpvalues,p0,p1,p2,p3,ratio):
btdf.sort_values('delta',axis=0,inplace=True)
return res>1,btdf
return res>1,btdf,res2>1