non functional mockup stage
This commit is contained in:
@@ -22,6 +22,74 @@ import xml.etree.ElementTree as et
|
||||
from xml.etree.ElementTree import Element, SubElement, Comment, tostring
|
||||
from xml.dom import minidom
|
||||
|
||||
# distance of course from lat_lon in km
|
||||
def howfaris(lat_lon,course):
|
||||
coords = course.coord
|
||||
distance = geo_distance(lat_lon[0],lat_lon[1],coords[0],coords[1])[0]
|
||||
|
||||
return distance
|
||||
|
||||
#whatisnear = 150
|
||||
|
||||
# get nearest races
|
||||
def getnearestraces(lat_lon,races,whatisnear=150):
|
||||
newlist = []
|
||||
counter = 0
|
||||
for race in races:
|
||||
if race.course is None: # pragma: no cover
|
||||
newlist.append(race)
|
||||
else:
|
||||
c = race.course
|
||||
coords = c.coord
|
||||
distance = howfaris(lat_lon,c)
|
||||
if distance < whatisnear:
|
||||
newlist.append(race)
|
||||
counter += 1
|
||||
|
||||
if counter>0:
|
||||
races = newlist
|
||||
else:
|
||||
courseraces = races.exclude(course__isnull=True)
|
||||
orders = [(c.id,howfaris(lat_lon,c.course)) for c in courseraces]
|
||||
orders = sorted(orders,key = lambda tup:tup[1])
|
||||
ids = [id for id,distance in orders[0:4]]
|
||||
for id, distance in orders[5:]: # pragma: no cover
|
||||
if distance<whatisnear:
|
||||
ids.append(id)
|
||||
|
||||
for id in ids:
|
||||
newlist.append(VirtualRace.objects.get(id=id))
|
||||
races = newlist
|
||||
|
||||
return races
|
||||
|
||||
def getnearestcourses(lat_lon,courses,whatisnear=150):
|
||||
newlist = []
|
||||
counter = 0
|
||||
for c in courses:
|
||||
coords = c.coord
|
||||
distance = howfaris(lat_lon,c)
|
||||
if distance < whatisnear:
|
||||
newlist.append(c)
|
||||
counter += 1
|
||||
|
||||
if counter>0:
|
||||
courses = newlist
|
||||
else:
|
||||
orders = [(c.id,howfaris(lat_lon,c)) for c in courses]
|
||||
orders = sorted(orders,key = lambda tup:tup[1])
|
||||
ids = [id for id,distance in orders[0:4]]
|
||||
for id, distance in orders[5:]:
|
||||
if distance<whatisnear: # pragma: no cover
|
||||
ids.append(id)
|
||||
|
||||
for id in ids:
|
||||
newlist.append(GeoCourse.objects.get(id=id))
|
||||
courses = newlist
|
||||
|
||||
return courses
|
||||
|
||||
|
||||
def prettify(elem):
|
||||
"""Return a pretty-printed XML string for the Element.
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user