Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions sql/reports/challenges/registrants-history.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ filtered_challenges AS (
latest_phase."actualEndDate" as "challengeCompletedDate"
FROM
challenges."Challenge" c
JOIN challenges."ChallengeType" ct
ON ct.id = c."typeId"
LEFT JOIN LATERAL (
SELECT cp."actualEndDate"
FROM challenges."ChallengePhase" cp
Expand Down Expand Up @@ -44,7 +42,7 @@ filtered_challenges AS (
-- filter by challenge status
AND ($3::text[] IS NULL OR c.status::text = ANY($3::text[]))
-- exclude task challenge types from this report
AND LOWER(ct.name) NOT IN ('task', 'topgear task')
AND COALESCE(c."taskIsTask", false) = false
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ correctness]
The change from LOWER(ct.name) NOT IN ('task', 'topgear task') to COALESCE(c."taskIsTask", false) = false assumes that the taskIsTask column is correctly populated and equivalent to the previous logic. Ensure that this column accurately reflects the task status for all relevant records, as any discrepancies could lead to incorrect filtering of challenge types.

-- filter by completion date bounds on the latest challenge phase end date
AND (
($4::timestamptz IS NULL AND $5::timestamptz IS NULL)
Expand All @@ -70,31 +68,34 @@ registrants AS (
AND res."roleId" = sr.id
ORDER BY
fc.id,
res."memberId",
res."updatedAt" DESC NULLS LAST,
res."createdAt" DESC,
res.id DESC
res."memberId"
LIMIT 1000
),
winners AS (
-- keep one winner row per challenge/member
-- aggregate winners only for already-selected registrants
SELECT
cw."challengeId",
cw."userId"::text as "memberId",
r."challengeId",
r."memberId",
MAX(cw.handle) as "winnerHandle"
FROM challenges."ChallengeWinner" cw
FROM registrants r
JOIN challenges."ChallengeWinner" cw
ON cw."challengeId" = r."challengeId"
AND cw."userId"::text = r."memberId"
WHERE cw.placement = 1
GROUP BY cw."challengeId", cw."userId"
GROUP BY r."challengeId", r."memberId"
),
submissions AS (
-- keep one submission row per challenge/member
-- aggregate submissions only for already-selected registrants
SELECT
sub."challengeId",
sub."memberId",
r."challengeId",
r."memberId",
MAX(sub."finalScore") as "finalScore",
BOOL_OR(sub.placement = 1) as "isWinner"
FROM reviews."submission" sub
GROUP BY sub."challengeId", sub."memberId"
FROM registrants r
JOIN reviews.submission sub
ON sub."challengeId" = r."challengeId"
AND sub."memberId" = r."memberId"
GROUP BY r."challengeId", r."memberId"
)
SELECT
registrants."challengeId",
Expand All @@ -114,5 +115,4 @@ LEFT JOIN winners win
AND win."memberId" = registrants."memberId"
LEFT JOIN submissions sub
ON sub."challengeId" = registrants."challengeId"
AND sub."memberId" = registrants."memberId"
LIMIT 1000;
AND sub."memberId" = registrants."memberId";
Loading