half way through doing course_adherence
This commit is contained in:
@@ -15,6 +15,8 @@ import xml.etree.ElementTree as et
|
||||
|
||||
import pandas as pd
|
||||
|
||||
import dataprep
|
||||
|
||||
ns = {'opengis': 'http://www.opengis.net/kml/2.2'}
|
||||
|
||||
|
||||
@@ -202,6 +204,11 @@ def createcourse(
|
||||
if i==0 and j==0:
|
||||
loc = geolocator.reverse((point['latitude'],point['longitude']))
|
||||
country = loc.raw['address']['country']
|
||||
if isinstance(country,unicode):
|
||||
country = country.encode('utf8')
|
||||
elif isinstance(country, str):
|
||||
country = country.decode('utf8')
|
||||
|
||||
c.country = country
|
||||
c.save()
|
||||
obj = GeoPoint(
|
||||
@@ -215,3 +222,48 @@ def createcourse(
|
||||
i += 1
|
||||
|
||||
return c
|
||||
|
||||
def coursetime_polygons(data,polygons):
|
||||
|
||||
entrytime = data['time'].max()
|
||||
coursecompleted = False
|
||||
|
||||
# corner case - empty list of polygons
|
||||
if len(polygons) == 0:
|
||||
return 0,True
|
||||
|
||||
# end - just the Finish polygon
|
||||
if len(polygons) == 1:
|
||||
try:
|
||||
entrytime = time_in_polygon(data,polygons[0],maxmin='min')
|
||||
coursecompleted = True
|
||||
except InvalidTrajectoryError:
|
||||
entrytime = data['time'].max()
|
||||
coursecompleted = False
|
||||
return entrytime,coursecompleted
|
||||
|
||||
if len(polygons) > 1:
|
||||
try:
|
||||
time = time_in_polygon(data, polygons[0])
|
||||
|
||||
return entrytime, coursecompleted
|
||||
|
||||
def get_time_course(ws,course):
|
||||
coursetimeseconds = 0.0
|
||||
coursecompleted = 0
|
||||
|
||||
w = ws[0]
|
||||
columns = ['time','latitude','longitude']
|
||||
rowdata = dataprep.getsmallrowdata_db(
|
||||
columns,
|
||||
ids = [w.id],
|
||||
workstrokesonly=False
|
||||
)
|
||||
|
||||
# we may want to expand the time (interpolate)
|
||||
|
||||
polygons = GeoPolygon.object.filter(course=course)
|
||||
|
||||
coursetimeseconds,coursecompleted = coursetime_polygons(rowdata,polygons)
|
||||
|
||||
return coursetimeseconds,coursecompleted
|
||||
|
||||
@@ -24,6 +24,7 @@ from rowers.models import (
|
||||
import metrics
|
||||
import numpy as np
|
||||
import dataprep
|
||||
import courses
|
||||
|
||||
# Low Level functions - to be called by higher level methods
|
||||
def add_workouts_plannedsession(ws,ps,r):
|
||||
@@ -47,7 +48,7 @@ def add_workouts_plannedsession(ws,ps,r):
|
||||
ids = [w.id for w in wold] + [w.id for w in ws]
|
||||
ids = list(set(ids))
|
||||
|
||||
if len(ids)>1 and ps.sessiontype == 'test':
|
||||
if len(ids)>1 and ps.sessiontype in ['test','coursetest']:
|
||||
errors.append('For tests, you can only attach one workout')
|
||||
return result,comments,errors
|
||||
|
||||
@@ -233,8 +234,36 @@ def is_session_complete_ws(ws,ps):
|
||||
else:
|
||||
if not completiondate:
|
||||
completiondate = ws.reverse()[0].date
|
||||
return ratio,'partial',completiondate
|
||||
|
||||
return ratio,'partial',completiondate
|
||||
elif ps.sessiontype == 'coursetest':
|
||||
if ps.course:
|
||||
coursetime,coursecompleted = courses.get_time_course(ws,ps.course)
|
||||
if coursecompleted:
|
||||
return 1.0,'completed',completiondate
|
||||
else:
|
||||
return ratio,'partial',completiondate
|
||||
else:
|
||||
if ps.criterium == 'exact':
|
||||
if ratio == 1.0:
|
||||
return ratio,'completed',completiondate
|
||||
else:
|
||||
if not completiondate:
|
||||
completiondate = ws.reverse()[0].date
|
||||
return ratio,'partial',completiondate
|
||||
elif ps.criterium == 'minimum':
|
||||
if ratio >= 1.0:
|
||||
return ratio,'completed',completiondate
|
||||
else:
|
||||
if not completiondate:
|
||||
completiondate = ws.reverse()[0].date
|
||||
|
||||
return ratio,'partial',completiondate
|
||||
else:
|
||||
if ratio>cratiomin and ratio<cratiomax:
|
||||
return ratio,'completed',completiondate
|
||||
else:
|
||||
return ratio,'partial',completiondate
|
||||
|
||||
else:
|
||||
if not completiondate:
|
||||
completiondate = ws.reverse()[0].date
|
||||
|
||||
@@ -289,6 +289,10 @@ def handle_sendemail_breakthrough(workoutid, useremail,
|
||||
btvalues=pd.DataFrame().to_json(),
|
||||
**kwargs):
|
||||
|
||||
siteurl = SITE_URL
|
||||
if debug:
|
||||
siteurl = SITE_URL_DEV
|
||||
|
||||
# send email with attachment
|
||||
subject = "A breakthrough workout on rowsandall.com"
|
||||
message = "Dear " + userfirstname + ",\n"
|
||||
@@ -299,11 +303,11 @@ def handle_sendemail_breakthrough(workoutid, useremail,
|
||||
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 += "Link to the workout "+siteurl+"/rowers/workout/"
|
||||
message += str(workoutid)
|
||||
message += "/edit\n\n"
|
||||
message += "To add the workout to your Ranking workouts and see the updated CP plot, click the following link:\n"
|
||||
message += "http://rowsandall.com/rowers/workout/"
|
||||
message += siteurl+"/rowers/workout/"
|
||||
message += str(workoutid)
|
||||
message += "/updatecp\n\n"
|
||||
|
||||
@@ -349,6 +353,10 @@ def handle_sendemail_hard(workoutid, useremail,
|
||||
btvalues=pd.DataFrame().to_json(),
|
||||
debug=False,**kwargs):
|
||||
|
||||
siteurl = SITE_URL
|
||||
if debug:
|
||||
siteurl = SITE_URL_DEV
|
||||
|
||||
# send email with attachment
|
||||
subject = "That was a pretty hard workout on rowsandall.com"
|
||||
message = "Dear " + userfirstname + ",\n"
|
||||
@@ -359,7 +367,7 @@ def handle_sendemail_hard(workoutid, useremail,
|
||||
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 += "Link to the workout: "+siteurl+"/rowers/workout/"
|
||||
message += str(workoutid)
|
||||
message += "/edit\n\n"
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
</table>
|
||||
</div>
|
||||
<div id="right" class="grid_6 omega">
|
||||
{% if plannedsession.sessiontype == 'test' %}
|
||||
{% if plannedsession.sessiontype == 'test' or plannedsession.sessiontype == 'coursetest' %}
|
||||
<h1>Ranking</h1>
|
||||
<table class="listtable shortpadded" width="80%">
|
||||
<thead>
|
||||
|
||||
@@ -8463,7 +8463,11 @@ def course_edit_view(request,id=0):
|
||||
if form.is_valid():
|
||||
name = form.cleaned_data['name']
|
||||
notes = form.cleaned_data['notes']
|
||||
|
||||
if isinstance(name,unicode):
|
||||
name = name.encode('utf8')
|
||||
elif isinstance(name, str):
|
||||
name = name.decode('utf8')
|
||||
|
||||
course.name = name
|
||||
course.notes = notes
|
||||
course.save()
|
||||
@@ -12645,7 +12649,7 @@ def plannedsession_view(request,id=0,rowerid=0,
|
||||
# ranking for test
|
||||
ranking = []
|
||||
|
||||
if ps.sessiontype == 'test':
|
||||
if ps.sessiontype in ['test','coursetest']:
|
||||
if ps.sessionmode == 'distance':
|
||||
rankws = Workout.objects.filter(
|
||||
plannedsession=ps).order_by("duration")
|
||||
|
||||
Reference in New Issue
Block a user