-
Notifications
You must be signed in to change notification settings - Fork 0
Fix completion date filter issue for challenge reports #51
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,13 +4,21 @@ SELECT | |
| c.groups as "groupNames", | ||
| c.status as "challengeStatus", | ||
| c."registrationStartDate" as "registrationStartDate", | ||
| CASE WHEN c.status = 'COMPLETED' THEN | ||
| (SELECT cp."actualEndDate" FROM challenges."ChallengePhase" cp WHERE cp."challengeId"=c.id ORDER BY cp."scheduledEndDate" DESC LIMIT 1) | ||
| ELSE null END as "challengeCompletionDate", | ||
| CASE | ||
| WHEN c.status = 'COMPLETED' THEN latest_phase."actualEndDate" | ||
| ELSE null | ||
| END as "challengeCompletionDate", | ||
| c.tags as "tags", | ||
| c."projectId" as "projectId" | ||
| FROM | ||
| challenges."Challenge" c | ||
| LEFT JOIN LATERAL ( | ||
| SELECT cp."actualEndDate" | ||
| FROM challenges."ChallengePhase" cp | ||
| WHERE cp."challengeId" = c.id | ||
| ORDER BY cp."scheduledEndDate" DESC | ||
| LIMIT 1 | ||
| ) latest_phase ON true | ||
| LEFT JOIN | ||
| challenges."ChallengeBilling" cb on cb."challengeId"=c.id | ||
| -- filter by billing account | ||
|
|
@@ -19,40 +27,13 @@ WHERE ($1::text[] IS NULL OR cb."billingAccountId" = ANY($1::text[])) | |
| AND ($2::text[] IS NULL OR cb."billingAccountId" <> ANY($2::text[])) | ||
| -- filter by challenge status | ||
| AND ($3::text[] IS NULL OR c.status::text= ANY($3::text[])) | ||
| -- -- filter by completion date | ||
| -- filter by challengeCompletedDate | ||
| AND (c.status!='COMPLETED' OR ( | ||
| -- filter by completion date bounds on the latest challenge phase end date | ||
| AND ( | ||
| ($4::timestamptz IS NULL AND $5::timestamptz IS NULL) | ||
| OR ( | ||
| $5::timestamptz IS NULL AND ( | ||
| ( | ||
| SELECT cp."actualEndDate" | ||
| FROM challenges."ChallengePhase" cp | ||
| WHERE cp."challengeId" = c.id | ||
| ORDER BY cp."scheduledEndDate" DESC | ||
| LIMIT 1 | ||
| ) >= $4::timestamptz | ||
| ) | ||
| latest_phase."actualEndDate" IS NOT NULL | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| AND ($4::timestamptz IS NULL OR latest_phase."actualEndDate" >= $4::timestamptz) | ||
| AND ($5::timestamptz IS NULL OR latest_phase."actualEndDate" <= $5::timestamptz) | ||
| ) | ||
| OR ( | ||
| $4::timestamptz IS NULL AND $5::timestamptz IS NOT NULL AND ( | ||
| ( | ||
| SELECT cp."actualEndDate" | ||
| FROM challenges."ChallengePhase" cp | ||
| WHERE cp."challengeId" = c.id | ||
| ORDER BY cp."scheduledEndDate" DESC | ||
| LIMIT 1 | ||
| ) >= $5::timestamptz | ||
| ) | ||
| ) | ||
| OR ( | ||
| $4::timestamptz IS NOT NULL AND $5::timestamptz IS NOT NULL AND (( | ||
| SELECT cp."actualEndDate" | ||
| FROM challenges."ChallengePhase" cp | ||
| WHERE cp."challengeId" = c.id | ||
| ORDER BY cp."scheduledEndDate" DESC | ||
| LIMIT 1 | ||
| ) BETWEEN $4::timestamptz AND $5::timestamptz) | ||
| ) | ||
| )) | ||
| ) | ||
| LIMIT 1000; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,13 +3,21 @@ SELECT | |
| c.status as "challengeStatus", | ||
| cw.handle as "winnerHandle", | ||
| CASE WHEN sub.placement = 1 THEN true ELSE false END as "isWinner", | ||
| CASE WHEN c.status = 'COMPLETED' THEN | ||
| (SELECT cp."actualEndDate" FROM challenges."ChallengePhase" cp WHERE cp."challengeId"=c.id ORDER BY cp."scheduledEndDate" DESC LIMIT 1) | ||
| ELSE null END as "challengeCompletedDate", | ||
| CASE | ||
| WHEN c.status = 'COMPLETED' THEN latest_phase."actualEndDate" | ||
| ELSE null | ||
| END as "challengeCompletedDate", | ||
| res."memberHandle" as "registrantHandle", | ||
| ROUND(sub."finalScore", 2) as "registrantFinalScore" | ||
| FROM | ||
| challenges."Challenge" c | ||
| LEFT JOIN LATERAL ( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| SELECT cp."actualEndDate" | ||
| FROM challenges."ChallengePhase" cp | ||
| WHERE cp."challengeId" = c.id | ||
| ORDER BY cp."scheduledEndDate" DESC | ||
| LIMIT 1 | ||
| ) latest_phase ON true | ||
| LEFT JOIN | ||
| resources."Resource" res ON c.id = res."challengeId" | ||
| LEFT JOIN | ||
|
|
@@ -27,40 +35,13 @@ WHERE rr.name = 'Submitter' | |
| AND ($2::text[] IS NULL OR cb."billingAccountId" <> ANY($2::text[])) | ||
| -- filter by challenge status | ||
| AND ($3::text[] IS NULL OR c.status::text= ANY($3::text[])) | ||
| -- -- filter by completion date | ||
| -- filter by challengeCompletedDate | ||
| AND (c.status!='COMPLETED' OR ( | ||
| -- filter by completion date bounds on the latest challenge phase end date | ||
| AND ( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| ($4::timestamptz IS NULL AND $5::timestamptz IS NULL) | ||
| OR ( | ||
| $5::timestamptz IS NULL AND ( | ||
| ( | ||
| SELECT cp."actualEndDate" | ||
| FROM challenges."ChallengePhase" cp | ||
| WHERE cp."challengeId" = c.id | ||
| ORDER BY cp."scheduledEndDate" DESC | ||
| LIMIT 1 | ||
| ) >= $4::timestamptz | ||
| ) | ||
| latest_phase."actualEndDate" IS NOT NULL | ||
| AND ($4::timestamptz IS NULL OR latest_phase."actualEndDate" >= $4::timestamptz) | ||
| AND ($5::timestamptz IS NULL OR latest_phase."actualEndDate" <= $5::timestamptz) | ||
| ) | ||
| OR ( | ||
| $4::timestamptz IS NULL AND $5::timestamptz IS NOT NULL AND ( | ||
| ( | ||
| SELECT cp."actualEndDate" | ||
| FROM challenges."ChallengePhase" cp | ||
| WHERE cp."challengeId" = c.id | ||
| ORDER BY cp."scheduledEndDate" DESC | ||
| LIMIT 1 | ||
| ) >= $5::timestamptz | ||
| ) | ||
| ) | ||
| OR ( | ||
| $4::timestamptz IS NOT NULL AND $5::timestamptz IS NOT NULL AND (( | ||
| SELECT cp."actualEndDate" | ||
| FROM challenges."ChallengePhase" cp | ||
| WHERE cp."challengeId" = c.id | ||
| ORDER BY cp."scheduledEndDate" DESC | ||
| LIMIT 1 | ||
| ) BETWEEN $4::timestamptz AND $5::timestamptz) | ||
| ) | ||
| )) | ||
| ) | ||
| LIMIT 1000; | ||
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.
[⚠️
performance]The use of
LEFT JOIN LATERALis a good choice for fetching the latest phase'sactualEndDate. However, ensure that the database engine being used supports this feature efficiently, as it might have performance implications depending on the size of theChallengePhasetable.