-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #409 from cagov/delay_performance_metric_ba
Update Bottleneck Models with Integrated Delay Metrics
- Loading branch information
Showing
7 changed files
with
582 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...m/models/intermediate/performance/int_performance__bottleneck_delay_metrics_agg_daily.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{{ config( | ||
materialized="incremental", | ||
unique_key=['station_id','sample_date'], | ||
snowflake_warehouse = get_snowflake_refresh_warehouse(small="XL") | ||
) }} | ||
|
||
with hourly_spatial_bottleneck_delay_metrics as ( | ||
select * | ||
from {{ ref('int_performance__bottleneck_delay_metrics_agg_hourly') }} | ||
where {{ make_model_incremental('sample_date') }} | ||
), | ||
|
||
/*aggregate hourly delay and bottleneck extent in a daily level. Since one day has | ||
3 time shifts, the aggregation would be in a time shift level*/ | ||
|
||
daily_time_shift_spatial_bottleneck_delay_metrics as ( | ||
select | ||
station_id, | ||
sample_date, | ||
time_shift, | ||
any_value(district) as district, | ||
any_value(county) as county, | ||
any_value(station_type) as station_type, | ||
any_value(freeway) as freeway, | ||
any_value(direction) as direction, | ||
any_value(absolute_postmile) as absolute_postmile, | ||
sum(hourly_duration) as daily_time_shift_duration, | ||
avg(hourly_bottleneck_extent) as daily_time_shift_bottleneck_extent, | ||
-- spatial delay aggregation in daily level, decomposed into time shift | ||
{% for value in var("V_t") %} | ||
sum(hourly_spatial_delay_{{ value }}_mph) | ||
as daily_time_shift_spatial_delay_{{ value }}_mph | ||
{% if not loop.last %} | ||
, | ||
{% endif %} | ||
{% endfor %} | ||
from hourly_spatial_bottleneck_delay_metrics | ||
where time_shift is not NULL | ||
group by station_id, sample_date, time_shift | ||
) | ||
|
||
select * from daily_time_shift_spatial_bottleneck_delay_metrics |
Oops, something went wrong.