Compare commits
1 Commits
5f040426a2
...
5d5e0fa4b5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d5e0fa4b5 |
@@ -103,6 +103,14 @@ class Query(graphene.ObjectType):
|
||||
description="Get total count of nodes (with optional transport filter)",
|
||||
)
|
||||
|
||||
nearest_nodes = graphene.List(
|
||||
NodeType,
|
||||
lat=graphene.Float(required=True, description="Latitude"),
|
||||
lon=graphene.Float(required=True, description="Longitude"),
|
||||
limit=graphene.Int(default_value=5, description="Max results"),
|
||||
description="Find nearest logistics nodes to given coordinates",
|
||||
)
|
||||
|
||||
node_connections = graphene.Field(
|
||||
NodeConnectionsType,
|
||||
uuid=graphene.String(required=True),
|
||||
@@ -319,6 +327,41 @@ class Query(graphene.ObjectType):
|
||||
cursor = db.aql.execute(aql, bind_vars={'transport_type': transport_type})
|
||||
return next(cursor, 0)
|
||||
|
||||
def resolve_nearest_nodes(self, info, lat, lon, limit=5):
|
||||
"""Find nearest logistics nodes to given coordinates."""
|
||||
db = get_db()
|
||||
|
||||
# Get all logistics nodes and calculate distance
|
||||
aql = """
|
||||
FOR node IN nodes
|
||||
FILTER node.node_type == 'logistics' OR node.node_type == null
|
||||
FILTER node.latitude != null AND node.longitude != null
|
||||
LET dist = DISTANCE(node.latitude, node.longitude, @lat, @lon) / 1000
|
||||
SORT dist ASC
|
||||
LIMIT @limit
|
||||
RETURN MERGE(node, {distance_km: dist})
|
||||
"""
|
||||
cursor = db.aql.execute(
|
||||
aql,
|
||||
bind_vars={'lat': lat, 'lon': lon, 'limit': limit},
|
||||
)
|
||||
|
||||
nodes = []
|
||||
for node in cursor:
|
||||
nodes.append(NodeType(
|
||||
uuid=node['_key'],
|
||||
name=node.get('name'),
|
||||
latitude=node.get('latitude'),
|
||||
longitude=node.get('longitude'),
|
||||
country=node.get('country'),
|
||||
country_code=node.get('country_code'),
|
||||
synced_at=node.get('synced_at'),
|
||||
transport_types=node.get('transport_types') or [],
|
||||
edges=[],
|
||||
))
|
||||
|
||||
return nodes
|
||||
|
||||
def resolve_node_connections(self, info, uuid, limit_auto=12, limit_rail=12):
|
||||
"""Get auto edges from hub and rail edges from nearest rail node."""
|
||||
db = get_db()
|
||||
|
||||
Reference in New Issue
Block a user