Skip to content
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
wants to merge 18 commits into from

Conversation

ShenyiCui
Copy link
Contributor

@ShenyiCui ShenyiCui commented Oct 13, 2022

Changes

  • Added a new route at {{hostname}}/v2/courses/{{course}}/admin/users/total_xp used to output all students total XP.

@coveralls
Copy link

coveralls commented Oct 13, 2022

Coverage Status

coverage: 95.225% (-0.06%) from 95.284%
when pulling 92cd7b3 on feat-calculate-all-user-xp
into df78afa on master.

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"
"""
Copy link
Member

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?

@RichDom2185
Copy link
Member

Related frontend PR (merged): source-academy/frontend#2281

@RichDom2185
Copy link
Member

As discussed offline, we will close this PR and revert the already-merged frontend change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants