work in progress - need to convert course time to datetime
This commit is contained in:
@@ -9,6 +9,7 @@ from django.db import IntegrityError
|
||||
import uuid
|
||||
from django.conf import settings
|
||||
|
||||
import geocoder
|
||||
|
||||
from matplotlib import path
|
||||
import xml.etree.ElementTree as et
|
||||
@@ -186,8 +187,6 @@ def kmltocourse(f):
|
||||
return get_polygons(polygonpms)
|
||||
|
||||
|
||||
from geopy.geocoders import Nominatim
|
||||
geolocator = Nominatim()
|
||||
|
||||
|
||||
def createcourse(
|
||||
@@ -203,16 +202,17 @@ def createcourse(
|
||||
j = 0
|
||||
for point in p['points']:
|
||||
if i==0 and j==0:
|
||||
try:
|
||||
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')
|
||||
except GeocoderInsufficientPrivileges:
|
||||
country = "Unknown Country"
|
||||
|
||||
latitude = point['latitude']
|
||||
longitude = point['longitude']
|
||||
g = geocoder.google([latitude,longitude],method='reverse')
|
||||
if g.ok:
|
||||
address = g.raw['address_components']
|
||||
country = 'unknown'
|
||||
for a in address:
|
||||
if 'country' in a['types']:
|
||||
country = a['long_name']
|
||||
else:
|
||||
country = 'unknown'
|
||||
c.country = country
|
||||
c.save()
|
||||
obj = GeoPoint(
|
||||
@@ -227,7 +227,20 @@ def createcourse(
|
||||
|
||||
return c
|
||||
|
||||
def coursetime_paths(data,paths):
|
||||
def coursetime_first(data,paths):
|
||||
|
||||
entrytime = data['time'].max()
|
||||
coursecompleted = False
|
||||
|
||||
try:
|
||||
entrytime = time_in_path(data,paths[0],maxmin='max')
|
||||
coursecompleted = True
|
||||
except InvalidTrajectoryError:
|
||||
entrytime = data['time'].max()
|
||||
coursecompleted = False
|
||||
return entrytime, coursecompleted
|
||||
|
||||
def coursetime_paths(data,paths,finalmaxmin='min'):
|
||||
|
||||
entrytime = data['time'].max()
|
||||
coursecompleted = False
|
||||
@@ -239,9 +252,8 @@ def coursetime_paths(data,paths):
|
||||
# end - just the Finish polygon
|
||||
if len(paths) == 1:
|
||||
try:
|
||||
entrytime = time_in_path(data,paths[0],maxmin='min')
|
||||
entrytime = time_in_path(data,paths[0],maxmin=finalmaxmin)
|
||||
coursecompleted = True
|
||||
print entrytime
|
||||
except InvalidTrajectoryError:
|
||||
entrytime = data['time'].max()
|
||||
coursecompleted = False
|
||||
@@ -252,7 +264,6 @@ def coursetime_paths(data,paths):
|
||||
time = time_in_path(data, paths[0])
|
||||
data = data[data['time']>time]
|
||||
data['time'] = data['time']-time
|
||||
print time
|
||||
timenext, coursecompleted = coursetime_paths(data,paths[1:])
|
||||
return time+timenext, coursecompleted
|
||||
except InvalidTrajectoryError:
|
||||
@@ -293,7 +304,9 @@ def get_time_course(ws,course):
|
||||
paths.append(path)
|
||||
|
||||
coursetimeseconds,coursecompleted = coursetime_paths(rowdata,paths)
|
||||
coursetimefirst,firstcompleted = coursetime_first(
|
||||
rowdata,paths)
|
||||
|
||||
print 'course time?',coursetimeseconds
|
||||
coursetimeseconds = coursetimeseconds-coursetimefirst
|
||||
|
||||
return coursetimeseconds,coursecompleted
|
||||
|
||||
@@ -121,6 +121,7 @@ def get_session_metrics(ps):
|
||||
completedatev = ''
|
||||
durationv /= 60.
|
||||
|
||||
|
||||
trimp.append(int(trimpv))
|
||||
duration.append(int(durationv))
|
||||
distance.append(int(distancev))
|
||||
|
||||
@@ -12664,8 +12664,20 @@ def plannedsession_view(request,id=0,rowerid=0,
|
||||
'time': w.duration,
|
||||
'type': w.workouttype,
|
||||
}
|
||||
if ps.sessiontype == 'coursetest':
|
||||
coursetimeseconds,coursecompleted = courses.get_time_course(ws,ps.course)
|
||||
intsecs = int(coursetimeseconds)
|
||||
microsecs = int(1.e6*(coursetimeseconds-intsecs))
|
||||
|
||||
wdict['time'] = datetime.timedelta(
|
||||
seconds=intsecs,
|
||||
microseconds=microsecs
|
||||
)
|
||||
|
||||
|
||||
ranking.append(wdict)
|
||||
|
||||
|
||||
# if coursetest, need to reorder the ranking
|
||||
|
||||
return render(request,'plannedsessionview.html',
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user