From 2e218bfcd71a5d055417a21151fcc437de77cf7e Mon Sep 17 00:00:00 2001 From: Nate-Wessel Date: Tue, 11 Jun 2024 18:49:15 +0000 Subject: [PATCH] remove newly unused bits --- backend/app/get_travel_time.py | 52 ++++------------------------------ 1 file changed, 6 insertions(+), 46 deletions(-) diff --git a/backend/app/get_travel_time.py b/backend/app/get_travel_time.py index 48ad97b..55a7360 100644 --- a/backend/app/get_travel_time.py +++ b/backend/app/get_travel_time.py @@ -27,33 +27,11 @@ def get_travel_time(start_node, end_node, start_time, end_time, start_date, end_ """Function for returning data from the aggregate-travel-times/ endpoint""" holiday_clause = '' - holiday_clause_raw = '' if not include_holidays: holiday_clause = '''AND NOT EXISTS ( - SELECT 1 FROM ref.holiday WHERE cn.dt = holiday.dt - )''' - holiday_clause_raw = '''AND NOT EXISTS ( SELECT 1 FROM ref.holiday WHERE ta.dt = holiday.dt )''' - hourly_tt_query = f''' - SELECT - dt, - SUM(cn.unadjusted_tt) * %(length_m)s::real / SUM(cn.length_w_data) AS tt - FROM congestion.network_segments_daily AS cn - WHERE - cn.segment_id::integer = ANY(%(seglist)s) - AND cn.hr <@ %(time_range)s::numrange - AND date_part('ISODOW', cn.dt)::integer = ANY(%(dow_list)s) - AND cn.dt <@ %(date_range)s::daterange - {holiday_clause} - GROUP BY - cn.dt, - cn.hr - -- where corridor has at least 80pct of links with data - HAVING SUM(cn.length_w_data) >= %(length_m)s::numeric * 0.8; - ''' - raw_data_query = f''' SELECT link_dir, @@ -69,7 +47,7 @@ def get_travel_time(start_node, end_node, start_time, end_time, start_date, end_ AND date_part('ISODOW', dt) = ANY(%(dow_list)s) AND dt >= %(start_date)s::date AND dt < %(end_date)s::date - {holiday_clause_raw} + {holiday_clause} ''' links = get_links(start_node, end_node) @@ -77,28 +55,23 @@ def get_travel_time(start_node, end_node, start_time, end_time, start_date, end_ total_corridor_length = sum(link['length_m'] for link in links) query_params = { + # not actually query params any more, but have been useful before "length_m": total_corridor_length, "seglist": list(set(link['segment_id'] for link in links)), + # real query params "link_dir_list": [link['link_dir'] for link in links], "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 "start_time": f'{start_time:02d}:00:00', "end_time": f'{end_time:02d}:00:00', "start_date": start_date, "end_date": end_date, - "date_range": f"[{start_date},{end_date})", # 'YYYY-MM-DD' "dow_list": dow_list } connection = getConnection() with connection: with connection.cursor() as cursor: - # get the hourly travel times - cursor.execute(hourly_tt_query, query_params) - sample = cursor.fetchall() - cursor.execute(raw_data_query, query_params) raw_data_frame = pandas.DataFrame( cursor.fetchall(), @@ -116,15 +89,10 @@ def get_travel_time(start_node, end_node, start_time, end_time, start_date, end_ # filter out hours with too much missing data observations = hr_sums[ hr_sums['length'] / total_corridor_length > 0.8 ] # convert to format that can be used by the same summary function - - obs_list = [] + sample = [] for tup in observations.itertuples(): (dt, hr), tt = tup.Index, tup.tt - obs_list.append((dt, tt)) - - # TODO check query speeds - - tt_hourly = [ tt for (dt,tt) in sample ] + sample.append((dt, tt)) if len(sample) < 1: # no travel times or related info to return here @@ -137,17 +105,9 @@ def get_travel_time(start_node, end_node, start_time, end_time, start_date, end_ } tt_seconds = mean_daily_mean(sample) - tt_seconds_raw = mean_daily_mean(obs_list) - print( - len(sample), - len(obs_list) - ) return { - 'results': { - 'travel_time': timeFormat(tt_seconds), - 'travel_time2': timeFormat(tt_seconds_raw) - }, + 'results': {'travel_time': timeFormat(tt_seconds)}, 'query': { 'corridor': {'links': links}, 'query_params': query_params