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
16 changes: 11 additions & 5 deletions sql/reports/topgear/hourly.sql
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ SELECT
ct.name AS challenge_type,
bc."registrationEndDate" AS registration_end_date,
bc."submissionEndDate" AS submission_end_date,
bc."endDate" AS completed_date,
pd.latest_actual_end_date AS completed_date,
mt.onsite_efforts AS onsite_efforts,
mt.offsite_efforts AS offsite_efforts,
COALESCE(rv.num_reviews, 0) AS num_reviews,
Expand Down Expand Up @@ -133,13 +133,13 @@ SELECT
bc."createdBy" AS creator,
bc."createdAt" AS creation_date,
CASE
WHEN bc.status = 'COMPLETED' AND bc."endDate" IS NOT NULL
THEN to_char(bc."endDate", 'Mon-YY')
WHEN bc.status = 'COMPLETED' AND pd.latest_actual_end_date IS NOT NULL
THEN to_char(pd.latest_actual_end_date, 'Mon-YY')
ELSE NULL
END AS completed_month,
CASE
WHEN bc.status = 'COMPLETED' AND bc."endDate" IS NOT NULL
THEN to_char(bc."endDate", 'DD-Mon-YYYY HH24:MI:SS')
WHEN bc.status = 'COMPLETED' AND pd.latest_actual_end_date IS NOT NULL
THEN to_char(pd.latest_actual_end_date, 'DD-Mon-YYYY HH24:MI:SS')
ELSE NULL
END AS completed_date_formatted,
bc."registrationStartDate" AS registration_start_date,
Expand Down Expand Up @@ -196,6 +196,12 @@ LEFT JOIN tag_list tl
ON tl.challenge_id = bc.id
LEFT JOIN group_list gl
ON gl.challenge_id = bc.id
LEFT JOIN LATERAL (
Copy link

Choose a reason for hiding this comment

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

[⚠️ correctness]
The new lateral join for latest_actual_end_date uses MAX(cp."actualEndDate") without any additional filtering or ordering. Ensure that actualEndDate is always populated correctly and that using MAX will consistently yield the correct completed_date. Consider if additional criteria are needed to ensure the correct phase is selected.

SELECT
MAX(cp."actualEndDate") AS latest_actual_end_date
FROM challenges."ChallengePhase" cp
WHERE cp."challengeId" = bc.id
) pd ON TRUE
LEFT JOIN LATERAL (
SELECT
COUNT(*)::int AS num_submissions,
Expand Down