Skip to content

Commit

Permalink
Create mitxonline problem engagement marts (#953)
Browse files Browse the repository at this point in the history
* create mart for mitxonline problem engagements

* add problem summary mart to count for showanswer

* update description
  • Loading branch information
rachellougee authored Jan 4, 2024
1 parent 71ab353 commit 55a1a9b
Show file tree
Hide file tree
Showing 6 changed files with 288 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,11 @@ models:
description: number, The number of times the user attempted to answer this problem
tests:
- not_null
- name: useractivity_problem_student_answers
description: json, student answers to this problem in problem_id and internal
answer pair. For multiple questions, it lists every question and answer.
tests:
- not_null
- name: useractivity_problem_success
description: str, It's either 'correct' or 'incorrect'
tests:
Expand Down Expand Up @@ -1543,6 +1548,41 @@ models:
column_list: ["user_username", "courserun_readable_id", "useractivity_problem_id",
"useractivity_timestamp"]

- name: int__mitxonline__user_courseactivity_showanswer
description: MITx Online learners show answer events within a course
columns:
- name: user_username
description: str, username of the open edX user
tests:
- not_null
- name: openedx_user_id
description: int, open edX user ID extracted from context field. This id doesn't
always match with auth_user in open edX table, there can be multiple openedx_user_ids
for the same user_username. For those cases, use openedx_user_id from auth_user
open edX table.
tests:
- not_null
- name: courserun_readable_id
description: str, Open edX Course ID formatted as course-v1:{org}+{course code}+{run_tag}
tests:
- not_null
- name: useractivity_path
description: str, relative url path of page when the answer to a problem is shown
event.
- name: useractivity_problem_id
description: str, Unique ID for this problem in a course, formatted as block-v1:{org)+{course
ID}+type@problem+block@{hash code}.
tests:
- not_null
- name: useractivity_timestamp
description: timestamp, time for this show answer event
tests:
- not_null
tests:
- dbt_expectations.expect_compound_columns_to_be_unique:
column_list: ["user_username", "courserun_readable_id", "useractivity_problem_id",
"useractivity_timestamp"]

- name: int__mitxonline__user_courseactivity_discussion
description: MITx Online learners discussion forum interaction within a course
columns:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ select
, useractivity_timestamp
, json_query(useractivity_context_object, 'lax $.module.display_name' omit quotes) as useractivity_problem_name
, json_query(useractivity_event_object, 'lax $.problem_id' omit quotes) as useractivity_problem_id
, json_query(useractivity_event_object, 'lax $.answers' omit quotes) as useractivity_problem_student_answers
, json_query(useractivity_event_object, 'lax $.attempts' omit quotes) as useractivity_problem_attempts
, json_query(useractivity_event_object, 'lax $.success' omit quotes) as useractivity_problem_success
, json_query(useractivity_event_object, 'lax $.grade' omit quotes) as useractivity_problem_current_grade
Expand Down
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'
117 changes: 117 additions & 0 deletions src/ol_dbt/models/marts/mitxonline/_marts__mitxonline__models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,120 @@ models:
description: timestamp, time of this video event
tests:
- not_null

- name: marts__mitxonline_problem_submissions
description: MITx Online learners problem submissions
columns:
- name: user_username
description: str, username of the open edX user
tests:
- not_null
- name: courserun_readable_id
description: str, Open edX Course ID formatted as course-v1:{org}+{course code}+{run_tag}
tests:
- not_null
- name: problem_id
description: str, Unique ID for this problem in a course. It's formatted in block-v1:{org)+{course
ID}+type@problem+block@{hash code}
tests:
- not_null
- name: problem_name
description: str, display name of this problem in a course
tests:
- not_null
- name: num_attempts
description: number, The number of times the user had attempted at the time of
this submission.
tests:
- not_null
- name: student_answers
description: json, student answers to this problem in a name/value (problem_id/answer)
pair. For multiple questions, it lists every question and answer.
tests:
- not_null
- name: problem_success
description: str, It's either 'correct' or 'incorrect'
tests:
- not_null
- name: problem_grade
description: number, user grade for this problem at the time of this submission.
It can range from 0 to the max possible grade for this problem. e.g. if problem_max_grade
is 12, problem_grade can be anywhere between 0 to 12.
tests:
- not_null
- name: problem_max_grade
description: number, Maximum possible grade value for this problem.
tests:
- not_null
- name: problem_submission_timestamp
description: timestamp, time for this problem submission
tests:
- not_null
- name: is_most_recent_attempt
description: boolean, indicating if this submission is the most recent attempt.
Useful to filter out any previous answers
tests:
- not_null
- name: user_email
description: str, user email on MITx Online
- name: user_full_name
description: str, user full name on MITx Online
- name: course_number
description: str, unique string for the course. It can contain letters, numbers,
or periods. e.g. 18.03.1x
tests:
- not_null
- name: courserun_title
description: str, title of the course run
- name: courserun_start_on
description: timestamp, datetime on when the course begins
- name: courserun_end_on
description: timestamp, datetime on when the course ends
tests:
- dbt_expectations.expect_compound_columns_to_be_unique:
column_list: ["user_username", "courserun_readable_id", "problem_id", "problem_submission_timestamp"]

- name: marts__mitxonline_problem_summary
description: MITx Online learners problem performance summary with a particular
problem
columns:
- name: user_username
description: str, username of the open edX user
tests:
- not_null
- name: courserun_readable_id
description: str, Open edX Course ID formatted as course-v1:{org}+{course code}+{run_tag}
tests:
- not_null
- name: problem_id
description: str, Unique ID for this problem in a course. It's formatted in block-v1:{org)+{course
ID}+type@problem+block@{hash code}
tests:
- not_null
- name: num_showanswer
description: number, The number of times the user clicked on showanswer for this
problem.
- name: num_attempts
description: number, The number of times the user had attempted this problem.
Null if user has never attempted this problem
- name: problem_success
description: str, indicating if user's most recent attempt to this problem is
correct or incorrect. Null if user has never attempted this problem
- name: user_email
description: str, user email on MITx Online
- name: user_full_name
description: str, user full name on MITx Online
- name: course_number
description: str, unique string for the course. It can contain letters, numbers,
or periods. e.g. 18.03.1x
tests:
- not_null
- name: courserun_title
description: str, title of the course run
- name: courserun_start_on
description: timestamp, datetime on when the course begins
- name: courserun_end_on
description: timestamp, datetime on when the course ends
tests:
- dbt_expectations.expect_compound_columns_to_be_unique:
column_list: ["user_username", "courserun_readable_id", "problem_id"]
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
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

0 comments on commit 55a1a9b

Please sign in to comment.