Private
Public Access
1
0

list course view

This commit is contained in:
Sander Roosendaal
2018-02-19 17:28:59 +01:00
parent 753673a0ce
commit 78c488efe7
7 changed files with 234 additions and 5 deletions

View File

@@ -14,6 +14,8 @@ from utils import myqueue
from matplotlib import path from matplotlib import path
import xml.etree.ElementTree as et import xml.etree.ElementTree as et
import pandas as pd
ns = {'opengis': 'http://www.opengis.net/kml/2.2'} ns = {'opengis': 'http://www.opengis.net/kml/2.2'}
import django_rq import django_rq
@@ -34,8 +36,59 @@ class InvalidTrajectoryError(Exception):
def __str__(self): def __str__(self):
return repr(self.value) return repr(self.value)
def polygon_coord_center(polygon):
points = GeoPoint.objects.filter(polygon=polygon).order_by("order_in_poly")
latitudes = pd.Series([p.latitude for p in points])
longitudes = pd.Series([p.longitude for p in points])
return latitudes.mean(), longitudes.mean()
def course_coord_center(course):
polygons = GeoPolygon.objects.filter(course=course).order_by("order_in_course")
latitudes = []
longitudes = []
for p in polygons:
latitude,longitude = polygon_coord_center(p)
latitudes.append(latitude)
longitudes.append(longitude)
latitude = pd.Series(latitudes).median()
longitude = pd.Series(longitudes).median()
coordinates = pd.DataFrame({
'latitude':latitudes,
'longitude':longitudes,
})
return latitude,longitude,coordinates
def course_coord_maxmin(course):
polygons = GeoPolygon.objects.filter(course=course).order_by("order_in_course")
latitudes = []
longitudes = []
for p in polygons:
latitude,longitude = polygon_coord_center(p)
latitudes.append(latitude)
longitudes.append(longitude)
lat_min = pd.Series(latitudes).min()
lat_max = pd.Series(latitudes).max()
long_min = pd.Series(longitudes).min()
long_max = pd.Series(longitudes).max()
return lat_min,lat_max,long_min,long_max
def polygon_to_path(polygon): def polygon_to_path(polygon):
points = GeoPoint.objects.filter(polygon==polygon).order_by(order_in_polygon) points = GeoPoint.objects.filter(polygon==polygon).order_by("order_in_polygon")
s = [] s = []
for point in points: for point in points:
s.append([point.latitude,point.longitude]) s.append([point.latitude,point.longitude])

View File

@@ -1,5 +1,8 @@
import colorsys import colorsys
from rowers.models import Workout, User, Rower, WorkoutForm,RowerForm,GraphImage from rowers.models import (
Workout, User, Rower, WorkoutForm,RowerForm,
GraphImage,GeoPolygon,GeoCourse,GeoPoint
)
from rowingdata import rower as rrower from rowingdata import rower as rrower
from rowingdata import main as rmain from rowingdata import main as rmain
from rowingdata import cumcpdata,histodata from rowingdata import cumcpdata,histodata
@@ -35,6 +38,10 @@ from bokeh.core.properties import value
from collections import OrderedDict from collections import OrderedDict
from django.conf import settings from django.conf import settings
from courses import (
course_coord_center,course_coord_maxmin,
)
import datetime import datetime
import math import math
import numpy as np import numpy as np
@@ -707,6 +714,124 @@ def interactive_histoall(theworkouts):
script, div = components(plot) script, div = components(plot)
return [script,div] return [script,div]
def course_map(course):
latmean,lonmean,coordinates = course_coord_center(course)
lat_min, lat_max, long_min, long_max = course_coord_maxmin(course)
scoordinates = "["
for index,row in coordinates.iterrows():
scoordinates += """[{x},{y}],
""".format(
x=row['latitude'],
y=row['longitude']
)
scoordinates +="]"
polygons = GeoPolygon.objects.filter(course=course).order_by("order_in_course")
pcoordinates = """[
"""
for p in polygons:
pcoordinates += """[
["""
points = GeoPoint.objects.filter(polygon=p).order_by("order_in_poly")
for pt in points:
pcoordinates += "[{x},{y}],".format(
x = pt.latitude,
y = pt.longitude
)
# remove last comma
pcoordinates = pcoordinates[:-1]
pcoordinates += """]
],
"""
pcoordinates += """
]"""
print pcoordinates
script = """
<script>
var streets = L.tileLayer('https://api.tiles.mapbox.com/v4/{{id}}/{{z}}/{{x}}/{{y}}.png?access_token=pk.eyJ1Ijoic2FuZGVycm9vc2VuZGFhbCIsImEiOiJjajY3aTRkeWQwNmx6MzJvMTN3andlcnBlIn0.MFG8Xt0kDeSA9j7puZQ9hA', {{
maxZoom: 18,
id: 'mapbox.streets'
}}),
satellite = L.tileLayer('https://api.tiles.mapbox.com/v4/{{id}}/{{z}}/{{x}}/{{y}}.png?access_token=pk.eyJ1Ijoic2FuZGVycm9vc2VuZGFhbCIsImEiOiJjajY3aTRkeWQwNmx6MzJvMTN3andlcnBlIn0.MFG8Xt0kDeSA9j7puZQ9hA', {{
maxZoom: 18,
id: 'mapbox.satellite'
}}),
outdoors = L.tileLayer('https://api.tiles.mapbox.com/v4/{{id}}/{{z}}/{{x}}/{{y}}.png?access_token=pk.eyJ1Ijoic2FuZGVycm9vc2VuZGFhbCIsImEiOiJjajY3aTRkeWQwNmx6MzJvMTN3andlcnBlIn0.MFG8Xt0kDeSA9j7puZQ9hA', {{
maxZoom: 18,
id: 'mapbox.outdoors'
}});
var mymap = L.map('map_canvas', {{
center: [{latmean}, {lonmean}],
zoom: 13,
layers: [streets, satellite]
}}).setView([{latmean},{lonmean}], 13);
var navionics = new JNC.Leaflet.NavionicsOverlay({{
navKey: 'Navionics_webapi_03205',
chartType: JNC.NAVIONICS_CHARTS.NAUTICAL,
isTransparent: true,
zIndex: 1
}});
var osmUrl2='http://tiles.openseamap.org/seamark/{{z}}/{{x}}/{{y}}.png';
var osmUrl='http://{{s}}.tile.openstreetmap.org/{{z}}/{{x}}/{{y}}.png';
//create two TileLayer
var nautical=new L.TileLayer(osmUrl,{{
maxZoom:18}});
L.control.layers({{
"Streets": streets,
"Satellite": satellite,
"Outdoors": outdoors,
"Nautical": nautical,
}},{{
"Navionics":navionics,
}}).addTo(mymap);
var latlongs = {scoordinates}
var polyline = L.polyline(latlongs, {{color:'red'}}).addTo(mymap)
mymap.fitBounds(polyline.getBounds())
var platlongs = {pcoordinates}
var polygons = L.polygon(platlongs, {{color:'blue'}}).addTo(mymap)
</script>
""".format(
latmean=latmean,
lonmean=lonmean,
scoordinates=scoordinates,
pcoordinates=pcoordinates
)
div = """
<div id="map_canvas" style="width: 100%; height: 400px;"><p>&nbsp;</p></div>
"""
return script,div
def leaflet_chart(lat,lon,name=""): def leaflet_chart(lat,lon,name=""):
if lat.empty or lon.empty: if lat.empty or lon.empty:

