Skip to content

Commit

Permalink
remove newly unused bits
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate-Wessel committed Jun 11, 2024
1 parent dd359f7 commit 2e218bf
Showing 1 changed file with 6 additions and 46 deletions.
52 changes: 6 additions & 46 deletions backend/app/get_travel_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -69,36 +47,31 @@ 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)

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(),
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 2e218bf

Please sign in to comment.