routine to find shortest course completion
If rowing through start box more than 1 time, it checks for every passing of the start box
This commit is contained in:
@@ -33,7 +33,7 @@ from rowers.models import (
|
||||
)
|
||||
|
||||
from utils import geo_distance
|
||||
from rowers.courseutils import coursetime_paths, coursetime_first
|
||||
from rowers.courseutils import coursetime_paths, coursetime_first,time_in_path
|
||||
|
||||
|
||||
|
||||
@@ -199,12 +199,16 @@ def get_time_course(ws,course):
|
||||
rowdata = rowdata.resample('100ms',on='dt').mean()
|
||||
rowdata = rowdata.interpolate()
|
||||
|
||||
# create path
|
||||
polygons = GeoPolygon.objects.filter(course=course).order_by("order_in_course")
|
||||
paths = []
|
||||
for polygon in polygons:
|
||||
path = polygon_to_path(polygon)
|
||||
paths.append(path)
|
||||
|
||||
|
||||
|
||||
|
||||
(
|
||||
coursetimeseconds,
|
||||
coursemeters,
|
||||
|
||||
@@ -10,7 +10,7 @@ class InvalidTrajectoryError(Exception):
|
||||
def __str__(self):
|
||||
return repr(self.value)
|
||||
|
||||
def time_in_path(df,p,maxmin='max'):
|
||||
def time_in_path(df,p,maxmin='max',getall=False):
|
||||
|
||||
if df.empty:
|
||||
return 0
|
||||
@@ -29,7 +29,10 @@ def time_in_path(df,p,maxmin='max'):
|
||||
|
||||
|
||||
if len(df[b==2]):
|
||||
return df[b==2]['time'].min(),df[b==2]['cum_dist'].min()
|
||||
if getall:
|
||||
return df[b==2]['time'],df[b==2]['cum_dist']
|
||||
else:
|
||||
return df[b==2]['time'].min(),df[b==2]['cum_dist'].min()
|
||||
|
||||
raise InvalidTrajectoryError("Trajectory doesn't go through path")
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ siteurl = SITE_URL
|
||||
# testing task
|
||||
|
||||
from rowers.emails import send_template_email
|
||||
from rowers.courseutils import coursetime_paths, coursetime_first
|
||||
from rowers.courseutils import coursetime_paths, coursetime_first, time_in_path
|
||||
|
||||
@app.task
|
||||
def add(x, y):
|
||||
@@ -276,21 +276,56 @@ def handle_check_race_course(self,
|
||||
path = polygon_to_path(polygon,debug=debug)
|
||||
paths.append(path)
|
||||
|
||||
(
|
||||
coursetimeseconds,
|
||||
coursemeters,
|
||||
coursecompleted,
|
||||
|
||||
) = coursetime_paths(rowdata,paths)
|
||||
(
|
||||
coursetimefirst,
|
||||
coursemetersfirst,
|
||||
firstcompleted
|
||||
) = coursetime_first(
|
||||
rowdata,paths)
|
||||
# check how many times went through start polygon
|
||||
entrytimes,entrydistances = time_in_path(rowdata,paths[0],maxmin='max',getall=True)
|
||||
|
||||
coursetimeseconds = coursetimeseconds-coursetimefirst
|
||||
coursemeters = coursemeters-coursemetersfirst
|
||||
cseconds = []
|
||||
cmeters = []
|
||||
ccomplete = []
|
||||
|
||||
for startt in entrytimes:
|
||||
|
||||
rowdata2 = rowdata[rowdata['time']>(startt-10.)]
|
||||
|
||||
(
|
||||
coursetimeseconds,
|
||||
coursemeters,
|
||||
coursecompleted,
|
||||
|
||||
) = coursetime_paths(rowdata2,paths)
|
||||
(
|
||||
coursetimefirst,
|
||||
coursemetersfirst,
|
||||
firstcompleted
|
||||
) = coursetime_first(
|
||||
rowdata2,paths)
|
||||
|
||||
|
||||
|
||||
coursetimeseconds = coursetimeseconds-coursetimefirst
|
||||
coursemeters = coursemeters-coursemetersfirst
|
||||
|
||||
cseconds.append(coursetimeseconds)
|
||||
cmeters.append(coursemeters)
|
||||
ccomplete.append(coursecompleted)
|
||||
|
||||
|
||||
records = pd.DataFrame({
|
||||
'coursetimeseconds':cseconds,
|
||||
'coursecompleted': ccomplete,
|
||||
'coursemeters': cmeters
|
||||
})
|
||||
|
||||
records = records[records['coursecompleted'] == True]
|
||||
|
||||
if len(records):
|
||||
coursecompleted = True
|
||||
mintime = records['coursetimeseconds'].min()
|
||||
coursetimeseconds = records[records['coursetimeseconds'] == mintime]['coursetimeseconds'].min()
|
||||
coursemeters = records[records['coursetimeseconds'] == mintime]['coursemeters'].min()
|
||||
else:
|
||||
coursecompleted = False
|
||||
|
||||
|
||||
if coursecompleted:
|
||||
query = 'UPDATE rowers_virtualraceresult SET coursecompleted = 1, duration = "{duration}", distance = {distance}, workoutid = {workoutid} WHERE id={recordid}'.format(
|
||||
|
||||
Reference in New Issue
Block a user