Skip to content

Commit

Permalink
allow map version to determine tables and funcs to select from
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate-Wessel committed Nov 13, 2024
1 parent d8caffc commit b0f1b0a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
19 changes: 13 additions & 6 deletions backend/app/get_links.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import json
from app.db import getConnection
from psycopg import sql

links_query = '''
WITH results as (
SELECT *
FROM here_gis.get_links_btwn_nodes_22_2(
FROM here_gis.{routing_function}(
%(node_start)s,
%(node_end)s
),
Expand All @@ -20,21 +21,27 @@
streets.source,
streets.target
FROM results
JOIN here.routing_streets_22_2 AS streets USING ( link_dir )
JOIN here_gis.streets_att_22_2 AS attr
JOIN here.{street_geoms_table} AS streets USING ( link_dir )
JOIN here_gis.{street_attributes_table} AS attr
ON attr.link_id::int = left(link_dir, -1)::int
ORDER BY seq;
'''

# returns a json with geometries of links between two nodes
def get_links(from_node_id, to_node_id):
def get_links(from_node_id, to_node_id, map_version):
parsed_links_query = sql.SQL(links_query).format(
routing_function = sql.Identifier(f'get_links_btwn_nodes_{map_version}'),
street_geoms_table = sql.Identifier(f'routing_streets_{map_version}'),
street_attributes_table = sql.Identifier(f'streets_att_{map_version}')
)
with getConnection() as connection:
with connection.cursor() as cursor:
cursor.execute(
links_query,
parsed_links_query,
{
"node_start": from_node_id,
"node_end": to_node_id
"node_end": to_node_id,
"map_version": map_version
}
)

Expand Down
7 changes: 4 additions & 3 deletions backend/app/get_travel_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ def selectMapVersion(start_date, end_date):
with connection:
with connection.cursor() as cursor:
cursor.execute(query,{'start_date':start_date,'end_date':end_date})
print(cursor.fetchall())
(map_version, coverage) = cursor.fetchone()
connection.close()
return map_version

def get_travel_time(start_node, end_node, start_time, end_time, start_date, end_date, include_holidays, dow_list):
"""Function for returning data from the aggregate-travel-times/ endpoint"""

selectMapVersion(start_date, end_date)
map_version = selectMapVersion(start_date, end_date)

holiday_clause = ''
if not include_holidays:
Expand All @@ -77,7 +78,7 @@ def get_travel_time(start_node, end_node, start_time, end_time, start_date, end_
{holiday_clause}
'''

links = get_links(start_node, end_node)
links = get_links(start_node, end_node, map_version)

links_df = pandas.DataFrame({
'link_dir': [l['link_dir'] for l in links],
Expand Down

0 comments on commit b0f1b0a

Please sign in to comment.