Skip to content

Commit

Permalink
unmask miami k grades
Browse files Browse the repository at this point in the history
  • Loading branch information
cbini committed Nov 6, 2023
1 parent 811f7e1 commit 91a748a
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 38 deletions.
21 changes: 11 additions & 10 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ a pull request, reviewing, and merging the pull request.

Here are some resources to help you get started with open source contributions:

- [Set up Git](https://docs.github.com/en/get-started/quickstart/set-up-git)
- [GitHub flow](https://docs.github.com/en/get-started/quickstart/github-flow)
- [Collaborating with pull requests](https://docs.github.com/en/github/collaborating-with-pull-requests)

## Getting started

### Account setup

- [ ] Google Workspace
- [ ] dbt Cloud
- [ ] GitHub
- [x] Google Workspace
- [x] dbt Cloud
- [x] GitHub

To contribute on GitHub, you must be a member of our
[Data Team](https://github.com/orgs/TEAMSchools/teams/data-team), and your ability to approve and
Expand All @@ -29,19 +28,21 @@ merge pull requests depends on your membership in one of these subgroups:
- [Data Engineers](https://github.com/orgs/TEAMSchools/teams/data-engineers)
- [Admins](https://github.com/orgs/TEAMSchools/teams/admins)

To access our BigQuery project and its datasets, you must be a member of `TEAMster Analysts KTAF`.
To access our BigQuery project and its datasets, you must be a member of our **TEAMster Analysts
KTAF** Google security group.

### dbt Cloud configuration

#### Development Dataset

When you first login to dbt Cloud, you will be asked to set up **Development credentials**. Every
user gets their own development _branch_ of the database, and dbt will prefix every dataset it
When you first login to dbt Cloud, you will be asked to set up **Development credentials**.

Every user gets their own development _branch_ of the database, and dbt will prefix every dataset it
generates with a name specific to you. By default, this will be your username, but please add an
underscore (`_`) to avoid cluttering up our BigQuery navigation. BigQuery will hide any datasets
that begin with an underscore from the left nav.

![Alt text](../images/dbt-cloud/settings_profile_credentials.png)
![Alt text](images/dbt-cloud/settings_profile_credentials.png)

#### sqlfmt

Expand All @@ -55,7 +56,7 @@ To enable sqlfmt:
1. Make sure you're on a development branch. Formatting isn't available on main or read-only
branches.
2. Open a `.sql` file and click on the **Code Quality** tab.
3. Click on the <kbd></> Config</kbd> button on the right side of the console.
3. Click on the <kbd>&lt;/&gt; Config</kbd> button on the right side of the console.
4. In the code quality tool config pop-up, you have the option to select **sqlfluff** or **sqlfmt**.
5. To format your code, select the `sqlfmt` radio button.
6. Once selected, go to the console section (located below the File editor) and select the
Expand All @@ -71,7 +72,7 @@ To enable sqlfmt:

https://docs.getdbt.com/docs/collaborate/git/version-control-basics

![Alt text](../images/dbt-cloud/version-control.png)
![Alt text](images/dbt-cloud/version-control.png)

#### Make your changes

Expand Down
3 changes: 3 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ nav:

markdown_extensions:
- attr_list
- pymdownx.keys
- pymdownx.emoji:
emoji_index: !!python/name:material.extensions.emoji.twemoji
emoji_generator: !!python/name:material.extensions.emoji.to_svg
- pymdownx.tasklist:
custom_checkbox: true
7 changes: 7 additions & 0 deletions src/dbt/kipptaf/macros/code_location_join.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{%- macro extract_code_location(table) -%}
regexp_extract({{ table }}._dbt_source_relation, r'(kipp\w+)_')
{%- endmacro -%}

{%- macro union_dataset_join_clause(left_alias, right_alias) -%}
{{ extract_code_location(left_alias) }} = {{ extract_code_location(right_alias) }}
{%- endmacro -%}
4 changes: 0 additions & 4 deletions src/dbt/kipptaf/macros/union_dataset_join_clause.sql

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@ with
enr.students_student_number,
enr.teacher_lastfirst,

s.grade_level,

rt.name as term_name,
rt.code as term_code,

{{ extract_code_location("enr") }} as code_location,

coalesce(enr.cc_currentabsences, 0) as currentabsences,
coalesce(enr.cc_currenttardies, 0) as currenttardies,
abs(enr.courses_sched_do_not_print - 1) as include_grades_display,
from {{ ref("base_powerschool__course_enrollments") }} as enr
inner join
{{ ref("stg_powerschool__students") }} as s
on enr.students_student_number = s.student_number
and {{ union_dataset_join_clause(left_alias="enr", right_alias="s") }}
inner join
{{ ref("stg_reporting__terms") }} as rt
on enr.cc_schoolid = rt.school_id
Expand All @@ -40,6 +48,70 @@ with
order_by="cc_dateenrolled desc",
)
}}
),

enr_fg as (
select
enr._dbt_source_relation,
enr.students_student_number,
enr.cc_studentid,
enr.cc_yearid,
enr.cc_academic_year,
enr.cc_course_number,
enr.cc_sectionid,
enr.sections_dcid,
enr.sections_section_number,
enr.teacher_lastfirst,
enr.courses_course_name,
enr.courses_credit_hours,
enr.term_name,
enr.term_code,
enr.include_grades_display,
enr.currentabsences,
enr.currenttardies,

fg.need_60,
fg.term_percent_grade_adjusted_rt1,
fg.term_percent_grade_adjusted_rt2,
fg.term_percent_grade_adjusted_rt3,
fg.term_percent_grade_adjusted_rt4,
fg.y1_percent_grade_adjusted,

if(
enr.code_location = 'kippmiami' and enr.grade_level = 0,
fg.term_letter_grade_rt1,
fg.term_letter_grade_adjusted_rt1
) as term_letter_grade_adjusted_rt1,
if(
enr.code_location = 'kippmiami' and enr.grade_level = 0,
fg.term_letter_grade_rt2,
fg.term_letter_grade_adjusted_rt2
) as term_letter_grade_adjusted_rt2,
if(
enr.code_location = 'kippmiami' and enr.grade_level = 0,
fg.term_letter_grade_rt3,
fg.term_letter_grade_adjusted_rt3
) as term_letter_grade_adjusted_rt3,
if(
enr.code_location = 'kippmiami' and enr.grade_level = 0,
fg.term_letter_grade_rt4,
fg.term_letter_grade_adjusted_rt4
) as term_letter_grade_adjusted_rt4,
if(
enr.code_location = 'kippmiami'
and enr.grade_level = 0
and fg.y1_letter_grade = 'F*',
'U',
fg.y1_letter_grade
) as y1_letter_grade,
from enr_deduplicate as enr
left join
{{ ref("int_powerschool__final_grades_pivot") }} as fg
on enr.cc_studentid = fg.studentid
and enr.cc_yearid = fg.yearid
and enr.cc_course_number = fg.course_number
and enr.term_name = fg.storecode
and {{ union_dataset_join_clause(left_alias="enr", right_alias="fg") }}
)

select
Expand All @@ -56,8 +128,7 @@ select
enr.include_grades_display,
enr.currentabsences,
enr.currenttardies,

fg.need_60,
enr.need_60,

cat.f_cur as f_term,
cat.s_cur as s_term,
Expand All @@ -72,55 +143,48 @@ select
null as e1_pct,
null as e2_pct,

max(fg.term_percent_grade_adjusted_rt1) over (
max(enr.term_percent_grade_adjusted_rt1) over (
partition by enr.cc_studentid, enr.cc_yearid, enr.cc_course_number
order by enr.term_name asc
) as `Q1_pct`,
max(fg.term_letter_grade_adjusted_rt1) over (
max(enr.term_letter_grade_adjusted_rt1) over (
partition by enr.cc_studentid, enr.cc_yearid, enr.cc_course_number
order by enr.term_name asc
) as `Q1_letter`,
max(fg.term_percent_grade_adjusted_rt2) over (
max(enr.term_percent_grade_adjusted_rt2) over (
partition by enr.cc_studentid, enr.cc_yearid, enr.cc_course_number
order by enr.term_name asc
) as `Q2_pct`,
max(fg.term_letter_grade_adjusted_rt2) over (
max(enr.term_letter_grade_adjusted_rt2) over (
partition by enr.cc_studentid, enr.cc_yearid, enr.cc_course_number
order by enr.term_name asc
) as `Q2_letter`,
max(fg.term_percent_grade_adjusted_rt3) over (
max(enr.term_percent_grade_adjusted_rt3) over (
partition by enr.cc_studentid, enr.cc_yearid, enr.cc_course_number
order by enr.term_name asc
) as `Q3_pct`,
max(fg.term_letter_grade_adjusted_rt3) over (
max(enr.term_letter_grade_adjusted_rt3) over (
partition by enr.cc_studentid, enr.cc_yearid, enr.cc_course_number
order by enr.term_name asc
) as `Q3_letter`,
max(fg.term_percent_grade_adjusted_rt4) over (
max(enr.term_percent_grade_adjusted_rt4) over (
partition by enr.cc_studentid, enr.cc_yearid, enr.cc_course_number
order by enr.term_name asc
) as `Q4_pct`,
max(fg.term_letter_grade_adjusted_rt4) over (
max(enr.term_letter_grade_adjusted_rt4) over (
partition by enr.cc_studentid, enr.cc_yearid, enr.cc_course_number
order by enr.term_name asc
) as `Q4_letter`,

coalesce(sgy1.percent, fg.y1_percent_grade_adjusted) as y1_pct,
coalesce(sgy1.grade, fg.y1_letter_grade) as y1_letter,
coalesce(sgy1.percent, enr.y1_percent_grade_adjusted) as y1_pct,
coalesce(sgy1.grade, enr.y1_letter_grade) as y1_letter,

coalesce(kctz.ctz_cur, cat.ctz_cur) as ctz_cur,
coalesce(kctz.ctz_rt1, cat.ctz_rt1) as ctz_rt1,
coalesce(kctz.ctz_rt2, cat.ctz_rt2) as ctz_rt2,
coalesce(kctz.ctz_rt3, cat.ctz_rt3) as ctz_rt3,
coalesce(kctz.ctz_rt4, cat.ctz_rt4) as ctz_rt4,
from enr_deduplicate as enr
left join
{{ ref("int_powerschool__final_grades_pivot") }} as fg
on enr.cc_studentid = fg.studentid
and enr.cc_yearid = fg.yearid
and enr.cc_course_number = fg.course_number
and enr.term_name = fg.storecode
and {{ union_dataset_join_clause(left_alias="enr", right_alias="fg") }}
from enr_fg as enr
left join
{{ ref("int_powerschool__category_grades_pivot") }} as cat
on enr.cc_studentid = cat.studentid
Expand All @@ -130,10 +194,10 @@ left join
and {{ union_dataset_join_clause(left_alias="enr", right_alias="cat") }}
left join
{{ ref("int_powerschool__category_grades_pivot") }} as kctz
on fg.studentid = kctz.studentid
and fg.yearid = kctz.yearid
and fg.storecode = kctz.reporting_term
and {{ union_dataset_join_clause(left_alias="fg", right_alias="kctz") }}
on enr.cc_studentid = kctz.studentid
and enr.cc_yearid = kctz.yearid
and enr.term_name = kctz.reporting_term
and {{ union_dataset_join_clause(left_alias="enr", right_alias="kctz") }}
and kctz.course_number = 'HR'
and left(enr.sections_section_number, 1) = '0'
left join
Expand Down

0 comments on commit 91a748a

Please sign in to comment.