-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #314 from SoryRawyer/rds/filter-on-course-key
refactor: use course_key index in dashboard queries (FC-0033)
- Loading branch information
Showing
17 changed files
with
320 additions
and
29 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
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
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
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
13 changes: 13 additions & 0 deletions
13
tutoraspects/templates/openedx-assets/queries/common_filters.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,13 @@ | ||
{% raw -%} | ||
{% if filter_values('org') != [] %} | ||
and org in {{ filter_values('org') | where_in }} | ||
{% endif %} | ||
|
||
{% if filter_values('course_name') != [] %} | ||
and course_key in ( | ||
select course_key | ||
from {% endraw -%}{{ ASPECTS_EVENT_SINK_DATABASE }}.course_names{%- raw %} | ||
where course_name in {{ filter_values('course_name') | where_in }} | ||
) | ||
{% endif %} | ||
{%- endraw %} |
18 changes: 18 additions & 0 deletions
18
tutoraspects/templates/openedx-assets/queries/fact_enrollments.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,18 @@ | ||
with enrollments as ( | ||
select * | ||
from {{ DBT_PROFILE_TARGET_DATABASE }}.fact_enrollments | ||
where | ||
1=1 | ||
{% include 'openedx-assets/queries/common_filters.sql' %} | ||
) | ||
|
||
select | ||
emission_time, | ||
org, | ||
course_key, | ||
course_name, | ||
course_run, | ||
actor_id, | ||
enrollment_mode, | ||
enrollment_status | ||
from enrollments |
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
120 changes: 120 additions & 0 deletions
120
tutoraspects/templates/openedx-assets/queries/fact_learner_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,120 @@ | ||
WITH problem_responses AS ( | ||
{% include 'openedx-assets/queries/fact_problem_responses.sql' %} | ||
), outcomes AS ( | ||
SELECT | ||
emission_time, | ||
org, | ||
course_key, | ||
problem_id, | ||
actor_id, | ||
success, | ||
first_value(success) OVER (PARTITION BY course_key, problem_id, actor_id ORDER BY success DESC) AS was_successful | ||
FROM problem_responses | ||
), successful_responses AS ( | ||
SELECT | ||
org, | ||
course_key, | ||
problem_id, | ||
actor_id, | ||
min(emission_time) AS first_success_at | ||
FROM outcomes | ||
WHERE was_successful = true and success = true | ||
GROUP BY | ||
org, | ||
course_key, | ||
problem_id, | ||
actor_id | ||
), unsuccessful_responses AS ( | ||
SELECT | ||
org, | ||
course_key, | ||
problem_id, | ||
actor_id, | ||
max(emission_time) AS last_response_at | ||
FROM outcomes | ||
WHERE was_successful = false | ||
GROUP BY | ||
org, | ||
course_key, | ||
problem_id, | ||
actor_id | ||
), final_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_response_at AS emission_time | ||
FROM unsuccessful_responses | ||
), int_problem_results AS ( | ||
SELECT | ||
emission_time, | ||
org, | ||
course_key, | ||
course_name, | ||
course_run, | ||
problem_id, | ||
problem_name, | ||
actor_id, | ||
responses, | ||
success, | ||
attempts | ||
FROM problem_responses | ||
INNER JOIN final_responses USING (org, course_key, problem_id, actor_id, emission_time) | ||
), summary AS ( | ||
SELECT | ||
org, | ||
course_key, | ||
course_name, | ||
course_run, | ||
problem_name, | ||
actor_id, | ||
success, | ||
attempts, | ||
0 AS num_hints_displayed, | ||
0 AS num_answers_displayed | ||
FROM int_problem_results | ||
UNION ALL | ||
SELECT | ||
org, | ||
course_key, | ||
course_name, | ||
course_run, | ||
problem_name, | ||
actor_id, | ||
NULL AS success, | ||
NULL AS attempts, | ||
caseWithExpression(help_type, 'hint', 1, 0) AS num_hints_displayed, | ||
caseWithExpression(help_type, 'answer', 1, 0) AS num_answers_displayed | ||
FROM {{ DBT_PROFILE_TARGET_DATABASE }}.int_problem_hints | ||
WHERE 1=1 | ||
{% include 'openedx-assets/queries/common_filters.sql' %} | ||
) | ||
|
||
SELECT | ||
org, | ||
course_key, | ||
course_name, | ||
course_run, | ||
problem_name, | ||
actor_id, | ||
coalesce(any(success), false) AS success, | ||
coalesce(any(attempts), 0) AS attempts, | ||
sum(num_hints_displayed) AS num_hints_displayed, | ||
sum(num_answers_displayed) AS num_answers_displayed | ||
FROM summary | ||
GROUP BY | ||
org, | ||
course_key, | ||
course_name, | ||
course_run, | ||
problem_name, | ||
actor_id |
Oops, something went wrong.