diff --git a/src/dbt/kipptaf/models/extracts/tableau/rpt_tableau__schoolmint_grow_observation_details.sql b/src/dbt/kipptaf/models/extracts/tableau/rpt_tableau__schoolmint_grow_observation_details.sql index 66dbe2facb..2e44778635 100644 --- a/src/dbt/kipptaf/models/extracts/tableau/rpt_tableau__schoolmint_grow_observation_details.sql +++ b/src/dbt/kipptaf/models/extracts/tableau/rpt_tableau__schoolmint_grow_observation_details.sql @@ -136,6 +136,7 @@ with array_to_string(list_two_column_a, '|') as glows, array_to_string(list_two_column_b, '|') as grows, + from {{ ref("stg_schoolmint_grow__observations") }} where is_published @@ -171,6 +172,47 @@ with regexp_replace( regexp_replace(b.text_box_value, r'<[^>]*>', ''), r' ', ' ' ) as text_box, + + case + when + os.measurement in ( + '6484981d725ca60011b15280', + '648499ab0b57a8001189bea8', + '64849b290bd6de00117a7dc9', + '64849b7f725ca60011b15ea8', + '64849f0bad931f00112e4a46', + '6484a223ca819d0011f10745', + '6484a22aca819d0011f10776', + '6484a230725ca60011b17262', + '6484a240ca819d0011f107aa', + '6484a2458b403e0011ff4317', + '6484a24a0bd6de00117a8fe9', + '6484a2580bd6de00117a8ff3', + '6484a25dad931f00112e51ae', + '6484a2648b403e0011ff437a', + '6484a26f0bd6de00117a905c', + '6484a2778b403e0011ff43b9', + '6484a2a98b403e0011ff4488', + '6484a2b08b403e0011ff44aa', + '64c951fef1e9ad0011f4fd03' + ) + then 'ETR' + when + os.measurement in ( + '6484c4fb725ca60011b1bc92', + '6484c500725ca60011b1bc98', + '64a7237b0c348e0011c51727', + '64a7238955032e001180cbc0', + '64a720f6f27af600114e0046', + '64a7233fc3a17300119ca37b', + '64be9eea9c918a001163ffd0', + '64be9d7dff1c61001190d165', + '64a7236d353ba70011ce2c43', + '64a722ca7ee3cf001117edef' + ) + then 'SO' + end as score_measurement_type, + from observations as o left join {{ ref("stg_schoolmint_grow__observations__observation_scores") }} as os @@ -184,6 +226,29 @@ with and os.measurement = b.measurement ), + pm_overall_scores_long as ( + select + om.observation_id, + om.score_measurement_type, + avg(om.row_score_value) as score_measurement_score, + from observation_measurements as om + where om.score_measurement_type in ('ETR', 'SO') + group by om.observation_id, om.score_measurement_type + + ), + + pm_overall_scores as ( + select + p.observation_id, + p.etr as etr_score, + p.so as so_score, + coalesce((0.8 * p.etr) + (0.2 * p.so), p.etr, p.so) as overall_score, + from + pm_overall_scores_long pivot ( + avg(score_measurement_score) for score_measurement_type in ('ETR', 'SO') + ) as p + ), + observation_details as ( select s.user_id, @@ -242,7 +307,7 @@ with /* Matches on name for PM Rounds to distinguish Self and Coach */ and s.form_short_name = o.form_short_name and s.user_id = o.teacher_id - and s.form_type = 'PM' + where s.form_type = 'PM' union all @@ -303,7 +368,7 @@ with /* matches only on type and date for weekly forms */ and s.form_type = o.form_type and s.user_id = o.teacher_id - and s.form_type in ('WT', 'O3') + where s.form_type in ('WT', 'O3') ), historical_overall_scores as ( @@ -311,9 +376,9 @@ with s.employee_number, s.academic_year, s.form_term, - null as etr_score, - null as so_score, - o.overall_score, + os.etr_score, + os.so_score, + os.overall_score, null as etr_tier, null as so_tier, o.tier, @@ -324,6 +389,7 @@ with /* Matches on name for PM Rounds to distinguish Self and Coach */ and s.form_short_name = o.form_short_name and s.user_id = o.teacher_id + left join pm_overall_scores as os on o.observation_id = os.observation_id where s.form_type = 'PM' union all @@ -413,50 +479,53 @@ with ) select - user_id, - role_name, - internal_id, - form_type, - form_term, - form_short_name, - form_long_name, - score_type, - start_date, - end_date, - academic_year, - employee_number, - teammate, - entity, - location, - grade_band, - home_work_location_powerschool_school_id, - department, - grade_taught, - job_title, - manager, - worker_original_hire_date, - assignment_status, - observation_id, - teacher_id, - created, - observed_at, - observer_name, - null as etr_score, - null as so_score, - overall_score, + od.user_id, + od.role_name, + od.internal_id, + od.form_type, + od.form_term, + od.form_short_name, + od.form_long_name, + od.score_type, + od.start_date, + od.end_date, + od.academic_year, + od.employee_number, + od.teammate, + od.entity, + od.location, + od.grade_band, + od.home_work_location_powerschool_school_id, + od.department, + od.grade_taught, + od.job_title, + od.manager, + od.worker_original_hire_date, + od.assignment_status, + od.observation_id, + od.teacher_id, + od.created, + od.observed_at, + od.observer_name, + os.etr_score as etr_score, + os.so_score as so_score, + case + when od.academic_year <= 2024 then os.overall_score else od.overall_score + end as overall_score, null as etr_tier, null as so_tier, - tier, - glows, - grows, - score_measurement_id, - score_percentage, - row_score_value, - measurement_name, - text_box, - rn_submission, -from observation_details -where rn_submission = 1 + od.tier, + od.glows, + od.grows, + od.score_measurement_id, + od.score_percentage, + od.row_score_value, + od.measurement_name, + od.text_box, + od.rn_submission, +from observation_details as od +left join pm_overall_scores as os on od.observation_id = os.observation_id +where od.rn_submission = 1 union all