distance, time sort of working
This commit is contained in:
@@ -371,10 +371,10 @@ def getfastest(df,thevalue,mode='distance'):
|
|||||||
|
|
||||||
tmax = tt.max()
|
tmax = tt.max()
|
||||||
if mode == 'distance':
|
if mode == 'distance':
|
||||||
if dd.max() > thevalue:
|
if dd.max() < thevalue:
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
if tt.max() > thevalue:
|
if tt.max() < thevalue:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if tmax > 500000:
|
if tmax > 500000:
|
||||||
@@ -418,10 +418,16 @@ def getfastest(df,thevalue,mode='distance'):
|
|||||||
restime = np.array(restime)
|
restime = np.array(restime)
|
||||||
distance = np.array(distance)
|
distance = np.array(distance)
|
||||||
|
|
||||||
|
#for i in range(len(restime)):
|
||||||
|
# if restime[i]<thevalue*60*1000:
|
||||||
|
# print(i,restime[i],distance[i],60*1000*thevalue)
|
||||||
|
|
||||||
d2 = 0
|
d2 = 0
|
||||||
if mode == 'distance':
|
if mode == 'distance':
|
||||||
d2 = griddata(distance,restime,[thevalue],method='linear',rescale=True)
|
d2 = griddata(distance,restime,[thevalue],method='linear',rescale=True)
|
||||||
|
return d2[0]/1000.
|
||||||
else:
|
else:
|
||||||
d2 = griddata(restime,distance,[thevalue],method='linear',rescale=True)
|
d2 = griddata(restime,distance,[thevalue*60*1000],method='linear',rescale=True)
|
||||||
|
return d2[0]
|
||||||
|
|
||||||
return d2[0]/1000.
|
return 0
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ import rowers.mytypes as mytypes
|
|||||||
import rowers.metrics as metrics
|
import rowers.metrics as metrics
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import rowers.dataprep as dataprep
|
import rowers.dataprep as dataprep
|
||||||
|
import rowers.datautils as datautils
|
||||||
import rowers.courses as courses
|
import rowers.courses as courses
|
||||||
import iso8601
|
import iso8601
|
||||||
from iso8601 import ParseError
|
from iso8601 import ParseError
|
||||||
@@ -376,6 +377,7 @@ def add_workouts_plannedsession(ws,ps,r):
|
|||||||
|
|
||||||
# start adding sessions
|
# start adding sessions
|
||||||
for w in ws:
|
for w in ws:
|
||||||
|
print(ps.sessiontype)
|
||||||
if w.date>=ps.startdate and w.date<=ps.enddate:
|
if w.date>=ps.startdate and w.date<=ps.enddate:
|
||||||
w.plannedsession = ps
|
w.plannedsession = ps
|
||||||
w.save()
|
w.save()
|
||||||
@@ -394,27 +396,67 @@ def add_workouts_plannedsession(ws,ps,r):
|
|||||||
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':
|
if ps.sessiontype == 'fastest_distance':
|
||||||
|
records = CourseTestResult.objects.filter(userid=w.user.id,plannedsession=ps)
|
||||||
|
for record in records:
|
||||||
|
record.delete()
|
||||||
|
|
||||||
df = dataprep.getsmallrowdata_db(['time','cumdist'],ids=[w.id])
|
df = dataprep.getsmallrowdata_db(['time','cumdist'],ids=[w.id])
|
||||||
fastest_milliseconds = datautils.getfastest(df,ps.sessionvalue,mode='distance')
|
fastest_milliseconds = datautils.getfastest(df,ps.sessionvalue,mode='distance')
|
||||||
|
|
||||||
if fastest_milliseconds > 0:
|
if fastest_milliseconds > 0:
|
||||||
duration = to_time(fastest_milliseconds)
|
|
||||||
|
duration = to_time(1000.*fastest_milliseconds)
|
||||||
|
|
||||||
record = CourseTestResult(
|
record = CourseTestResult(
|
||||||
userid=w.user.id,
|
userid=w.user.id,
|
||||||
plannedsession = ps,
|
plannedsession = ps,
|
||||||
duration = duration,
|
duration = duration,
|
||||||
coursecompleted = True,
|
coursecompleted = True,
|
||||||
|
workoutid=w.id,
|
||||||
distance = ps.sessionvalue,
|
distance = ps.sessionvalue,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
record.save()
|
||||||
|
else:
|
||||||
|
record = CourseTestResult(
|
||||||
|
userid = w.user.id,
|
||||||
|
workoutid=w.id,
|
||||||
|
plannedsession = ps,
|
||||||
|
duration = dt.time(0,0),
|
||||||
|
coursecompleted = True,
|
||||||
|
distance = ps.sessionvalue,
|
||||||
|
)
|
||||||
|
record.save()
|
||||||
|
if ps.sessiontype == 'fastest_time':
|
||||||
|
records = CourseTestResult.objects.filter(userid=w.user.id,plannedsession=ps)
|
||||||
|
for record in records:
|
||||||
|
record.delete()
|
||||||
|
|
||||||
|
df = dataprep.getsmallrowdata_db(['time','cumdist'],ids=[w.id])
|
||||||
|
fastest_meters = datautils.getfastest(df,ps.sessionvalue,mode='time')
|
||||||
|
print(fastest_meters,'aap')
|
||||||
|
if fastest_meters > 0:
|
||||||
|
duration = dt.time(0,ps.sessionvalue)
|
||||||
|
|
||||||
|
record = CourseTestResult(
|
||||||
|
userid=w.user.id,
|
||||||
|
workoutid=w.id,
|
||||||
|
plannedsession = ps,
|
||||||
|
duration = duration,
|
||||||
|
coursecompleted = True,
|
||||||
|
distance = fastest_meters,
|
||||||
|
)
|
||||||
record.save()
|
record.save()
|
||||||
else:
|
else:
|
||||||
record = CourseTestResult(
|
record = CourseTestResult(
|
||||||
userid = w.user.id,
|
userid = w.user.id,
|
||||||
plannedsession = ps,
|
plannedsession = ps,
|
||||||
duration = dt.time(0,0),
|
workoutid=w.id,
|
||||||
|
duration = dt.time(0,ps.sessionvalue),
|
||||||
coursecompleted = True,
|
coursecompleted = True,
|
||||||
distance = ps.sessionvalue,
|
distance = fastest_meters,
|
||||||
)
|
)
|
||||||
|
record.save()
|
||||||
else:
|
else:
|
||||||
errors.append('Workout %i did not match session dates' % w.id)
|
errors.append('Workout %i did not match session dates' % w.id)
|
||||||
|
|
||||||
@@ -668,6 +710,27 @@ def is_session_complete_ws(ws,ps):
|
|||||||
ratio = record.distance/ps.sessionvalue
|
ratio = record.distance/ps.sessionvalue
|
||||||
return ratio,'partial',completiondate
|
return ratio,'partial',completiondate
|
||||||
return (0,'partial',None)
|
return (0,'partial',None)
|
||||||
|
elif ps.sessiontype in ['fastest_time','fastest_distance']:
|
||||||
|
vs = CourseTestResult.objects.filter(plannedsession=ps,userid=ws[0].user.id)
|
||||||
|
completiondate = ws.reverse()[0].date
|
||||||
|
wids = [w.id for w in ws]
|
||||||
|
for record in vs:
|
||||||
|
if record.workoutid in wids:
|
||||||
|
if record.coursecompleted:
|
||||||
|
ratio = 1
|
||||||
|
return ratio,'on target',completiondate
|
||||||
|
else:
|
||||||
|
return 0,'partial',completiondate
|
||||||
|
if ws:
|
||||||
|
record = CourseTestResult(
|
||||||
|
userid = ws[0].user.id,
|
||||||
|
plannedsession = ps,
|
||||||
|
workoutid = ws[0].id,
|
||||||
|
duration = dt.time(0,0),
|
||||||
|
coursecompleted = False
|
||||||
|
)
|
||||||
|
record.save()
|
||||||
|
return (0,'not done',None)
|
||||||
elif ps.sessiontype == 'coursetest':
|
elif ps.sessiontype == 'coursetest':
|
||||||
vs = CourseTestResult.objects.filter(plannedsession=ps)
|
vs = CourseTestResult.objects.filter(plannedsession=ps)
|
||||||
wids = [w.id for w in ws]
|
wids = [w.id for w in ws]
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
</table>
|
</table>
|
||||||
</li>
|
</li>
|
||||||
<li class="grid_2">
|
<li class="grid_2">
|
||||||
{% if plannedsession.sessiontype == 'test' or plannedsession.sessiontype == 'coursetest' %}
|
{% if plannedsession.sessiontype == 'test' or plannedsession.sessiontype == 'coursetest' or plannedsession.sessiontype == 'fastest_distance' or plannedsession.sessiontype == 'fastest_time' %}
|
||||||
<h2>Ranking</h2>
|
<h2>Ranking</h2>
|
||||||
<table id="rankingtable" class="listtable shortpadded tablesorter" width="80%">
|
<table id="rankingtable" class="listtable shortpadded tablesorter" width="80%">
|
||||||
<thead>
|
<thead>
|
||||||
|
|||||||
@@ -558,6 +558,7 @@ def cpdata(workouts, options):
|
|||||||
|
|
||||||
res = interactive_otwcpchart(powerdf,promember=True,rowername=rowername,r=r,
|
res = interactive_otwcpchart(powerdf,promember=True,rowername=rowername,r=r,
|
||||||
cpfit=cpfit,title=title,type=wtype)
|
cpfit=cpfit,title=title,type=wtype)
|
||||||
|
|
||||||
script = res[0]
|
script = res[0]
|
||||||
div = res[1]
|
div = res[1]
|
||||||
p1 = res[2]
|
p1 = res[2]
|
||||||
|
|||||||
@@ -1876,10 +1876,12 @@ def plannedsession_detach_view(request,id=0,psid=0):
|
|||||||
@permission_required('plannedsession.view_session',fn=get_session_by_pk,raise_exception=True)
|
@permission_required('plannedsession.view_session',fn=get_session_by_pk,raise_exception=True)
|
||||||
def plannedsession_view(request,id=0,userid=0):
|
def plannedsession_view(request,id=0,userid=0):
|
||||||
|
|
||||||
|
|
||||||
r = getrequestplanrower(request,userid=userid)
|
r = getrequestplanrower(request,userid=userid)
|
||||||
|
|
||||||
ps = get_object_or_404(PlannedSession,pk=id)
|
ps = get_object_or_404(PlannedSession,pk=id)
|
||||||
|
|
||||||
|
|
||||||
if ps.sessiontype in ['race','indoorrace']:
|
if ps.sessiontype in ['race','indoorrace']:
|
||||||
url = reverse('virtualevent_view',
|
url = reverse('virtualevent_view',
|
||||||
kwargs={'id':ps.id}
|
kwargs={'id':ps.id}
|
||||||
@@ -1974,12 +1976,72 @@ def plannedsession_view(request,id=0,userid=0):
|
|||||||
)
|
)
|
||||||
wdict['distance'] = ps.course.distance
|
wdict['distance'] = ps.course.distance
|
||||||
wdict['coursecompleted'] = False
|
wdict['coursecompleted'] = False
|
||||||
|
|
||||||
|
|
||||||
ranking.append(wdict)
|
ranking.append(wdict)
|
||||||
if ps.sessiontype == 'coursetest':
|
if ps.sessiontype == 'coursetest':
|
||||||
ranking = sorted(ranking, key=lambda k: k['time'])
|
ranking = sorted(ranking, key=lambda k: k['time'])
|
||||||
|
|
||||||
|
if ps.sessiontype == 'fastest_distance':
|
||||||
|
vs = CourseTestResult.objects.filter(plannedsession=ps)
|
||||||
|
|
||||||
|
if vs:
|
||||||
|
for record in vs:
|
||||||
|
userid = record.userid
|
||||||
|
uu = User.objects.get(id=userid)
|
||||||
|
w = Workout.objects.get(id=record.workoutid)
|
||||||
|
wdict = {
|
||||||
|
'name': uu.first_name+' '+uu.last_name,
|
||||||
|
'date': w.date,
|
||||||
|
'distance': record.distance,
|
||||||
|
'type': w.workouttype,
|
||||||
|
'coursecompleted':True,
|
||||||
|
}
|
||||||
|
|
||||||
|
coursecompleted = record.coursecompleted
|
||||||
|
t = record.duration
|
||||||
|
wdict['time'] = datetime.timedelta(
|
||||||
|
hours=t.hour,
|
||||||
|
seconds=t.second,
|
||||||
|
minutes=t.minute,
|
||||||
|
microseconds=t.microsecond
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
wdict['coursecompleted'] = coursecompleted
|
||||||
|
|
||||||
|
ranking.append(wdict)
|
||||||
|
|
||||||
|
ranking = sorted(ranking, key=lambda k: k['time'])
|
||||||
|
if ps.sessiontype == 'fastest_time':
|
||||||
|
vs = CourseTestResult.objects.filter(plannedsession=ps)
|
||||||
|
|
||||||
|
if vs:
|
||||||
|
for record in vs:
|
||||||
|
userid = record.userid
|
||||||
|
uu = User.objects.get(id=userid)
|
||||||
|
w = Workout.objects.get(id=record.workoutid)
|
||||||
|
wdict = {
|
||||||
|
'name': uu.first_name+' '+uu.last_name,
|
||||||
|
'date': w.date,
|
||||||
|
'distance': record.distance,
|
||||||
|
'type': w.workouttype,
|
||||||
|
'coursecompleted':True,
|
||||||
|
}
|
||||||
|
|
||||||
|
coursecompleted = record.coursecompleted
|
||||||
|
t = record.duration
|
||||||
|
wdict['time'] = datetime.timedelta(
|
||||||
|
hours=t.hour,
|
||||||
|
seconds=t.second,
|
||||||
|
minutes=t.minute,
|
||||||
|
microseconds=t.microsecond
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
wdict['coursecompleted'] = coursecompleted
|
||||||
|
|
||||||
|
ranking.append(wdict)
|
||||||
|
ranking = sorted(ranking, key=lambda k: -k['distance'])
|
||||||
|
|
||||||
# if coursetest, need to reorder the ranking
|
# if coursetest, need to reorder the ranking
|
||||||
|
|
||||||
startdate,enddate = get_dates_timeperiod(request)
|
startdate,enddate = get_dates_timeperiod(request)
|
||||||
|
|||||||
Reference in New Issue
Block a user