-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ Feat: Add all_users_total_xp
function and route
#914
Closed
Conversation
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
ShenyiCui
force-pushed
the
feat-calculate-all-user-xp
branch
from
October 13, 2022 09:33
ddea196
to
c4dfc27
Compare
chownces
requested changes
Jan 8, 2023
test/cadet_web/admin_controllers/admin_user_controller_test.exs
Outdated
Show resolved
Hide resolved
riccqi
force-pushed
the
feat-calculate-all-user-xp
branch
from
January 13, 2023 02:13
97a69ee
to
dfb4a37
Compare
RichDom2185
requested changes
Jun 16, 2023
Comment on lines
+124
to
+204
combined_user_xp_total_query = """ | ||
SELECT | ||
name, | ||
username, | ||
assessment_xp, | ||
achievement_xp | ||
FROM | ||
(SELECT | ||
sum(total_xp) as assessment_xp, | ||
users.name, | ||
users.username, | ||
total_xps.cr_id | ||
FROM | ||
( | ||
SELECT | ||
sum(sa1."xp") + sum(sa1."xp_adjustment") + max(ss0."xp_bonus") AS "total_xp", | ||
ss0."student_id" as cr_id, | ||
ss0.user_id | ||
FROM | ||
( | ||
SELECT | ||
submissions.xp_bonus, | ||
submissions.student_id, | ||
submissions.id, | ||
cr_ids.user_id | ||
FROM | ||
submissions | ||
INNER JOIN ( | ||
SELECT | ||
cr.id as id, | ||
cr.user_id | ||
FROM | ||
course_registrations cr | ||
WHERE | ||
cr.course_id = #{course_id} | ||
) cr_ids on cr_ids.id = submissions.student_id | ||
) as ss0 | ||
INNER JOIN "answers" sa1 ON ss0."id" = sa1."submission_id" | ||
GROUP BY | ||
ss0."id", | ||
ss0."student_id", | ||
ss0."user_id" | ||
) total_xps | ||
inner join users on users.id = total_xps.user_id | ||
GROUP BY | ||
username, | ||
cr_id, | ||
name) as total_assessments | ||
LEFT JOIN | ||
(SELECT | ||
sum(s0."xp") as achievement_xp, | ||
s0."course_reg_id" as cr_id | ||
FROM | ||
( | ||
SELECT | ||
CASE WHEN bool_and(is_variable_xp) THEN SUM(count) ELSE MAX(xp) END AS "xp", | ||
sg3."course_reg_id" AS "course_reg_id" | ||
FROM | ||
"achievements" AS sa0 | ||
INNER JOIN "achievement_to_goal" AS sa1 ON sa1."achievement_uuid" = sa0."uuid" | ||
INNER JOIN "goals" AS sg2 ON sg2."uuid" = sa1."goal_uuid" | ||
RIGHT OUTER JOIN "goal_progress" AS sg3 ON (sg3."goal_uuid" = sg2."uuid") | ||
WHERE | ||
(sa0."course_id" = #{course_id}) | ||
GROUP BY | ||
sa0."uuid", | ||
sg3."course_reg_id" | ||
HAVING | ||
( | ||
bool_and( | ||
( | ||
sg3."completed" | ||
AND (sg3."count" >= sg2."target_count") | ||
) | ||
AND NOT (sg3."course_reg_id" IS NULL) | ||
) | ||
) | ||
) AS s0 | ||
GROUP BY s0."course_reg_id") as total_achievement | ||
ON total_assessments."cr_id" = total_achievement."cr_id" | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a rationale why we have to use such a long raw SQL query? Why don't we just use our ORM methods?
Related frontend PR (merged): source-academy/frontend#2281 |
As discussed offline, we will close this PR and revert the already-merged frontend change. |
7 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
{{hostname}}/v2/courses/{{course}}/admin/users/total_xp
used to output all students total XP.