-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create mitxonline problem engagement marts (#953)
* create mart for mitxonline problem engagements * add problem summary mart to count for showanswer * update description
- Loading branch information
1 parent
71ab353
commit 55a1a9b
Showing
6 changed files
with
288 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...ol_dbt/models/intermediate/mitxonline/int__mitxonline__user_courseactivity_showanswer.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{{ config(materialized='view') }} | ||
|
||
with course_activities as ( | ||
select * from {{ ref('stg__mitxonline__openedx__tracking_logs__user_activity') }} | ||
where courserun_readable_id is not null | ||
) | ||
|
||
select | ||
user_username | ||
, courserun_readable_id | ||
, openedx_user_id | ||
, useractivity_path | ||
, useractivity_timestamp | ||
, json_query(useractivity_event_object, 'lax $.problem_id' omit quotes) as useractivity_problem_id | ||
from course_activities | ||
where useractivity_event_type = 'showanswer' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/ol_dbt/models/marts/mitxonline/marts__mitxonline_problem_submissions.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
with problem_response as ( | ||
select | ||
* | ||
, row_number() over ( | ||
partition by courserun_readable_id, user_username, useractivity_problem_id | ||
order by useractivity_problem_attempts desc | ||
) as most_recent_num | ||
from {{ ref('int__mitxonline__user_courseactivity_problemcheck') }} | ||
) | ||
|
||
, course_runs as ( | ||
select * from {{ ref('int__mitxonline__course_runs') }} | ||
) | ||
|
||
, users as ( | ||
select * from {{ ref('int__mitxonline__users') }} | ||
) | ||
|
||
select | ||
problem_response.user_username | ||
, problem_response.courserun_readable_id | ||
, problem_response.useractivity_problem_id as problem_id | ||
, problem_response.useractivity_problem_name as problem_name | ||
, problem_response.useractivity_problem_attempts as num_attempts | ||
, problem_response.useractivity_problem_student_answers as student_answers | ||
, problem_response.useractivity_problem_success as problem_success | ||
, problem_response.useractivity_problem_current_grade as problem_grade | ||
, problem_response.useractivity_problem_max_grade as problem_max_grade | ||
, problem_response.useractivity_timestamp as problem_submission_timestamp | ||
, users.user_full_name | ||
, users.user_email | ||
, course_runs.courserun_title | ||
, course_runs.course_number | ||
, course_runs.courserun_start_on | ||
, course_runs.courserun_end_on | ||
, if(problem_response.most_recent_num = 1, true, false) as is_most_recent_attempt | ||
from problem_response | ||
inner join course_runs on problem_response.courserun_readable_id = course_runs.courserun_readable_id | ||
left join users on problem_response.user_username = users.user_username |
75 changes: 75 additions & 0 deletions
75
src/ol_dbt/models/marts/mitxonline/marts__mitxonline_problem_summary.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
with showanswers as ( | ||
select * from {{ ref('int__mitxonline__user_courseactivity_showanswer') }} | ||
) | ||
|
||
, showanswers_stats as ( | ||
select | ||
user_username | ||
, courserun_readable_id | ||
, useractivity_problem_id | ||
, count(*) as num_showanswer | ||
from showanswers | ||
group by | ||
user_username | ||
, courserun_readable_id | ||
, useractivity_problem_id | ||
) | ||
|
||
, problem_attempts as ( | ||
select | ||
* | ||
, row_number() over ( | ||
partition by courserun_readable_id, user_username, useractivity_problem_id | ||
order by useractivity_problem_attempts desc | ||
) as row_num | ||
from {{ ref('int__mitxonline__user_courseactivity_problemcheck') }} | ||
) | ||
|
||
, most_recent_attempts as ( | ||
select * | ||
from problem_attempts | ||
where row_num = 1 | ||
) | ||
|
||
, course_runs as ( | ||
select * from {{ ref('int__mitxonline__course_runs') }} | ||
) | ||
|
||
, users as ( | ||
select * from {{ ref('int__mitxonline__users') }} | ||
) | ||
|
||
, combined as ( | ||
select | ||
showanswers_stats.num_showanswer | ||
, most_recent_attempts.useractivity_problem_attempts as num_attempts | ||
, most_recent_attempts.useractivity_problem_success as problem_success | ||
, coalesce(showanswers_stats.user_username, most_recent_attempts.user_username) as user_username | ||
, coalesce(showanswers_stats.courserun_readable_id, most_recent_attempts.courserun_readable_id) | ||
as courserun_readable_id | ||
, coalesce(showanswers_stats.useractivity_problem_id, most_recent_attempts.useractivity_problem_id) | ||
as useractivity_problem_id | ||
from showanswers_stats | ||
full outer join most_recent_attempts | ||
on | ||
showanswers_stats.user_username = most_recent_attempts.user_username | ||
and showanswers_stats.courserun_readable_id = most_recent_attempts.courserun_readable_id | ||
and showanswers_stats.useractivity_problem_id = most_recent_attempts.useractivity_problem_id | ||
) | ||
|
||
select | ||
combined.user_username | ||
, combined.courserun_readable_id | ||
, combined.useractivity_problem_id as problem_id | ||
, combined.num_showanswer | ||
, combined.num_attempts | ||
, combined.problem_success | ||
, users.user_full_name | ||
, users.user_email | ||
, course_runs.courserun_title | ||
, course_runs.course_number | ||
, course_runs.courserun_start_on | ||
, course_runs.courserun_end_on | ||
from combined | ||
inner join course_runs on combined.courserun_readable_id = course_runs.courserun_readable_id | ||
left join users on combined.user_username = users.user_username |