Skip to content

Commit

Permalink
added some changes, please review failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jordan-springer committed Jan 30, 2024
1 parent 08a885b commit 30f1a82
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 45 deletions.
14 changes: 13 additions & 1 deletion dbt/models/marts/marts_docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,16 @@
- Active New- The school is currently active, was not active in the previous year, and has never been active before.
- Active Reacquired- The school is currently active, was not active in the previous year, but has been active in some previous years.
- Active Retained- The school is currently active and has been active in the previous year.
{% enddocs %}
{% enddocs %}


{% docs fct_monthly_accounts_created %}
### Accounts created by month
- Scope: user account was created in the given month (and year)
- Segmented by student/
- Excludes "dummy accounts" (student accounts created but don't have a sign_in attempt)
- Use Case: teacher creates a section of picture accounts many of which don't get used.
- NOTE: right now delted accounts are filtered out at the base_users table. Waiting on a change
to that in order to make these counts accurate.
{% enddocs %}

2 changes: 1 addition & 1 deletion dbt/models/marts/metrics/_metrics__models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ models:
description: total number of schools within the school level and active status dimensions as of that week

- name: fct_monthly_accounts_created
description: total teacher and student accounts created each month, segmented by user type and us/intl
description: user accounts created by month
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
Expand Down
53 changes: 22 additions & 31 deletions dbt/models/marts/metrics/fct_monthly_accounts_created.sql
Original file line number Diff line number Diff line change
@@ -1,36 +1,31 @@
{# NOTES:
accounts created by month - user account was created in the given month (and year)
segmented by student/
EXCLUDING "dummy accounts" - student accounts created but don't have a sign_in attempt.
use case: teacher creates a section of picture accounts many of which don't get used.

NOTE: right now delted accounts are filtered out at the base_users table. Waiting on a change
to that in order to make these counts accurate.
#}

with

all_users as (
users as (
select
user_id,
user_type,
created_at,
current_sign_in_at
from {{ref('stg_dashboard__users')}}
where current_sign_in_at is not NULL -- don't count "dummy accounts"
where current_sign_in_at is not null
),

user_geos as (
select
user_id,
is_international
from {{ref('stg_dashboard__user_geos')}}
where user_id in (select user_id from users)
),

all_accounts as (
select u.*, ug.is_international
from all_users u
left join user_geos ug on ug.user_id = u.user_id
combined as (
select
u.user_id,
u.created_at,
u.user_type,
ug.is_international
from users u
left join user_geos ug
on ug.user_id = u.user_id
),

school_years as (
Expand All @@ -40,21 +35,17 @@ school_years as (

final as (
select
user_type,
case when is_international = 1 then 'intl' else 'us' end as us_intl,
sy.school_year as created_at_school_year,
date_part(year, created_at) as created_at_year,
date_part(month, created_at) as created_at_month,
count(distinct user_id) as num_accounts
from all_accounts ac
left join school_years sy
on ac.created_at between sy.started_at and sy.ended_at
c.user_type,
case when c.is_international = 1 then 'intl' else 'us' end as us_intl,
sy.school_year as created_at_school_year,
date_part(year, c.created_at) as created_at_year,
date_part(month, c.created_at) as created_at_month,
count(distinct c.user_id) as num_accounts
from combined as c
left join school_years as sy
on c.created_at
between sy.started_at and sy.ended_at
{{ dbt_utils.group_by(5) }}
order by
created_at_year asc,
created_at_month asc,
user_type asc,
us_intl desc
)

select *
Expand Down
21 changes: 10 additions & 11 deletions dbt/models/marts/metrics/fct_monthly_signed_in_users.sql
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
{# Notes:
def: monthly signed-in users -- any user who has signed in at least once during a given month (and year)
segmented by student/teacher and us/intl
#}
with sign_ins as (
select *
from {{ ref('stg_dashboard__sign_ins')}}
),

all_users as (
users as (
select
user_id,
user_type
from {{ ref('stg_dashboard__users') }}

where user_id in (select user_id from sign_ins)
),

user_geos as (
select
user_id,
is_international
from {{ ref('stg_dashboard__user_geos') }}
where user_id in (select user_id from users)
),

school_years as (
Expand All @@ -28,20 +25,22 @@ school_years as (
),

final as (

select
u.user_type,
case when is_international = 1 then 'intl' else 'us' end as us_intl,
case when ug.is_international = 1 then 'intl' else 'us' end as us_intl,
sy.school_year as sign_in_school_year,
date_part(year, si.sign_in_at)::integer as sign_in_year,
date_part(month, si.sign_in_at)::integer as sign_in_month,
count(distinct si.user_id) as num_signed_in_users

from sign_ins as si
left join all_users u on si.user_id = u.user_id
left join user_geos ug on si.user_id = ug.user_id
left join users u
on si.user_id = u.user_id
left join user_geos ug
on si.user_id = ug.user_id
left join school_years sy
on sign_in_at between sy.started_at and sy.ended_at
on sign_in_at
between sy.started_at and sy.ended_at
{{ dbt_utils.group_by(5) }}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ with
source as (
select *
from {{ source('dashboard', 'users') }}
--where deleted_at is null
),

renamed as (
Expand Down

0 comments on commit 30f1a82

Please sign in to comment.