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

Feature/dim self paced pd activity #140

Merged
merged 33 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
639e246
saving progress
allison-code-dot-org Jul 26, 2024
0ee9802
saving progress
allison-code-dot-org Jul 29, 2024
4132414
Merge branch 'main' of https://github.com/code-dot-org/analytics into…
allison-code-dot-org Jul 29, 2024
6bbac64
small change
allison-code-dot-org Jul 30, 2024
0e3629e
Update dbt/models/marts/teachers/dim_self_paced_pd_activity.sql
allison-code-dot-org Aug 15, 2024
8a73031
Update dbt/models/marts/teachers/dim_self_paced_pd_activity.sql
allison-code-dot-org Aug 15, 2024
ad35627
Update dbt/models/marts/teachers/dim_self_paced_pd_activity.sql
allison-code-dot-org Aug 15, 2024
ed1451b
Update dbt/models/marts/teachers/dim_self_paced_pd_activity.sql
allison-code-dot-org Aug 15, 2024
c037701
Merge branch 'main' of https://github.com/code-dot-org/analytics into…
allison-code-dot-org Aug 16, 2024
cad3fc9
Update dbt/models/marts/teachers/dim_self_paced_pd_activity.sql
allison-code-dot-org Aug 16, 2024
265db93
Update dbt/models/marts/teachers/dim_self_paced_pd_activity.sql
allison-code-dot-org Aug 16, 2024
b17e2ed
Update dbt/models/marts/teachers/dim_self_paced_pd_activity.sql
allison-code-dot-org Aug 16, 2024
3a0df15
Update dbt/models/marts/teachers/dim_self_paced_pd_activity.sql
allison-code-dot-org Aug 16, 2024
85b64c5
Update dbt/models/marts/teachers/dim_self_paced_pd_activity.sql
allison-code-dot-org Aug 16, 2024
672ac07
Update dbt/models/marts/teachers/dim_self_paced_pd_analysis.sql
allison-code-dot-org Aug 16, 2024
3f2293f
Update dbt/models/marts/teachers/dim_self_paced_pd_analysis.sql
allison-code-dot-org Aug 16, 2024
cf35686
Update dbt/models/marts/teachers/dim_self_paced_pd_analysis.sql
allison-code-dot-org Aug 16, 2024
a06b450
Update dbt/models/marts/teachers/dim_self_paced_pd_analysis.sql
allison-code-dot-org Aug 16, 2024
25ce74b
Update dbt/models/marts/teachers/dim_self_paced_pd_analysis.sql
allison-code-dot-org Aug 16, 2024
c55a487
Update dbt/models/marts/teachers/dim_self_paced_pd_analysis.sql
allison-code-dot-org Aug 16, 2024
258f24e
Update dbt/models/marts/teachers/dim_self_paced_pd_analysis.sql
allison-code-dot-org Aug 16, 2024
42542f6
Update dbt/models/marts/teachers/dim_self_paced_pd_analysis.sql
allison-code-dot-org Aug 16, 2024
d9c2d8c
Update dbt/models/marts/teachers/dim_self_paced_pd_analysis.sql
allison-code-dot-org Aug 16, 2024
2298d2a
Update dbt/models/marts/teachers/dim_self_paced_pd_analysis.sql
allison-code-dot-org Aug 16, 2024
d333fb1
Update dbt/models/marts/teachers/dim_self_paced_pd_analysis.sql
allison-code-dot-org Aug 16, 2024
3f0332b
Update dbt/models/marts/teachers/dim_self_paced_pd_analysis.sql
allison-code-dot-org Aug 16, 2024
ca8f8f9
Update dbt/models/marts/teachers/dim_self_paced_pd_analysis.sql
allison-code-dot-org Aug 16, 2024
5c78d2e
Update dbt/models/marts/teachers/dim_self_paced_pd_analysis.sql
allison-code-dot-org Aug 16, 2024
38feb4f
Update dbt/models/marts/teachers/dim_self_paced_pd_analysis.sql
allison-code-dot-org Aug 16, 2024
9fa65b4
Update dbt/models/marts/teachers/dim_self_paced_pd_analysis.sql
allison-code-dot-org Aug 16, 2024
d6cda48
Update dbt/models/marts/teachers/dim_self_paced_pd_analysis.sql
allison-code-dot-org Aug 16, 2024
34cf2a7
Update dbt/models/marts/teachers/dim_self_paced_pd_analysis.sql
allison-code-dot-org Aug 16, 2024
32aed3a
final changes to self paced pd activity
allison-code-dot-org Aug 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions dbt/models/marts/teachers/dim_self_paced_pd_activity.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
with
course_structure as (
select *
from {{ ref('dim_course_structure') }}
),

user_levels as (
select *
from {{ ref('stg_dashboard__user_levels') }}
),

