added navionics (needs to be tested on production)
This commit is contained in:
@@ -729,6 +729,8 @@ def leaflet_chart(lat,lon,name=""):
|
||||
id: 'mapbox.outdoors'
|
||||
}});
|
||||
|
||||
|
||||
|
||||
var mymap = L.map('map_canvas', {{
|
||||
center: [{latmean}, {lonmean}],
|
||||
zoom: 13,
|
||||
@@ -777,6 +779,111 @@ def leaflet_chart(lat,lon,name=""):
|
||||
|
||||
|
||||
|
||||
return script,div
|
||||
|
||||
def leaflet_chart2(lat,lon,name=""):
|
||||
if lat.empty or lon.empty:
|
||||
return [0,"invalid coordinate data"]
|
||||
|
||||
latmean = lat.mean()
|
||||
lonmean = lon.mean()
|
||||
latbegin = lat[lat.index[0]]
|
||||
longbegin = lon[lon.index[0]]
|
||||
latend = lat[lat.index[-1]]
|
||||
longend = lon[lon.index[-1]]
|
||||
|
||||
coordinates = zip(lat,lon)
|
||||
|
||||
scoordinates = "["
|
||||
|
||||
for x,y in coordinates:
|
||||
scoordinates += """[{x},{y}],
|
||||
""".format(
|
||||
x=x,
|
||||
y=y
|
||||
)
|
||||
|
||||
scoordinates += "]"
|
||||
|
||||
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 marker = L.marker([{latbegin}, {longbegin}]).addTo(mymap);
|
||||
marker.bindPopup("<b>Start</b>");
|
||||
var emarker = new L.marker([{latend}, {longend}]).addTo(mymap);
|
||||
emarker.bindPopup("<b>End</b>");
|
||||
|
||||
var latlongs = {scoordinates}
|
||||
var polyline = L.polyline(latlongs, {{color:'red'}}).addTo(mymap)
|
||||
mymap.fitBounds(polyline.getBounds())
|
||||
|
||||
</script>
|
||||
""".format(
|
||||
latmean=latmean,
|
||||
lonmean=lonmean,
|
||||
latbegin = latbegin,
|
||||
latend=latend,
|
||||
longbegin=longbegin,
|
||||
longend=longend,
|
||||
scoordinates=scoordinates,
|
||||
)
|
||||
|
||||
div = """
|
||||
<div id="map_canvas" style="width: 100%; height: 400px;"><p> </p></div>
|
||||
"""
|
||||
|
||||
|
||||
|
||||
return script,div
|
||||
|
||||
def googlemap_chart(lat,lon,name=""):
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
<link rel="stylesheet" href="/static/css/bokeh-0.12.3.min.css" type="text/css" />
|
||||
<link rel="stylesheet" href="/static/css/bokeh-widgets-0.12.3.min.css" type="text/css" />
|
||||
|
||||
<link rel="stylesheet" href="https://webapiv2.navionics.com/dist/webapi/webapi.min.css" >
|
||||
<script type="text/javascript" src="https://webapiv2.navionics.com/dist/webapi/webapi.min.no-dep.js"></script>
|
||||
|
||||
<link rel="shortcut icon" href="/static/img/favicon.ico" type="image/x-icon" />
|
||||
<link rel="icon" sizes="32x32" href="/static/img/favicon-32x32.png" type="image/png"/>
|
||||
<link rel="icon" sizes="64x64" href="/static/img/favicon-64x64.png" type="image/png"/>
|
||||
|
||||
@@ -187,6 +187,7 @@ urlpatterns = [
|
||||
url(r'^workout/compare2/(?P<id1>\d+)/(?P<id2>\d+)/(?P<xparam>\w+.*)/(?P<yparam>\w+.*)/$',views.workout_comparison_view),
|
||||
url(r'^workout/compare/(?P<id>\d+)/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\w+.*)$',views.workout_comparison_list),
|
||||
url(r'^workout/(?P<id>\d+)/edit$',views.workout_edit_view),
|
||||
url(r'^workout/(?P<id>\d+)/navionics$',views.workout_edit_view_navionics),
|
||||
url(r'^workout/(?P<id>\d+)/setprivate$',views.workout_setprivate_view),
|
||||
url(r'^workout/(?P<id>\d+)/updatecp$',views.workout_update_cp_view),
|
||||
url(r'^workout/(?P<id>\d+)/makepublic$',views.workout_makepublic_view),
|
||||
|
||||
169
rowers/views.py
169
rowers/views.py
@@ -6405,6 +6405,175 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
# The basic edit page
|
||||
@login_required()
|
||||
def workout_edit_view_navionics(request,id=0,message="",successmessage=""):
|
||||
request.session[translation.LANGUAGE_SESSION_KEY] = USER_LANGUAGE
|
||||
request.session['referer'] = absolute(request)['PATH']
|
||||
|
||||
|
||||
try:
|
||||
# check if valid ID exists (workout exists)
|
||||
row = Workout.objects.get(id=id)
|
||||
form = WorkoutForm(instance=row)
|
||||
except Workout.DoesNotExist:
|
||||
raise Http404("Workout doesn't exist")
|
||||
|
||||
if request.method == 'POST':
|
||||
# Form was submitted
|
||||
form = WorkoutForm(request.POST)
|
||||
if form.is_valid():
|
||||
# Get values from form
|
||||
name = form.cleaned_data['name']
|
||||
date = form.cleaned_data['date']
|
||||
starttime = form.cleaned_data['starttime']
|
||||
workouttype = form.cleaned_data['workouttype']
|
||||
duration = form.cleaned_data['duration']
|
||||
distance = form.cleaned_data['distance']
|
||||
notes = form.cleaned_data['notes']
|
||||
thetimezone = form.cleaned_data['timezone']
|
||||
try:
|
||||
boattype = request.POST['boattype']
|
||||
except KeyError:
|
||||
boattype = Workout.objects.get(id=id).boattype
|
||||
try:
|
||||
privacy = request.POST['privacy']
|
||||
except KeyError:
|
||||
privacy = Workout.objects.get(id=id).privacy
|
||||
try:
|
||||
rankingpiece = form.cleaned_data['rankingpiece']
|
||||
except KeyError:
|
||||
rankingpiece =- Workout.objects.get(id=id).rankingpiece
|
||||
|
||||
startdatetime = (str(date) + ' ' + str(starttime))
|
||||
startdatetime = datetime.datetime.strptime(startdatetime,
|
||||
"%Y-%m-%d %H:%M:%S")
|
||||
startdatetime = timezone.make_aware(startdatetime)
|
||||
startdatetime = startdatetime.astimezone(pytz.timezone(thetimezone))
|
||||
|
||||
|
||||
# check if user is owner of this workout
|
||||
if checkworkoutuser(request.user,row):
|
||||
row.name = name
|
||||
row.date = date
|
||||
row.starttime = starttime
|
||||
row.startdatetime = startdatetime
|
||||
row.workouttype = workouttype
|
||||
row.notes = notes
|
||||
row.duration = duration
|
||||
row.distance = distance
|
||||
row.boattype = boattype
|
||||
row.privacy = privacy
|
||||
row.rankingpiece = rankingpiece
|
||||
row.timezone = thetimezone
|
||||
try:
|
||||
row.save()
|
||||
except IntegrityError:
|
||||
pass
|
||||
# change data in csv file
|
||||
|
||||
r = rdata(row.csvfilename)
|
||||
if r == 0:
|
||||
return HttpResponse("Error: CSV Data File Not Found")
|
||||
r.rowdatetime = startdatetime
|
||||
r.write_csv(row.csvfilename,gzip=True)
|
||||
dataprep.update_strokedata(id,r.df)
|
||||
successmessage = "Changes saved"
|
||||
messages.info(request,successmessage)
|
||||
url = reverse(workout_edit_view,
|
||||
kwargs = {
|
||||
'id':str(row.id),
|
||||
})
|
||||
response = HttpResponseRedirect(url)
|
||||
else:
|
||||
message = "You are not allowed to change this workout"
|
||||
messages.error(request,message)
|
||||
url = reverse(workouts_view)
|
||||
|
||||
response = HttpResponseRedirect(url)
|
||||
|
||||
#else: # form not POSTed
|
||||
form = WorkoutForm(instance=row)
|
||||
|
||||
|
||||
try:
|
||||
row = Workout.objects.get(id=id)
|
||||
except Workout.DoesNotExist:
|
||||
raise Http404("Workout doesn't exist")
|
||||
|
||||
g = GraphImage.objects.filter(workout=row).order_by("-creationdatetime")
|
||||
# check if user is owner of this workout
|
||||
|
||||
comments = WorkoutComment.objects.filter(workout=row)
|
||||
|
||||
aantalcomments = len(comments)
|
||||
|
||||
if (checkworkoutuser(request.user,row)==False):
|
||||
raise Http404("You are not allowed to edit this workout")
|
||||
|
||||
# create interactive plot
|
||||
f1 = row.csvfilename
|
||||
u = row.user.user
|
||||
r = getrower(u)
|
||||
rowdata = rdata(f1)
|
||||
hascoordinates = 1
|
||||
if rowdata != 0:
|
||||
try:
|
||||
latitude = rowdata.df[' latitude']
|
||||
if not latitude.std():
|
||||
hascoordinates = 0
|
||||
except KeyError,AttributeError:
|
||||
hascoordinates = 0
|
||||
|
||||
else:
|
||||
hascoordinates = 0
|
||||
|
||||
|
||||
if hascoordinates:
|
||||
mapscript,mapdiv = leaflet_chart2(rowdata.df[' latitude'],
|
||||
rowdata.df[' longitude'],
|
||||
row.name)
|
||||
|
||||
#res = googlemap_chart(rowdata.df[' latitude'],
|
||||
# rowdata.df[' longitude'],
|
||||
# row.name)
|
||||
#gmscript = res[0]
|
||||
#gmdiv = res[1]
|
||||
|
||||
else:
|
||||
mapscript = ""
|
||||
mapdiv = ""
|
||||
|
||||
|
||||
# render page
|
||||
if (len(g)<=3):
|
||||
return render(request, 'workout_form.html',
|
||||
{'form':form,
|
||||
'workout':row,
|
||||
'teams':get_my_teams(request.user),
|
||||
'graphs1':g[0:3],
|
||||
'mapscript':mapscript,
|
||||
'aantalcomments':aantalcomments,
|
||||
'mapdiv':mapdiv,
|
||||
})
|
||||
|
||||
else:
|
||||
return render(request, 'workout_form.html',
|
||||
{'form':form,
|
||||
'teams':get_my_teams(request.user),
|
||||
'workout':row,
|
||||
'graphs1':g[0:3],
|
||||
'graphs2':g[3:6],
|
||||
'mapscript':mapscript,
|
||||
'aantalcomments':aantalcomments,
|
||||
'mapdiv':mapdiv,
|
||||
})
|
||||
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
|
||||
|
||||
# Create the chart image with wind corrected pace (OTW)
|
||||
@user_passes_test(ispromember,login_url="/",redirect_field_name=None)
|
||||
def workout_add_otw_powerplot_view(request,id):
|
||||
|
||||
Reference in New Issue
Block a user