saves session result?
This commit is contained in:
@@ -2131,6 +2131,8 @@ regularsessiontypechoices = (
|
|||||||
('test','Mandatory Test'),
|
('test','Mandatory Test'),
|
||||||
('cycletarget','Total for a time period'),
|
('cycletarget','Total for a time period'),
|
||||||
('coursetest','OTW test over a course'),
|
('coursetest','OTW test over a course'),
|
||||||
|
('fastest_distance','Finds fastest time over a given distance'),
|
||||||
|
('fastest_time','Finds largest distance rowed over a given time'),
|
||||||
)
|
)
|
||||||
|
|
||||||
# model for Planned Session (Workout, Challenge, Test)
|
# model for Planned Session (Workout, Challenge, Test)
|
||||||
@@ -2143,6 +2145,8 @@ class PlannedSession(models.Model):
|
|||||||
('test','Mandatory Test'),
|
('test','Mandatory Test'),
|
||||||
('cycletarget','Total for a time period'),
|
('cycletarget','Total for a time period'),
|
||||||
('coursetest','OTW test over a course'),
|
('coursetest','OTW test over a course'),
|
||||||
|
('fastest_distance','Finds fastest time over a given distance'),
|
||||||
|
('fastest_time','Finds largest distance rowed over a given time'),
|
||||||
('race','Virtual challenge'),
|
('race','Virtual challenge'),
|
||||||
('indoorrace','Indoor Virtual challenge'),
|
('indoorrace','Indoor Virtual challenge'),
|
||||||
)
|
)
|
||||||
@@ -2153,6 +2157,8 @@ class PlannedSession(models.Model):
|
|||||||
('test','Mandatory Test'),
|
('test','Mandatory Test'),
|
||||||
('cycletarget','Total for a time period'),
|
('cycletarget','Total for a time period'),
|
||||||
('coursetest','OTW test over a course'),
|
('coursetest','OTW test over a course'),
|
||||||
|
('fastest_distance','Finds fastest time over a given distance'),
|
||||||
|
('fastest_time','Finds largest distance rowed over a given time'),
|
||||||
)
|
)
|
||||||
|
|
||||||
sessionmodechoices = (
|
sessionmodechoices = (
|
||||||
@@ -2274,7 +2280,7 @@ class PlannedSession(models.Model):
|
|||||||
else:
|
else:
|
||||||
self.sessionunit = 'None'
|
self.sessionunit = 'None'
|
||||||
|
|
||||||
if self.sessiontype == 'test' or self.sessiontype == 'indoorrace':
|
if self.sessiontype in ['test','indoorrace','fastest_distance','fastest_time']:
|
||||||
if self.sessionmode not in ['distance','time']:
|
if self.sessionmode not in ['distance','time']:
|
||||||
if self.sessionvalue < 100:
|
if self.sessionvalue < 100:
|
||||||
self.sessionmode = 'time'
|
self.sessionmode = 'time'
|
||||||
@@ -2832,6 +2838,8 @@ class PlannedSessionFormSmall(ModelForm):
|
|||||||
('test','Mandatory Test'),
|
('test','Mandatory Test'),
|
||||||
('cycletarget','Total for a time period'),
|
('cycletarget','Total for a time period'),
|
||||||
('coursetest','OTW test over a course'),
|
('coursetest','OTW test over a course'),
|
||||||
|
('fastest_distance','Finds fastest time over a given distance'),
|
||||||
|
('fastest_time','Finds largest distance rowed over a given time'),
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|||||||
@@ -27,6 +27,16 @@ import pandas as pd
|
|||||||
from rowingdata import rowingdata as rrdata
|
from rowingdata import rowingdata as rrdata
|
||||||
from rowingdata import rower as rrower
|
from rowingdata import rower as rrower
|
||||||
|
|
||||||
|
def to_time(milliseconds):
|
||||||
|
seconds = milliseconds/1000.
|
||||||
|
hours = int(seconds / 3600)
|
||||||
|
mins = int((seconds%3600)/60)
|
||||||
|
sec = int((seconds%3600)%60)
|
||||||
|
microsec = int(1e6*(seconds % 1))
|
||||||
|
#print(seconds,hours,mins,sec,millisec)
|
||||||
|
|
||||||
|
return dt.time(hours,mins,sec,microsec)
|
||||||
|
|
||||||
# Wrapper around the rowingdata call to catch some exceptions
|
# Wrapper around the rowingdata call to catch some exceptions
|
||||||
# Checks for CSV file, then for gzipped CSV file, and if all fails, returns 0
|
# Checks for CSV file, then for gzipped CSV file, and if all fails, returns 0
|
||||||
def rdata(file,rower=rrower()):
|
def rdata(file,rower=rrower()):
|
||||||
@@ -360,7 +370,7 @@ def add_workouts_plannedsession(ws,ps,r):
|
|||||||
ids = [w.id for w in wold] + [w.id for w in ws]
|
ids = [w.id for w in wold] + [w.id for w in ws]
|
||||||
ids = list(set(ids))
|
ids = list(set(ids))
|
||||||
|
|
||||||
if len(ids)>1 and ps.sessiontype in ['test','coursetest','race']:
|
if len(ids)>1 and ps.sessiontype in ['test','coursetest','race','fastest_distance','fastest_time']:
|
||||||
errors.append('For tests, you can only attach one workout')
|
errors.append('For tests, you can only attach one workout')
|
||||||
return result,comments,errors
|
return result,comments,errors
|
||||||
|
|
||||||
@@ -383,6 +393,28 @@ def add_workouts_plannedsession(ws,ps,r):
|
|||||||
w.id,ps.course.id,record.id,
|
w.id,ps.course.id,record.id,
|
||||||
w.user.user.email,w.user.user.first_name,
|
w.user.user.email,w.user.user.first_name,
|
||||||
mode='coursetest')
|
mode='coursetest')
|
||||||
|
if ps.sessiontype == 'fastest_distance':
|
||||||
|
df = dataprep.getsmallrowdata_db(['time','cumdist'],ids=[w.id])
|
||||||
|
fastest_milliseconds = datautils.getfastest(df,ps.sessionvalue,mode='distance')
|
||||||
|
if fastest_milliseconds > 0:
|
||||||
|
duration = to_time(fastest_milliseconds)
|
||||||
|
|
||||||
|
record = CourseTestResult(
|
||||||
|
userid=w.user.id,
|
||||||
|
plannedsession = ps,
|
||||||
|
duration = duration,
|
||||||
|
coursecompleted = True,
|
||||||
|
distance = ps.sessionvalue,
|
||||||
|
)
|
||||||
|
record.save()
|
||||||
|
else:
|
||||||
|
record = CourseTestResult(
|
||||||
|
userid = w.user.id,
|
||||||
|
plannedsession = ps,
|
||||||
|
duration = dt.time(0,0),
|
||||||
|
coursecompleted = True,
|
||||||
|
distance = ps.sessionvalue,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
errors.append('Workout %i did not match session dates' % w.id)
|
errors.append('Workout %i did not match session dates' % w.id)
|
||||||
|
|
||||||
|
|||||||
@@ -205,6 +205,20 @@
|
|||||||
if (this.value == 'cycletarget') {
|
if (this.value == 'cycletarget') {
|
||||||
$("td #id_criterium").prop("value","none");
|
$("td #id_criterium").prop("value","none");
|
||||||
$('#id_guidance').html("<p>For Cycle Targets, the default criterium is 'Approximately'</p>");
|
$('#id_guidance').html("<p>For Cycle Targets, the default criterium is 'Approximately'</p>");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.value == 'fastest_distance') {
|
||||||
|
$("td #id_criterium").prop("value","exact");
|
||||||
|
$("td #id_sessionunit").prop("value","m");
|
||||||
|
$("td #id_sessionmode").prop("value","distance")
|
||||||
|
$('#id_guidance').html("<p>For Fastest Distance, set an exact number of meters</p>");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.value == 'fastest_time') {
|
||||||
|
$("td #id_criterium").prop("value","exact");
|
||||||
|
$("td #id_sessionunit").prop("value","min");
|
||||||
|
$("td #id_sessionmode").prop("value","time")
|
||||||
|
$('#id_guidance').html("<p>For Fastest Time, set an exact number of minutes</p>");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user