teachers as (
select *
from {{ ref('dim_teachers') }}
),

levels as (
select *
from {{ ref('dim_levels') }}
),

school_years as (
select *
from {{ ref('int_school_years') }}
),

self_paced_scripts as (
select distinct
cs.level_id
, cs.script_id
, cs.stage_id
, unit
allison-code-dot-org marked this conversation as resolved.
Show resolved Hide resolved
, cs.script_name
, cs.stage_name
, cs.level_name
, cs.stage_number
, cs.level_number
, cs.level_script_order
, cs.course_name_true
, case
when cs.script_name like 'k5-onlinepd%' then 'csf'
allison-code-dot-org marked this conversation as resolved.
Show resolved Hide resolved
when cs.script_name like 'self-paced-pl-k5%' then 'csf'
when cs.script_name like 'self-paced-pl-csd%' then 'csd'
when cs.script_name like 'self-paced-pl-csp%' then 'csp'
when cs.script_name like 'self-paced-pl-csc%' then 'csc'
when cs.script_name like 'self-paced-pl-ai%' then 'csd'
allison-code-dot-org marked this conversation as resolved.
Show resolved Hide resolved
when cs.script_name like 'self-paced-pl-physical%' then 'csd'
when cs.script_name like 'self-paced-pl-microbit%' then 'csd'
when cs.script_name like 'kodea-pd%' then 'csf'
end as course_name
allison-code-dot-org marked this conversation as resolved.
Show resolved Hide resolved
from course_structure cs
where
(
cs.script_name like 'k5-onlinepd-20__'
allison-code-dot-org marked this conversation as resolved.
Show resolved Hide resolved
or cs.script_name like 'self-paced-pl%'
allison-code-dot-org marked this conversation as resolved.
Show resolved Hide resolved
or cs.script_name like 'kodea-pd%' -- Translated version of csf in Spanish, for Chilean parter Kodea
allison-code-dot-org marked this conversation as resolved.
Show resolved Hide resolved
)
and cs.script_name not like 'self-paced-pl-csd6-2021'
allison-code-dot-org marked this conversation as resolved.
Show resolved Hide resolved
and cs.script_name not like 'self-paced-pl-csa%' -- csa's self-paced pl is asynchronous work for facilitator-led pd workshops
allison-code-dot-org marked this conversation as resolved.
Show resolved Hide resolved
)
select
ul.user_id as teacher_id
, ul.level_id
, ul.script_id
, sps.stage_id
, sps.unit
, sps.script_name
, sps.stage_name
, sps.level_name
, sps.course_name
, ul.created_at as level_created_at
, sy.school_year as level_created_school_year
, ul.best_result
, ul.time_spent
, l.level_type
, t.studio_person_id
, t.gender
, t.races
, t.is_urg
, t.school_id
, rank ()
over (
partition by ul.user_id
order by ul.created_at asc) as touch_rank
, sps.level_number
, sps.level_script_order
, sps.stage_number
, t.created_at as account_created_at

from self_paced_scripts as sps

join user_levels as ul
on sps.level_id = ul.level_id
and sps.script_id = ul.script_id

join levels as l
on ul.level_id = l.level_id

join teachers as t
on ul.user_id = t.teacher_id

join school_years as sy
on ul.created_at between sy.started_at and sy.ended_at
174 changes: 174 additions & 0 deletions dbt/models/marts/teachers/dim_self_paced_pd_analysis.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
with

active_teachers as (
select
teacher_id
, school_year
, course_name
, 1 as started
from {{ ref('int_active_sections') }}
)

, self_paced_pd_activity as (
select *
from {{ ref('dim_self_paced_pd_activity') }}
)

, teacher_history as(
select
t.course_name
, t.teacher_id
, first_value (
case
when t.started = 1 then t.school_year
else null
end ignore nulls)
over (
partition by t.teacher_id, t.course_name
order by left(t.school_year,4)
rows between unbounded preceding and unbounded following
) as first_teaching_sy
-- , count (
-- case
-- when t.started = 1 then t.school_year
-- else null
-- end ignore nulls
-- )
-- over (
-- partition by t.teacher_id, t.course_name
-- ) as num_sy_teaching
-- , first_value (
-- case
-- when t.started = 1 then t.school_id
-- else null
-- end ignore nulls)
-- over (
-- partition by t.teacher_id, t.course_name
-- order by left(t.school_year,4)
-- rows between unbounded preceding and unbounded following) as school_id_sy1
from active_teachers as t
)

, self_paced_metrics_1 as (
select distinct
teacher_id
, course_name
allison-code-dot-org marked this conversation as resolved.
Show resolved Hide resolved
, script_name
, count (distinct script_id) as num_scripts
, count (distinct level_id) as num_levels
from self_paced_pd_activity
group by teacher_id
, course_name
allison-code-dot-org marked this conversation as resolved.
Show resolved Hide resolved
, script_name
)

