Skip to content

Commit be05a2a

Browse files
committed
Fix up wireframe wins
1 parent b4b7fd1 commit be05a2a

File tree

1 file changed

+39
-20
lines changed

1 file changed

+39
-20
lines changed
Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,40 @@
1+
WITH raw_winners AS (
2+
SELECT
3+
m."userId"::bigint AS user_id,
4+
NULLIF(TRIM(m.handle), '') AS handle,
5+
s."challengeId" AS challenge_id
6+
FROM reviews.submission s
7+
JOIN challenges."Challenge" c
8+
ON c.id = s."challengeId"
9+
JOIN challenges."ChallengeTrack" tr
10+
ON tr.id = c."trackId"
11+
JOIN members.member m
12+
ON m."userId"::text = s."memberId"::text
13+
WHERE s.placement = 1
14+
AND tr.abbreviation = 'DS'
15+
AND EXISTS (
16+
SELECT 1
17+
FROM UNNEST(c.tags) AS tag
18+
WHERE LOWER(tag) = 'wireframe'
19+
)
20+
),
21+
placements AS (
22+
SELECT
23+
user_id,
24+
handle,
25+
COUNT(DISTINCT challenge_id)::int AS wins_count
26+
FROM raw_winners
27+
WHERE handle IS NOT NULL
28+
GROUP BY user_id, handle
29+
)
130
SELECT
2-
m."userId" AS member_id,
3-
m.handle AS handle,
4-
COUNT(DISTINCT s."challengeId")::int AS wins_count,
5-
COUNT(DISTINCT s."challengeId")::int AS count
6-
FROM reviews.submission s
7-
JOIN challenges."Challenge" c
8-
ON c.id = s."challengeId"
9-
JOIN challenges."ChallengeTrack" tr
10-
ON tr.id = c."trackId"
11-
JOIN members.member m
12-
ON m."userId"::text = s."memberId"::text
13-
WHERE s.placement = 1
14-
AND tr.abbreviation = 'DS'
15-
AND EXISTS (
16-
SELECT 1
17-
FROM UNNEST(c.tags) AS tag
18-
WHERE LOWER(tag) = 'wireframe'
19-
)
20-
GROUP BY m."userId", m.handle
21-
ORDER BY wins_count DESC, handle ASC;
31+
p.handle AS "challenge_stats.winner_handle",
32+
p.handle AS handle,
33+
p.wins_count AS "challenge_stats.count",
34+
p.wins_count AS count,
35+
mmr.rating AS "member_profile_advanced.max_rating",
36+
DENSE_RANK() OVER (ORDER BY p.wins_count DESC, p.handle ASC)::int AS rank
37+
FROM placements p
38+
LEFT JOIN members."memberMaxRating" mmr
39+
ON mmr."userId" = p.user_id
40+
ORDER BY "challenge_stats.count" DESC, "challenge_stats.winner_handle" ASC;

0 commit comments

Comments
 (0)