From 409118c7e87ace5780c2878359d2d822f88bfc66 Mon Sep 17 00:00:00 2001 From: britt <47340362+traintestbritt@users.noreply.github.com> Date: Tue, 23 Apr 2024 13:25:53 -0700 Subject: [PATCH 1/4] making problems for everyone --- .../int_pems__detector_status.sql | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/transform/models/intermediate/detector_health_diag/int_pems__detector_status.sql b/transform/models/intermediate/detector_health_diag/int_pems__detector_status.sql index 04fd73da..9109431c 100644 --- a/transform/models/intermediate/detector_health_diag/int_pems__detector_status.sql +++ b/transform/models/intermediate/detector_health_diag/int_pems__detector_status.sql @@ -3,11 +3,15 @@ ) }} with +samples_per_station as ( + select * {{ ref ('int_pems__diagnostic_samples_per_station') }} + where sample_date > year(2023) +) -detector_status as ( +, detector_status as ( select - sps.*, - case + sps.* + , case when sps.sample_ct = 0 or sps.sample_ct is null then 'Down/No Data' /* # of samples < 60% of the max collected during the test period @@ -29,12 +33,12 @@ detector_status as ( set_assgnmt.station_diagnostic_method_id = 'ramp' and sps.high_volume_ct / ({{ var("detector_status_max_sample_value") }}) > (set_assgnmt.high_flow_percent / 100) - then 'High Val' + then 'High Value' when set_assgnmt.station_diagnostic_method_id = 'mainline' and sps.high_occupancy_ct / ({{ var("detector_status_max_sample_value") }}) > (set_assgnmt.high_occupancy_percent / 100) - then 'High Val' + then 'High Value' when set_assgnmt.station_diagnostic_method_id = 'mainline' and sps.zero_vol_pos_occ_ct / ({{ var("detector_status_max_sample_value") }}) @@ -47,10 +51,10 @@ detector_status as ( then 'Intermittent' --constant occupancy case needed --Feed unstable case needed - else 'Good' + else 'Great' end as status from {{ ref('int_pems__det_diag_set_assignment') }} as set_assgnmt - left join {{ ref ('int_pems__diagnostic_samples_per_station') }} as sps + left join samples_per_station as sps on set_assgnmt.station_id = sps.station_id and set_assgnmt.station_valid_from <= sps.sample_date @@ -61,4 +65,4 @@ detector_status as ( ) ) -select * from detector_status +select * from detector_status \ No newline at end of file From 4905fb23d39a51e2ee32976c445a731c2d92fb16 Mon Sep 17 00:00:00 2001 From: britt <47340362+traintestbritt@users.noreply.github.com> Date: Tue, 23 Apr 2024 13:42:57 -0700 Subject: [PATCH 2/4] making more problems for everyone --- .../int_pems__detector_status.sql | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/transform/models/intermediate/detector_health_diag/int_pems__detector_status.sql b/transform/models/intermediate/detector_health_diag/int_pems__detector_status.sql index 9109431c..e3ba051c 100644 --- a/transform/models/intermediate/detector_health_diag/int_pems__detector_status.sql +++ b/transform/models/intermediate/detector_health_diag/int_pems__detector_status.sql @@ -2,43 +2,37 @@ materialized="table" ) }} -with -samples_per_station as ( - select * {{ ref ('int_pems__diagnostic_samples_per_station') }} - where sample_date > year(2023) -) - -, detector_status as ( +detector_status as ( select - sps.* - , case + sps.*, + case when sps.sample_ct = 0 or sps.sample_ct is null - then 'Down/No Data' + then 'Down_or_No_Data' /* # of samples < 60% of the max collected during the test period max value: 2 samples per min * 60 mins/hr * 17 hrs in a day == 1224 btwn 1 and 1224 is too few samples */ when sps.sample_ct between 1 and (0.6 * ({{ var("detector_status_max_sample_value") }})) - then 'Insufficient Data' + then 'Insufficient_Data' when set_assgnmt.station_diagnostic_method_id = 'ramp' and sps.zero_vol_ct / ({{ var("detector_status_max_sample_value") }}) > (set_assgnmt.zero_flow_percent / 100) - then 'Card Off' + then 'Card_Off' when set_assgnmt.station_diagnostic_method_id = 'mainline' and sps.zero_occ_ct / ({{ var("detector_status_max_sample_value") }}) > (set_assgnmt.zero_occupancy_percent / 100) - then 'Card Off' + then 'Card_Off' when set_assgnmt.station_diagnostic_method_id = 'ramp' and sps.high_volume_ct / ({{ var("detector_status_max_sample_value") }}) > (set_assgnmt.high_flow_percent / 100) - then 'High Value' + then 'High_Value' when set_assgnmt.station_diagnostic_method_id = 'mainline' and sps.high_occupancy_ct / ({{ var("detector_status_max_sample_value") }}) > (set_assgnmt.high_occupancy_percent / 100) - then 'High Value' + then 'High_Value' when set_assgnmt.station_diagnostic_method_id = 'mainline' and sps.zero_vol_pos_occ_ct / ({{ var("detector_status_max_sample_value") }}) @@ -49,12 +43,10 @@ samples_per_station as ( and sps.zero_occ_pos_vol_ct / ({{ var("detector_status_max_sample_value") }}) > (set_assgnmt.occupancy_flow_percent / 100) then 'Intermittent' - --constant occupancy case needed - --Feed unstable case needed - else 'Great' + else 'Superb' end as status from {{ ref('int_pems__det_diag_set_assignment') }} as set_assgnmt - left join samples_per_station as sps + left join {{ ref ('int_pems__diagnostic_samples_per_station') }} as sps on set_assgnmt.station_id = sps.station_id and set_assgnmt.station_valid_from <= sps.sample_date From 634ef3b4bf3c6f9ce5591a6a08cd75390e4ad1b1 Mon Sep 17 00:00:00 2001 From: britt <47340362+traintestbritt@users.noreply.github.com> Date: Tue, 23 Apr 2024 13:49:08 -0700 Subject: [PATCH 3/4] introducing a third set of problems --- .../int_pems__detector_status.sql | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/transform/models/intermediate/detector_health_diag/int_pems__detector_status.sql b/transform/models/intermediate/detector_health_diag/int_pems__detector_status.sql index e3ba051c..2d34a78f 100644 --- a/transform/models/intermediate/detector_health_diag/int_pems__detector_status.sql +++ b/transform/models/intermediate/detector_health_diag/int_pems__detector_status.sql @@ -1,38 +1,41 @@ {{ config( materialized="table" ) }} - -detector_status as ( +samples_per_station as ( + select * from {{ ref('int_pems__det_diag_set_assignment') }} + where sample_date > year(2023) +) +, detector_status as ( select sps.*, case when sps.sample_ct = 0 or sps.sample_ct is null - then 'Down_or_No_Data' + then 'Down/No Data' /* # of samples < 60% of the max collected during the test period max value: 2 samples per min * 60 mins/hr * 17 hrs in a day == 1224 btwn 1 and 1224 is too few samples */ when sps.sample_ct between 1 and (0.6 * ({{ var("detector_status_max_sample_value") }})) - then 'Insufficient_Data' + then 'Insufficient Data' when set_assgnmt.station_diagnostic_method_id = 'ramp' and sps.zero_vol_ct / ({{ var("detector_status_max_sample_value") }}) > (set_assgnmt.zero_flow_percent / 100) - then 'Card_Off' + then 'Card Off' when set_assgnmt.station_diagnostic_method_id = 'mainline' and sps.zero_occ_ct / ({{ var("detector_status_max_sample_value") }}) > (set_assgnmt.zero_occupancy_percent / 100) - then 'Card_Off' + then 'Card Off' when set_assgnmt.station_diagnostic_method_id = 'ramp' and sps.high_volume_ct / ({{ var("detector_status_max_sample_value") }}) > (set_assgnmt.high_flow_percent / 100) - then 'High_Value' + then 'High Val' when set_assgnmt.station_diagnostic_method_id = 'mainline' and sps.high_occupancy_ct / ({{ var("detector_status_max_sample_value") }}) > (set_assgnmt.high_occupancy_percent / 100) - then 'High_Value' + then 'High Val' when set_assgnmt.station_diagnostic_method_id = 'mainline' and sps.zero_vol_pos_occ_ct / ({{ var("detector_status_max_sample_value") }}) @@ -45,7 +48,7 @@ detector_status as ( then 'Intermittent' else 'Superb' end as status - from {{ ref('int_pems__det_diag_set_assignment') }} as set_assgnmt + from samples_per_station as set_assgnmt left join {{ ref ('int_pems__diagnostic_samples_per_station') }} as sps on set_assgnmt.station_id = sps.station_id From 9275b4f69c260c123f9e956ed4f32ea19688796d Mon Sep 17 00:00:00 2001 From: Zifeng Wu Date: Thu, 25 Apr 2024 21:58:55 +0000 Subject: [PATCH 4/4] fixed formatting --- transform/package-lock.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/transform/package-lock.yml b/transform/package-lock.yml index eddc3bea..669f9637 100644 --- a/transform/package-lock.yml +++ b/transform/package-lock.yml @@ -1,4 +1,4 @@ packages: -- package: dbt-labs/dbt_utils - version: 1.1.1 + - package: dbt-labs/dbt_utils + version: 1.1.1 sha1_hash: a158c48c59c2bb7d729d2a4e215aabe5bb4f3353