, self_paced_metrics_2 as (
select distinct
teacher_id
, course_name
allison-code-dot-org marked this conversation as resolved.
Show resolved Hide resolved
, script_name
, min (level_created_at)
over (
partition by teacher_id, course_name) as start_dt
allison-code-dot-org marked this conversation as resolved.
Show resolved Hide resolved
, max (level_created_at)
over (
partition by teacher_id, course_name) as end_dt
allison-code-dot-org marked this conversation as resolved.
Show resolved Hide resolved
, min (level_created_school_year)
over (
partition by teacher_id, course_name) as first_self_paced_sy -- accounting for users who are have activity in multiple schools years for the same course
allison-code-dot-org marked this conversation as resolved.
Show resolved Hide resolved
, last_value (script_id)
over (
partition by teacher_id, course_name
allison-code-dot-org marked this conversation as resolved.
Show resolved Hide resolved
order by level_created_at
rows between unbounded preceding and unbounded following) as max_script_id
, last_value (script_name)
over (
partition by teacher_id, course_name
allison-code-dot-org marked this conversation as resolved.
Show resolved Hide resolved
order by level_created_at
rows between unbounded preceding and unbounded following) as max_script_name
, last_value (level_id)
over (
partition by teacher_id, course_name, script_name
allison-code-dot-org marked this conversation as resolved.
Show resolved Hide resolved
order by level_created_at
rows between unbounded preceding and unbounded following) as max_level_id
, last_value (level_name)
over (
partition by teacher_id, course_name, script_name
allison-code-dot-org marked this conversation as resolved.
Show resolved Hide resolved
order by level_created_at
rows between unbounded preceding and unbounded following) as max_level_name
, last_value (stage_id)
over (
partition by teacher_id, course_name, script_name
allison-code-dot-org marked this conversation as resolved.
Show resolved Hide resolved
order by level_created_at
rows between unbounded preceding and unbounded following) as max_stage_id
, last_value (stage_name)
over (
partition by teacher_id, course_name, script_name
allison-code-dot-org marked this conversation as resolved.
Show resolved Hide resolved
order by level_created_at
rows between unbounded preceding and unbounded following) as max_stage_name
from self_paced_pd_activity
)

, self_paced_summary as (
select distinct
sp.teacher_id
, sp.course_name
allison-code-dot-org marked this conversation as resolved.
Show resolved Hide resolved
, sp.studio_person_id
, m2.start_dt
, m2.end_dt
, m2.first_self_paced_sy
, sp.script_name
, m1.num_scripts
, m1.num_levels
, m2.max_script_id
, m2.max_script_name
, m2.max_stage_id
, m2.max_stage_name
, m2.max_level_id
, m2.max_level_name
from self_paced_pd_activity as sp
left join self_paced_metrics_1 as m1
on sp.teacher_id = m1.teacher_id
and sp.course_name = m1.course_name
allison-code-dot-org marked this conversation as resolved.
Show resolved Hide resolved
and sp.script_name = m1.script_name
join self_paced_metrics_2 as m2
on sp.teacher_id = m2.teacher_id
and sp.course_name = m2.course_name
allison-code-dot-org marked this conversation as resolved.
Show resolved Hide resolved
and sp.script_name = m2.script_name
)

select distinct
coalesce(th.teacher_id, sps.teacher_id) as teacher_id
, coalesce(th.course_name, sps.course_name) as course_name
, th.first_teaching_sy
, case
when sps.teacher_id is not null then 1
else 0
end as did_self_paced_pl
, sps.start_dt
, sps.end_dt
, sps.first_self_paced_sy
, sps.script_name
, sps.num_scripts
, sps.num_levels
, sps.max_script_id
, sps.max_script_name
, sps.max_stage_id
, sps.max_stage_name
, sps.max_level_id
, sps.max_level_name
, case
when th.first_teaching_sy is null
or sps.first_self_paced_sy is null
then null
when left(th.first_teaching_sy,4) > left(sps.first_self_paced_sy,4)
then 'After self-paced'
when left(th.first_teaching_sy,4) < left(sps.first_self_paced_sy,4)
then 'Before self-paced'
when left(th.first_teaching_sy,4) = left(sps.first_self_paced_sy,4)
then 'Same year as self-paced'
end as course_teaching_timing
from teacher_history as th
allison-code-dot-org marked this conversation as resolved.
Show resolved Hide resolved
full outer join self_paced_summary as sps
allison-code-dot-org marked this conversation as resolved.
Show resolved Hide resolved
on th.teacher_id = sps.teacher_id
and th.course_name = sps.course_name
allison-code-dot-org marked this conversation as resolved.
Show resolved Hide resolved