View File

@@ -0,0 +1 @@
E408191@CZ27LT9RCGN72.9092:1519040360

View File

@@ -0,0 +1,24 @@
{% extends "base.html" %}
{% load staticfiles %}
{% load rowerfilters %}
{% block scripts %}
{% include "monitorjobs.html" %}
{% endblock %}
{% block title %}{{ course.name }} {% endblock %}
{% block og_title %}{{ course.name }} {% endblock %}
{% block content %}
<div class="grid_12 alpha">
<h1>{{ course.name }}</h1>
{{ mapdiv|safe }}
{{ mapscript|safe }}
</div>
{% endblock %}

View File

@@ -32,8 +32,14 @@
</thead> </thead>
<tbody> <tbody>
{% for course in courses %} {% for course in courses %}
<td> {{ course.country }} </td> <td> {{ course.country }} </td>
<td> {{ course.name }} </td> <td>
{% if course.manager.user == user %}
<a href="/rowers/courses/{{ course.id }}/edit">{{ course.name }}</a>
{% else %}
<a href="/rowers/courses/{{ course.id }}">{{ course.name }}</a>
{% endif %}
</td>
</tr> </tr>

View File

@@ -485,6 +485,8 @@ urlpatterns = [
url(r'^sessions/rower/(?P<rowerid>\d+)$',views.plannedsessions_view), url(r'^sessions/rower/(?P<rowerid>\d+)$',views.plannedsessions_view),
url(r'^sessions/(?P<timeperiod>[\w\ ]+.*)/rower/(?P<rowerid>\d+)$',views.plannedsessions_view), url(r'^sessions/(?P<timeperiod>[\w\ ]+.*)/rower/(?P<rowerid>\d+)$',views.plannedsessions_view),
url(r'^sessions/(?P<timeperiod>[\w\ ]+.*)$',views.plannedsessions_view), url(r'^sessions/(?P<timeperiod>[\w\ ]+.*)$',views.plannedsessions_view),
url(r'^courses/(?P<id>\d+)/edit$',views.course_edit_view,
name='course_edit_view'),
] ]
if settings.DEBUG: if settings.DEBUG:

View File

@@ -8404,7 +8404,25 @@ def workout_comment_view(request,id=0):
'comments':comments, 'comments':comments,
'form':form, 'form':form,
}) })
@login_required()
def course_edit_view(request,id=0):
try:
course = GeoCourse.objects.get(id=id)
except GeoCourse.DoesNotExist:
return Http404("Course doesn't exist")
script,div = course_map(course)
return render(request, 'course_view.html',
{
'course':course,
'mapscript':script,
'mapdiv':div,
}
)
# The basic edit page # The basic edit page
@login_required() @login_required()