Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extrapolate travel time across missing data #112

Merged
merged 2 commits into from
Apr 24, 2024
Merged

Extrapolate travel time across missing data #112

merged 2 commits into from
Apr 24, 2024

Conversation

Nate-Wessel
Copy link
Contributor

@Nate-Wessel Nate-Wessel commented Apr 23, 2024

@chmnata can you confirm that the SQL in this block matches your understanding of how we are currently measuring average travel time using the congestion network?

-- Aggregate segments to corridor on a daily, hourly basis
WITH corridor_hourly_daily_agg AS (
SELECT
cn.dt,
cn.hr,
SUM(cn.tt) AS corr_hourly_daily_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
{tt_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
),
-- Average the hours selected into daily period level data
corridor_period_daily_avg_tt AS (
SELECT
dt,
AVG(corr_hourly_daily_tt) AS avg_corr_period_daily_tt
FROM corridor_hourly_daily_agg
GROUP BY
dt
)
-- Average all the days with data to get period level data for each date range
SELECT
ROUND(AVG(avg_corr_period_daily_tt) / 60, 2) AS average_tt_min
FROM corridor_period_daily_avg_tt

@chmnata
Copy link
Contributor

chmnata commented Apr 23, 2024

If we are using link->segment-> corridor with adjusted tt aka tt, in the where clause for agg_tt_query, we should add a is_valid = TRUE. The adjusted TT column is calculated for all segment even if the length w data is below 80%. The is_valid column is true when there are 80% or more links with data in that segment.
And then instead of using length_w_data as a base for the 80% check, we should use the sum length of the segments with is_valid = true to check against the corridor length.

If we are using unadjusted_tt, we will just need to adjust the sum(unadjusted_tt) with corridor_length/sum link_length, on top of the previous query used.

@Nate-Wessel
Copy link
Contributor Author

If we are using unadjusted_tt, we will just need to adjust the sum(unadjusted_tt) with corridor_length/sum link_length, on top of the previous query used.

This approach seems more robust as it would extrapolate across any missing segments. Can you take another look now?

@Nate-Wessel Nate-Wessel changed the title Use _adjusted_ travel time field from congestion network Extrapolate travel time across missing data Apr 23, 2024
@Nate-Wessel
Copy link
Contributor Author

Results seem reasonable. Slightly higher travel times than before.

@Nate-Wessel Nate-Wessel merged commit 3c573de into deploy Apr 24, 2024
1 check passed
@Nate-Wessel Nate-Wessel deleted the tt-adjust branch April 24, 2024 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants