Skip to content

Commit

Permalink
misc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate-Wessel committed Oct 24, 2023
1 parent 2fa2070 commit 8ce83ff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
3 changes: 2 additions & 1 deletion backend/app/get_travel_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def get_travel_time(start_node, end_node, start_time, end_time, start_date, end_
WHERE
cn.segment_id::integer IN %(seglist)s
AND cn.hr <@ %(time_range)s::numrange
AND date_part('isodow', cn.dt)::integer IN %(dow_list)s
AND date_part('ISODOW', cn.dt)::integer IN %(dow_list)s
AND cn.dt <@ %(date_range)s::daterange
{holiday_subquery}
GROUP BY
Expand Down Expand Up @@ -63,6 +63,7 @@ def get_travel_time(start_node, end_node, start_time, end_time, start_date, end_
"seglist": tuple(seglist),
"node_start": start_node,
"node_end": end_node,
# this is where we define that the end of the range is exclusive
"time_range": f"[{start_time},{end_time})", # ints
"date_range": f"[{start_date},{end_date})", # 'YYYY-MM-DD'
"dow_list": tuple(dow_list)
Expand Down
36 changes: 12 additions & 24 deletions backend/app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,11 @@ def get_links_between_two_nodes(from_node_id, to_node_id):
'/aggregate-travel-times/<start_node>/<end_node>/<start_time>/<end_time>/<start_date>/<end_date>/<include_holidays>/<dow_str>',
methods=['GET']
)
# aggregate_travel_times()
#
# Params:
# - start_node(int): the node_id of the starting node
# - end_node(int): the node_id of the end node
# - start_time(int): starting hour of aggregation
# - end_time(int): end hour of aggregation (exclusive)
# - start_date(datetime): start date of aggregation
# - end_date(datetime): end date of aggregation (exclusive)
# - include_holidays(str): Set to 'true' to include holidays in aggregation, otherwise 'false' to exclude holidays.
# - dow_list(str): flattened list of integers, i.e. [1,2,3,4] -> '1234', representing days of week to be included
#
# - start_node, end_node (int): the congestion network / HERE node_id's
# - start_time, end_time (int): starting (inclusive), ending (exclusive) hours of aggregation
# - start_date, end_date (YYYY-MM-DD): start (inclusive), end (exclusive) date of aggregation
# - include_holidays(str, boolean-ish): 'true' will include holidays
# - dow_list(str): flattened list of integers, i.e. [1,2,3,4] -> '1234', representing days of week to be included (ISODOW)
def aggregate_travel_times(start_node, end_node, start_time, end_time, start_date, end_date, include_holidays, dow_str):
try:
start_node = int(start_node)
Expand Down Expand Up @@ -113,16 +106,15 @@ def aggregate_travel_times(start_node, end_node, start_time, end_time, start_dat
# test URL /date-bounds
@app.route('/date-bounds', methods=['GET'])
def get_date_bounds():
"Get the earliest date and latest data in the travel database."
connection = getConnection()
with connection:
with connection.cursor() as cursor:
cursor.execute('SELECT MIN(dt), MAX(dt) FROM here.ta;')
cursor.execute('SELECT MIN(dt)::text, MAX(dt)::text FROM here.ta;')
( min_date, max_date ) = cursor.fetchone()
connection.close()
return {
"start_time": min_date.strftime('%Y-%m-%d'),
"end_time": max_date.strftime('%Y-%m-%d')
"start_time": min_date,
"end_time": max_date
}

# test URL /holidays
Expand All @@ -132,13 +124,9 @@ def get_holidays():
connection = getConnection()
with connection:
with connection.cursor() as cursor:
cursor.execute("""
SELECT
dt::text,
holiday
FROM ref.holiday
ORDER BY dt;
""")
dates = [ {'date': dt, 'name': nm} for (dt, nm) in cursor.fetchall()]
cursor.execute(
"SELECT dt::text, holiday FROM ref.holiday ORDER BY dt;"
)
dates = [{'date': dt, 'name': nm} for (dt, nm) in cursor.fetchall()]
connection.close()
return dates

0 comments on commit 8ce83ff

Please sign in to comment.