Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/api/geo/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from .models import *
from drf_spectacular.utils import extend_schema_serializer, OpenApiExample
from django.core.exceptions import ObjectDoesNotExist
from drf_writable_nested.serializers import WritableNestedModelSerializer
from drf_writable_nested.mixins import UniqueFieldsMixin

class CRUDLocationTypeSerializer(serializers.ModelSerializer):
class Meta:
Expand Down
1 change: 0 additions & 1 deletion src/api/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ django-storages==1.13.2
django-tinymce==3.6.1
djangorestframework==3.14.0
drf-spectacular==0.26.5
drf-writable-nested==0.7.0
drf-yasg==1.21.7
feedparser==6.0.10
Flask==2.3.2
Expand Down
4 changes: 2 additions & 2 deletions src/api/voyages3/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from django.views.generic import TemplateView

urlpatterns = [
path('admin/', admin.site.urls),
# path('admin/', admin.site.urls),
path('tinymce/', include('tinymce.urls')),
path('voyage/',include('voyage.urls')),
path('timelapse/',include('timelapse.urls')),
Expand All @@ -36,7 +36,7 @@
path('blog/',include('blog.urls')),
path('common/',include('common.urls')),
path('captcha/', include('captcha.urls')),
path('filebrowser/', site.urls),
# path('filebrowser/', site.urls),
path('tinymce/', site.urls),
re_path(r'^_nested_admin/', include('nested_admin.urls')),
path('schema/', SpectacularAPIView.as_view(), name='schema'),
Expand Down
4 changes: 3 additions & 1 deletion src/geo-networks/maps/all_routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ var routeNodes = [
new L.LatLng(42.52069952914966, -70.048828125),
new L.LatLng(40.896905775860006, -71.707763671875),
new L.LatLng(26.745610382199022, -20.7421875),
new L.LatLng(32.48196313217176, -16.7431640625),
new L.LatLng(29.84064389983441, -17.358398437500004),
new L.LatLng(15.749962572748768, -20.2587890625),
new L.LatLng(12.254127737657381, -19.2041015625),
new L.LatLng(36.659606226479696, -9.20654296875),
Expand Down Expand Up @@ -1047,4 +1047,6 @@ var links = [
{ start: 315, end: 317 },
{ start: 317, end: 193 },
{ start: 193, end: 318 },
{ start: 148, end: 69 },
{ start: 150, end: 69 },
];
8 changes: 7 additions & 1 deletion src/geo-networks/maps/ao_routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var routeNodes = [
new L.LatLng(1.537901237431487, 3.8232421875000004),
new L.LatLng(28.806173508854776, -88.76953125),
new L.LatLng(3.0746950723696944, -1.2744140625000002),
new L.LatLng(37.38761749978395, -73.67431640625001),
new L.LatLng(36.56260003738548, -73.67431640625001),
new L.LatLng(37.30027528134433, -65.83443968658294),
new L.LatLng(23.120153621695614, -86.00097656250001),
new L.LatLng(18.104087015773956, -84.28710937500001),
Expand All @@ -36,6 +36,8 @@ var routeNodes = [
new L.LatLng(20.159098270646936, -69.71923828125001),
new L.LatLng(19.02057711096681, -65.41259765625001),
new L.LatLng(16.90968361555865, -60.73242187500001),
new L.LatLng(37.84015683604136, -74.09179687500001),
new L.LatLng(40.84706035607122, -71.67480468750001),
];
var links = [
{ start: 6, end: 7 },
Expand Down Expand Up @@ -84,4 +86,8 @@ var links = [
{ start: 20, end: 35 },
{ start: 10, end: 36 },
{ start: 10, end: 33 },
{ start: 37, end: 27 },
{ start: 27, end: 37 },
{ start: 27, end: 38 },
{ start: 38, end: 27 },
];
58 changes: 55 additions & 3 deletions src/geo-networks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,22 @@ def getclosestneighbor(G,thisnode_id,comp_nodes_ids):
closest_neighbor_distance,closest_neighbor_id=sorted_distances[0]
return closest_neighbor_id,closest_neighbor_distance

def straightab(A,B,ab_id,result):
midx=(A[0]+B[0])/2
midy=(A[1]+B[1])/2
Control=(midx,midy)
result[ab_id]=[[[A, B], [Control, Control]]]
isstraight=True
return result,Control

def curvedab(A,B,C,prev_controlXY,smoothing=0.15):
# print("curving-->",A,B,C,prev_controlXY)
## this function takes 4 xy points (the first [prev] or last [C] being nullable)
## and returns a control point and a next control point for the AB segment
## why this way? because splines that look forward and back not just to points
## but to control points are much, much smoother
# print("curving",A,B,C,prev_controlXY)
overshoot_corrected=False
if prev_controlXY is None:
#first edge
ControlX = B[0] + smoothing*(A[0]-C[0])
Expand All @@ -256,8 +265,10 @@ def curvedab(A,B,C,prev_controlXY,smoothing=0.15):
nextControl=Control
else:
#last edge
lastedge=False
if C is None:
C=B
lastedge=True
#all tother edges
prev_ControlX,prev_ControlY=prev_controlXY
ControlX = A[0]*2 - prev_ControlX
Expand All @@ -266,7 +277,30 @@ def curvedab(A,B,C,prev_controlXY,smoothing=0.15):
next_ControlY = B[1] + smoothing*(A[1]-C[1])
Control=[ControlX,ControlY]
nextControl=[next_ControlX,next_ControlY]
return Control,nextControl

# if lastedge:
#we're getting gross overshoots on our end nodes in some cases (like Annapolis and Madeira)
#can't quite pin down why
#so we're going to flatten those down
dist_A_to_Control=geteuclideandistance(A[1],A[0],Control[1],Control[0])
dist_A_to_nextControl=geteuclideandistance(A[1],A[0],nextControl[1],nextControl[0])
dist_A_to_B=geteuclideandistance(A[1],A[0],B[1],B[0])
mid=[(A[0]+B[0])/2,(A[1]+B[1])/2]
dist_A_to_mid=geteuclideandistance(A[1],A[0],mid[1],mid[0])

if dist_A_to_B < max([dist_A_to_Control,dist_A_to_nextControl]):
overshoot_corrected=True
if dist_A_to_nextControl < dist_A_to_B:
Control=nextControl
elif dist_A_to_Control < dist_A_to_B:
nextControl=Control
else:
Control=mid
nextControl=mid



return Control,nextControl,overshoot_corrected

def straightab(A,B,ab_id,result):
midx=(A[0]+B[0])/2
Expand Down Expand Up @@ -351,6 +385,8 @@ def weightedaverage_tuple(controlpoints):
finalYb=numeratorYb/denominator
return [[finalXa,finalYa],[finalXb,finalYb]]

overshoots_corrected=[]

def spline_curves(nodes,edges,paths,G):
for path in paths:
pathnodes=path['nodes']
Expand All @@ -367,7 +403,14 @@ def spline_curves(nodes,edges,paths,G):
Axy=retrieve_nodeXY(A)
Bxy=retrieve_nodeXY(B)
Cxy=retrieve_nodeXY(C)
this_control,next_control=curvedab(Axy,Bxy,Cxy,prev_controlXY)
this_control,next_control,overshoot_corrected=curvedab(Axy,Bxy,Cxy,prev_controlXY)
if overshoot_corrected:
Aname=A['data'].get('name')
Bname=B['data'].get('name')
if Aname not in overshoots_corrected and Bname not in overshoots_corrected:
print('OVERSHOOT CORRECTED ON',Aname,Bname)
overshoots_corrected.append(Aname)
overshoots_corrected.append(Bname)
edge_id=[A_id,B_id]
edges=add_edge_topathdict(edges,edge_id,this_control,next_control,pathweight)
prev_controlXY=next_control
Expand All @@ -379,8 +422,17 @@ def spline_curves(nodes,edges,paths,G):
Bxy=retrieve_nodeXY(B)
A_id=str(A['id'])
B_id=str(B['id'])
this_control,next_control=curvedab(Axy,Bxy,C,prev_controlXY)
this_control,next_control,overshoot_corrected=curvedab(Axy,Bxy,C,prev_controlXY)
if overshoot_corrected:
Aname=A['data'].get('name')
Bname=B['data'].get('name')
if Aname not in overshoots_corrected and Bname not in overshoots_corrected:
print('OVERSHOOT CORRECTED ON',Aname,Bname)
overshoots_corrected.append(Aname)
overshoots_corrected.append(Bname)

edge_id=[A_id,B_id]

edges=add_edge_topathdict(edges,edge_id,this_control,next_control,pathweight)

elif len(pathnodes)==2:
Expand Down