-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: bring back int_problem_results CTEs
- Loading branch information
Showing
1 changed file
with
76 additions
and
4 deletions.
There are no files selected for viewing
80 changes: 76 additions & 4 deletions
80
tutoraspects/templates/openedx-assets/queries/int_problem_results.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 |
---|---|---|
@@ -1,4 +1,76 @@ | ||
select * | ||
from {{ DBT_PROFILE_TARGET_DATABASE }}.int_problem_results | ||
where 1=1 | ||
{% include 'openedx-assets/queries/common_filters.sql' %} | ||
-- select one record per (learner, problem, course, org) tuple | ||
-- contains either the first successful attempt | ||
-- or the most recent unsuccessful attempt | ||
-- find the timestamp of the earliest successful response | ||
-- this will be used to pick the xAPI event corresponding to that submission | ||
with | ||
successful_responses as ( | ||
select org, course_key, problem_id, actor_id, first_success_at | ||
from {{ ASPECTS_XAPI_DATABASE }}.responses | ||
where isNotNull(first_success_at) | ||
{% include 'openedx-assets/queries/common_filters.sql' %} | ||
), | ||
-- for all learners who did not submit a successful response, | ||
-- find the timestamp of the most recent unsuccessful response | ||
unsuccessful_responses as ( | ||
select | ||
org, | ||
course_key, | ||
problem_id, | ||
actor_id, | ||
max(last_attempt_at) as last_attempt_at | ||
from {{ ASPECTS_XAPI_DATABASE }}.responses | ||
where actor_id not in (select distinct actor_id from successful_responses) | ||
group by org, course_key, problem_id, actor_id | ||
{% include 'openedx-assets/queries/common_filters.sql' %} | ||
), | ||
-- combine result sets for successful and unsuccessful problem submissions | ||
responses as ( | ||
select org, course_key, problem_id, actor_id, first_success_at as emission_time | ||
from successful_responses | ||
union all | ||
select org, course_key, problem_id, actor_id, last_attempt_at as emission_time | ||
from unsuccessful_responses | ||
), | ||
full_responses as ( | ||
select | ||
events.emission_time as emission_time, | ||
events.org as org, | ||
events.course_key as course_key, | ||
events.problem_id as problem_id, | ||
events.object_id as object_id, | ||
events.actor_id as actor_id, | ||
events.responses as responses, | ||
events.success as success, | ||
events.attempts as attempts, | ||
events.interaction_type as interaction_type | ||
from {{ ASPECTS_XAPI_DATABASE }}.problem_events events | ||
join responses using (org, course_key, problem_id, actor_id, emission_time) | ||
) | ||
|
||
select | ||
full_responses.emission_time as emission_time, | ||
full_responses.org as org, | ||
full_responses.course_key as course_key, | ||
blocks.course_name as course_name, | ||
blocks.course_run as course_run, | ||
full_responses.problem_id as problem_id, | ||
blocks.block_name as problem_name, | ||
blocks.display_name_with_location as problem_name_with_location, | ||
blocks.course_order as course_order, | ||
concat( | ||
'<a href="', full_responses.object_id, '" target="_blank">', blocks.block_name, '</a>' | ||
) as problem_link, | ||
full_responses.actor_id as actor_id, | ||
full_responses.responses as responses, | ||
full_responses.success as success, | ||
full_responses.attempts as attempts, | ||
full_responses.interaction_type as interaction_type, | ||
blocks.graded | ||
from full_responses | ||
join | ||
{{ DBT_PROFILE_TARGET_DATABASE }}.dim_course_blocks blocks | ||
on ( | ||
full_responses.course_key = blocks.course_key | ||
and full_responses.problem_id = blocks.block_id | ||
) |