Private
Public Access
1
0

Merge branch 'feature/cpnotification' into develop

This commit is contained in:
Sander Roosendaal
2017-07-03 22:09:25 +02:00
8 changed files with 204 additions and 150 deletions
+6 -3
View File
@@ -428,7 +428,8 @@ def save_workout_database(f2,r,dosmooth=True,workouttype='rower',
isbreakthrough = False isbreakthrough = False
if workouttype == 'water': if workouttype == 'water':
delta,cpvalues,avgpower = datautils.getsinglecp(row.df) 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 isbreakthrough = True
res = datautils.updatecp(delta,cpvalues,r) 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: if settings.DEBUG and r.getemailnotifications:
res = handle_sendemail_breakthrough.delay(w.id,r.user.email, res = handle_sendemail_breakthrough.delay(w.id,r.user.email,
r.user.first_name, r.user.first_name,
r.user.last_name) r.user.last_name,
btvalues=btvalues.to_json())
elif r.getemailnotifications: elif r.getemailnotifications:
try: try:
res = queuehigh.enqueue( res = queuehigh.enqueue(
handle_sendemail_breakthrough(w.id, handle_sendemail_breakthrough(w.id,
r.user.email, r.user.email,
r.user.first_name, r.user.first_name,
r.user.last_name)) r.user.last_name,
btvalues=btvalues.to_json()))
except AttributeError: except AttributeError:
pass pass
else: else:
+3 -4
View File
@@ -77,8 +77,8 @@ def cpfit(powerdf):
def getlogarr(maxt): def getlogarr(maxt):
maxlog10 = np.log10(maxt-5) maxlog10 = np.log10(maxt-5)
logarr = np.log10(5.)+np.arange(50)*maxlog10/50. logarr = np.arange(50)*maxlog10/50.
logarr = [int(10.**(la)) for la in logarr] logarr = [5+int(10.**(la)) for la in logarr]
logarr = pd.Series(logarr) logarr = pd.Series(logarr)
logarr.drop_duplicates(keep='first',inplace=True) logarr.drop_duplicates(keep='first',inplace=True)
@@ -88,7 +88,7 @@ def getlogarr(maxt):
def getsinglecp(df): def getsinglecp(df):
thesecs = df['TimeStamp (sec)'].max()-df['TimeStamp (sec)'].min() thesecs = df['TimeStamp (sec)'].max()-df['TimeStamp (sec)'].min()
if thesecs != 0: if thesecs != 0:
maxt = 2*thesecs maxt = 1.05*thesecs
else: else:
maxt = 1000. maxt = 1000.
@@ -152,7 +152,6 @@ def getcp(dfgrouped,logarr):
dt = pd.Series(dt) dt = pd.Series(dt)
cpw = pd.Series(cpw) cpw = pd.Series(cpw)
if len(dt): if len(dt):
cpvalues = griddata(dt.values, cpvalues = griddata(dt.values,
cpw.values, cpw.values,
logarr,method='linear', logarr,method='linear',
+30 -5
View File
@@ -18,7 +18,8 @@ import matplotlib.pyplot as plt
from matplotlib import figure from matplotlib import figure
import stravalib import stravalib
import pandas as pd
from django_rq import job from django_rq import job
from utils import serialize_list,deserialize_list from utils import serialize_list,deserialize_list
@@ -49,7 +50,9 @@ def handle_new_workout_from_file(r,f2,
# send email when a breakthrough workout is uploaded # send email when a breakthrough workout is uploaded
@app.task @app.task
def handle_sendemail_breakthrough(workoutid,useremail,userfirstname,userlastname): def handle_sendemail_breakthrough(workoutid,useremail,
userfirstname,userlastname,
btvalues = pd.DataFrame().to_json()):
# send email with attachment # send email with attachment
subject = "A breakthrough workout on rowsandall.com" subject = "A breakthrough workout on rowsandall.com"
@@ -60,7 +63,7 @@ def handle_sendemail_breakthrough(workoutid,useremail,userfirstname,userlastname
message += " Critical Power (CP) is the power that you can " message += " Critical Power (CP) is the power that you can "
message += "sustain for a given duration. For more, see this " message += "sustain for a given duration. For more, see this "
message += " article in the analytics blog:\n\n" 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 += "Link to the workout http://rowsandall.com/rowers/workout/"
message += str(workoutid) message += str(workoutid)
message +="/edit\n\n" message +="/edit\n\n"
@@ -69,6 +72,27 @@ def handle_sendemail_breakthrough(workoutid,useremail,userfirstname,userlastname
message += str(workoutid) message += str(workoutid)
message += "/updatecp\n\n" 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():
delta = t.delta
cpvalue = t.cpvalues
pwr = t.pwr
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" 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" message += "Best Regards, the Rowsandall Team"
@@ -222,10 +246,11 @@ def handle_otwsetpower(f1,boattype,weightvalue,
update_strokedata(workoutid,rowdata.df,debug=debug) update_strokedata(workoutid,rowdata.df,debug=debug)
delta,cpvalues,avgpower = datautils.getsinglecp(rowdata.df) delta,cpvalues,avgpower = datautils.getsinglecp(rowdata.df)
if 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, handle_sendemail_breakthrough(workoutid,email,
first_name, first_name,
last_name) last_name,btvalues=btvalues.to_json())
# send email # send email
fullemail = first_name + " " + last_name + " " + "<" + email + ">" fullemail = first_name + " " + last_name + " " + "<" + email + ">"
+51 -43
View File
@@ -7,49 +7,57 @@
{% block content %} {% block content %}
<div id="workouts" class="grid_6 alpha"> <div id="workouts" class="grid_6 alpha">
<div class="grid_6 alpha">
<h1>Stream Editor</h1> <h1>Stream Editor</h1>
<div class="grid_2 alpha"> </div>
<p> <div class="grid_6 alpha">
<a class="button gray small" href="/rowers/workout/{{ workout.id }}/edit">Edit Workout</a> <div class="grid_2 alpha">
</p> <p>
</div> <a class="button gray small" href="/rowers/workout/{{ workout.id }}/edit">Edit Workout</a>
<div class="grid_2"> </p>
<p> </div>
<a class="button gray small" href="/rowers/workout/{{ workout.id }}/advanced">Advanced Edit</a> <div class="grid_2">
</p> <p>
<a class="button gray small" href="/rowers/workout/{{ workout.id }}/advanced">Advanced Edit</a>
</div> </p>
<div class="grid_2 omega tooltip">
<p><a class="button blue small" href="/rowers/workout/{{ workout.id }}/otwsetpower">OTW Power</a></p> </div>
<span class="tooltiptext">Run calculations to get power values for your row.</span> <div class="grid_2 omega tooltip">
<p><a class="button blue small" href="/rowers/workout/{{ workout.id }}/otwsetpower">OTW Power</a></p>
</div> <span class="tooltiptext">Run calculations to get power values for your row.</span>
<div class="grid_6 alpha">
<p> </div>
Edit river Stream between turning points in your row. </div>
Use positive (+) values to denote rowing with the stream, <div class="grid_6 alpha">
negative (-) values to denote rowing against the stream. <div class="grid_2 prefix_4 alpha">
</p> <p><a class="button blue small" href="/rowers/workout/{{ workout.id }}/wind">Wind Edit</a></p>
</div>
</div>
<div class="grid_6 alpha">
<p>
Edit river Stream between turning points in your row.
Use positive (+) values to denote rowing with the stream,
negative (-) values to denote rowing against the stream.
</p>
<form enctype="multipart/form-data" action="{{ formloc }}" method="post"> <form enctype="multipart/form-data" action="{{ formloc }}" method="post">
{% if form.errors %} {% if form.errors %}
<p style="color: red;"> <p style="color: red;">
Please correct the error{{ form.errors|pluralize }} below. Please correct the error{{ form.errors|pluralize }} below.
</p> </p>
{% endif %} {% endif %}
<table> <table>
{{ form.as_table }} {{ form.as_table }}
</table> </table>
{% csrf_token %} {% csrf_token %}
</div> </div>
<div id="formbutton" class="grid_1 prefix_3 suffix_2"> <div id="formbutton" class="grid_1 prefix_3 suffix_2">
<input class="button green" type="submit" value="Update"> <input class="button green" type="submit" value="Update">
</div> </div>
</form> </form>
<img src="/static/img/rivercurrent.jpg" width="400"> <img src="/static/img/rivercurrent.jpg" width="400">
</div> </div>
<div id="advancedplots" class="grid_6 omega"> <div id="advancedplots" class="grid_6 omega">
@@ -86,4 +94,4 @@
{{ the_div |safe }} {{ the_div |safe }}
</div> </div>
{% endblock %} {% endblock %}
+98 -90
View File
@@ -6,113 +6,121 @@
{% block content %} {% block content %}
<div id="workouts" class="grid_6 alpha"> <div id="workouts" class="grid_6 alpha">
<div class="grid_6 alpha">
<h1>Wind Editor</h1> <h1>Wind Editor</h1>
<div class="grid_2 alpha"> </div>
<p> <div class="grid_6 alpha">
<a class="button gray small" href="/rowers/workout/{{ workout.id }}/edit">Edit Workout</a> <div class="grid_2 alpha">
</p> <p>
</div> <a class="button gray small" href="/rowers/workout/{{ workout.id }}/edit">Edit Workout</a>
<div class="grid_2"> </p>
<p> </div>
<a class="button gray small" href="/rowers/workout/{{ workout.id }}/advanced">Advanced Edit</a> <div class="grid_2">
</p> <p>
<a class="button gray small" href="/rowers/workout/{{ workout.id }}/advanced">Advanced Edit</a>
</div> </p>
<div class="grid_2 omega tooltip">
<p><a class="button blue small" href="/rowers/workout/{{ workout.id }}/otwsetpower">OTW Power</a></p> </div>
<span class="tooltiptext">Run calculations to get power values for your row.</span> <div class="grid_2 omega tooltip">
<p><a class="button blue small" href="/rowers/workout/{{ workout.id }}/otwsetpower">OTW Power</a></p>
</div> <span class="tooltiptext">Run calculations to get power values for your row.</span>
<div class="grid_6 alpha">
<p> </div>
Update wind between distance 1 and distance 2. Submit wind strength </div>
and direction at start and end of segment. Blank the form for values <div class="grid_6 alpha">
you want to keep intact. <div class="grid_2 prefix_4 alpha">
</p> <p><a class="button blue small" href="/rowers/workout/{{ workout.id }}/stream">Stream Edit</a></p>
</div>
<p> </div>
Check <a href="https://www.wunderground.com">www.wunderground.com</a> <div class="grid_6 alpha">
to find historical weather data from an on-line weather station near <p>
the location of your row. Update wind between distance 1 and distance 2. Submit wind strength
</p> and direction at start and end of segment. Blank the form for values
you want to keep intact.
<div class="grid_4 alpha"> </p>
<form enctype="multipart/form-data" action="{{ formloc }}" method="post">
{% if form.errors %} <p>
Check <a href="https://www.wunderground.com">www.wunderground.com</a>
to find historical weather data from an on-line weather station near
the location of your row.
</p>
<div class="grid_4 alpha">
<form enctype="multipart/form-data" action="{{ formloc }}" method="post">
{% if form.errors %}
<p style="color: red;"> <p style="color: red;">
Please correct the error{{ form.errors|pluralize }} below. Please correct the error{{ form.errors|pluralize }} below.
</p> </p>
{% endif %} {% endif %}
<table> <table>
{{ form.as_table }} {{ form.as_table }}
</table> </table>
{% csrf_token %} {% csrf_token %}
</div> </div>
<div class="grid_2 omega"> <div class="grid_2 omega">
<p>Closest Airport Weather: {{ airport }} <p>Closest Airport Weather: {{ airport }}
({{ airportdistance | floatformat:-1 }} km) ({{ airportdistance | floatformat:-1 }} km)
<a class="button green small" href="/rowers/workout/{{ workout.id }}/metar/{{ airport }}">Airport Data</a></p> <a class="button green small" href="/rowers/workout/{{ workout.id }}/metar/{{ airport }}">Airport Data</a></p>
<p> <p>
<a class="button green small" href="/rowers/workout/{{ workout.id }}/darkskywind">Dark Sky Data</a> <a class="button green small" href="/rowers/workout/{{ workout.id }}/darkskywind">Dark Sky Data</a>
<p> <p>
Download wind speed and bearing from <a href="http://forecast.io/">The Dark Sky</a> Download wind speed and bearing from <a href="http://forecast.io/">The Dark Sky</a>
</p> </p>
</div> </div>
<div class="grid_2 omega"> <div class="grid_2 omega">
<input class="button green small" type="submit" value="Submit Form"> <input class="button green small" type="submit" value="Submit Form">
<p> <p>
Manual update of the wind data from the form. Manual update of the wind data from the form.
</p> </p>
</div> </div>
</form> </form>
<img src="http://cliparts.co/cliparts/rTn/KaR/rTnKaRrxc.gif" width="400"> <img src="http://cliparts.co/cliparts/rTn/KaR/rTnKaRrxc.gif" width="400">
</div> </div>
</div> </div>
<div id="advancedplots" class="grid_6 omega"> <div id="advancedplots" class="grid_6 omega">
<script type="text/javascript" src="/static/js/bokeh-0.12.3.min.js"></script> <script type="text/javascript" src="/static/js/bokeh-0.12.3.min.js"></script>
<script async="true" type="text/javascript"> <script async="true" type="text/javascript">
Bokeh.set_log_level("info"); Bokeh.set_log_level("info");
</script> </script>
{{ interactiveplot |safe }} {{ interactiveplot |safe }}
{{ gmap |safe }} {{ gmap |safe }}
<script> <script>
// Set things up to resize the plot on a window resize. You can play with // Set things up to resize the plot on a window resize. You can play with
// the arguments of resize_width_height() to change the plot's behavior. // the arguments of resize_width_height() to change the plot's behavior.
var plot_resize_setup = function () { var plot_resize_setup = function () {
var plotid = Object.keys(Bokeh.index)[0]; // assume we have just one plot var plotid = Object.keys(Bokeh.index)[0]; // assume we have just one plot
var plot = Bokeh.index[plotid]; var plot = Bokeh.index[plotid];
var plotresizer = function() { var plotresizer = function() {
// arguments: use width, use height, maintain aspect ratio // arguments: use width, use height, maintain aspect ratio
plot.resize_width_height(true, true, true); plot.resize_width_height(true, true, true);
}; };
window.addEventListener('resize', plotresizer); window.addEventListener('resize', plotresizer);
plotresizer(); plotresizer();
}; };
window.addEventListener('load', plot_resize_setup); window.addEventListener('load', plot_resize_setup);
</script> </script>
<style> <style>
/* Need this to get the page in "desktop mode"; not having an infinite height.*/ /* Need this to get the page in "desktop mode"; not having an infinite height.*/
html, body {height: 100%; margin:5px;} html, body {height: 100%; margin:5px;}
</style> </style>
<div id="interactiveplot" class="grid_6 omega"> <div id="interactiveplot" class="grid_6 omega">
<div class="grid_6 alpha"> <div class="grid_6 alpha">
{{ the_div |safe }} {{ the_div |safe }}
</div> </div>
</div> </div>
<div id="interactiveplot" class="grid_6 omega"> <div id="interactiveplot" class="grid_6 omega">
<div class="grid_6 alpha"> <div class="grid_6 alpha">
{{ gmapdiv |safe }} {{ gmapdiv |safe }}
</div> </div>
</div> </div>
{% endblock %} {% endblock %}
+13 -3
View File
@@ -1,6 +1,6 @@
import math import math
import numpy as np import numpy as np
import pandas as pd
lbstoN = 4.44822 lbstoN = 4.44822
@@ -77,7 +77,6 @@ def geo_distance(lat1,lon1,lat2,lon2):
def isbreakthrough(delta,cpvalues,p0,p1,p2,p3,ratio): def isbreakthrough(delta,cpvalues,p0,p1,p2,p3,ratio):
pwr = p0/(1+delta/p2) pwr = p0/(1+delta/p2)
pwr += p1/(1+delta/p3) pwr += p1/(1+delta/p3)
@@ -85,4 +84,15 @@ def isbreakthrough(delta,cpvalues,p0,p1,p2,p3,ratio):
res = np.sum(cpvalues>pwr) res = np.sum(cpvalues>pwr)
return res>1 btdf = pd.DataFrame(
{
'delta':delta[cpvalues>pwr],
'cpvalues':cpvalues[cpvalues>pwr],
'pwr':pwr[cpvalues>pwr],
}
)
btdf.sort_values('delta',axis=0,inplace=True)
return res>1,btdf
+3 -2
View File
@@ -4403,8 +4403,9 @@ def workout_otwsetpower_view(request,id=0,message="",successmessage=""):
rowdata.write_csv(f1,gzip=True) rowdata.write_csv(f1,gzip=True)
# do power calculation (asynchronous) # do power calculation (asynchronous)
u = request.user r = row.user
r = Rower.objects.get(user=u) u = r.user
first_name = u.first_name first_name = u.first_name
last_name = u.last_name last_name = u.last_name
emailaddress = u.email emailaddress = u.email
BIN
View File
Binary file not shown.