Merge branch 'release/v5.95'
This commit is contained in:
+62
-26
@@ -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
|
||||
@@ -119,7 +120,7 @@ def time_in_path(df,p,maxmin='max'):
|
||||
b = (~df['inpolygon']).shift(1)+df['inpolygon']
|
||||
|
||||
if len(df[b==2]):
|
||||
return df[b==2]['time'].min()
|
||||
return df[b==2]['time'].min(),df[b==2]['cum_dist'].min()
|
||||
|
||||
raise InvalidTrajectoryError("Trajectory doesn't go through path")
|
||||
|
||||
@@ -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,9 +227,25 @@ def createcourse(
|
||||
|
||||
return c
|
||||
|
||||
def coursetime_paths(data,paths):
|
||||
def coursetime_first(data,paths):
|
||||
|
||||
entrytime = data['time'].max()
|
||||
entrydistance = data['cum_dist'].max()
|
||||
coursecompleted = False
|
||||
|
||||
try:
|
||||
entrytime,entrydistance = time_in_path(data,paths[0],maxmin='max')
|
||||
coursecompleted = True
|
||||
except InvalidTrajectoryError:
|
||||
entrytime = data['time'].max()
|
||||
entrydistance = data['cum_dist'].max()
|
||||
coursecompleted = False
|
||||
return entrytime, entrydistance, coursecompleted
|
||||
|
||||
def coursetime_paths(data,paths,finalmaxmin='min'):
|
||||
|
||||
entrytime = data['time'].max()
|
||||
entrydistance = data['cum_dist'].max()
|
||||
coursecompleted = False
|
||||
|
||||
# corner case - empty list of paths
|
||||
@@ -239,34 +255,42 @@ 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,
|
||||
entrydistance
|
||||
) = time_in_path(data,paths[0],maxmin=finalmaxmin)
|
||||
coursecompleted = True
|
||||
print entrytime
|
||||
except InvalidTrajectoryError:
|
||||
entrytime = data['time'].max()
|
||||
entrydistance = data['cum_dist'].max()
|
||||
coursecompleted = False
|
||||
return entrytime,coursecompleted
|
||||
return entrytime,entrydistance,coursecompleted
|
||||
|
||||
if len(paths) > 1:
|
||||
try:
|
||||
time = time_in_path(data, paths[0])
|
||||
time,dist = 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
|
||||
data['cum_dist'] = data['cum_dist']-dist
|
||||
(
|
||||
timenext,
|
||||
distnext,
|
||||
coursecompleted
|
||||
) = coursetime_paths(data,paths[1:])
|
||||
return time+timenext, dist+distnext,coursecompleted
|
||||
except InvalidTrajectoryError:
|
||||
entrytime = data['time'].max()
|
||||
entrydistance = data['cum_dist'].max()
|
||||
coursecompleted = False
|
||||
|
||||
return entrytime, coursecompleted
|
||||
return entrytime, entrydistance, coursecompleted
|
||||
|
||||
def get_time_course(ws,course):
|
||||
coursetimeseconds = 0.0
|
||||
coursecompleted = 0
|
||||
|
||||
w = ws[0]
|
||||
columns = ['time',' latitude',' longitude']
|
||||
columns = ['time',' latitude',' longitude','cum_dist']
|
||||
rowdata = dataprep.getsmallrowdata_db(
|
||||
columns,
|
||||
ids = [w.id],
|
||||
@@ -292,8 +316,20 @@ def get_time_course(ws,course):
|
||||
path = polygon_to_path(polygon)
|
||||
paths.append(path)
|
||||
|
||||
coursetimeseconds,coursecompleted = coursetime_paths(rowdata,paths)
|
||||
(
|
||||
coursetimeseconds,
|
||||
coursemeters,
|
||||
coursecompleted,
|
||||
|
||||
print 'course time?',coursetimeseconds
|
||||
) = coursetime_paths(rowdata,paths)
|
||||
(
|
||||
coursetimefirst,
|
||||
coursemetersfirst,
|
||||
firstcompleted
|
||||
) = coursetime_first(
|
||||
rowdata,paths)
|
||||
|
||||
return coursetimeseconds,coursecompleted
|
||||
coursetimeseconds = coursetimeseconds-coursetimefirst
|
||||
coursemeters = coursemeters-coursemetersfirst
|
||||
|
||||
return coursetimeseconds,coursemeters,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))
|
||||
@@ -237,7 +238,11 @@ def is_session_complete_ws(ws,ps):
|
||||
return ratio,'partial',completiondate
|
||||
elif ps.sessiontype == 'coursetest':
|
||||
if ps.course:
|
||||
coursetime,coursecompleted = courses.get_time_course(ws,ps.course)
|
||||
(
|
||||
coursetime,
|
||||
coursemeters,
|
||||
coursecompleted
|
||||
) = courses.get_time_course(ws,ps.course)
|
||||
if coursecompleted:
|
||||
return 1.0,'completed',completiondate
|
||||
else:
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
<td>{{ forloop.counter }}</td>
|
||||
<td>{{ result|lookup:'name' }}</td>
|
||||
<td>{{ result|lookup:'distance' }}</td>
|
||||
<td>{{ result|lookup:'time'|durationprint:"%H:%M:%S.%f" }}</td>
|
||||
<td>{{ result|lookup:'time'|deltatimeprint }}</td>
|
||||
<td>{{ result|lookup:'date'|date:"Y-m-d" }}</td>
|
||||
<td>{{ result|lookup:'type' }}</td>
|
||||
</tr>
|
||||
|
||||
+26
-2
@@ -12657,15 +12657,39 @@ def plannedsession_view(request,id=0,rowerid=0,
|
||||
rankws = Workout.objects.filter(
|
||||
plannedsession=ps).order_by("-distance")
|
||||
for w in rankws:
|
||||
dd = w.duration
|
||||
dddelta = datetime.timedelta(hours=dd.hour,
|
||||
minutes=dd.minute,
|
||||
seconds=dd.second,
|
||||
microseconds=dd.microsecond)
|
||||
wdict = {
|
||||
'name': w.user.user.first_name+' '+w.user.user.last_name,
|
||||
'date': w.date,
|
||||
'distance': w.distance,
|
||||
'time': w.duration,
|
||||
'time': dddelta,
|
||||
'type': w.workouttype,
|
||||
}
|
||||
ranking.append(wdict)
|
||||
if ps.sessiontype == 'coursetest':
|
||||
(
|
||||
coursetimeseconds,
|
||||
coursemeters,
|
||||
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
|
||||
)
|
||||
wdict['distance'] = int(round(coursemeters))
|
||||
|
||||
|
||||
ranking.append(wdict)
|
||||
if ps.sessiontype == 'coursetest':
|
||||
ranking = sorted(ranking, key=lambda k: k['time'])
|
||||
|
||||
# if coursetest, need to reorder the ranking
|
||||
|
||||
return render(request,'plannedsessionview.html',
|
||||
{
|
||||
|
||||
@@ -32,6 +32,7 @@ handler500 = 'rowers.views.error500_view'
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^admin/jsi18n', 'django.views.i18n.javascript_catalog'),
|
||||
url(r'^django-rq/',include('django_rq.urls')),
|
||||
url(r'^password_change_done/$',auth_views.password_change_done,name='password_change_done'),
|
||||
url(r'^password_change/$',auth_views.password_change),
|
||||
|
||||
Reference in New Issue
Block a user