Skip to content

Commit adda2d0

Browse files
committed
Updates to additional design reports - will have to test these in prod due to relatively little dev test data
1 parent c5f81e8 commit adda2d0

File tree

6 files changed

+175
-0
lines changed

6 files changed

+175
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
WITH raw_winners AS (
2+
SELECT
3+
cw."userId"::bigint AS user_id,
4+
COALESCE(NULLIF(TRIM(cw.handle), ''), m.handle) AS handle
5+
FROM challenges."ChallengeWinner" cw
6+
JOIN challenges."Challenge" c
7+
ON c.id = cw."challengeId"
8+
JOIN challenges."ChallengeTrack" tr
9+
ON tr.id = c."trackId"
10+
LEFT JOIN members.member m
11+
ON m."userId" = cw."userId"::bigint
12+
WHERE tr.abbreviation = 'DS'
13+
AND c.status = 'COMPLETED'
14+
AND cw.placement IS NOT NULL
15+
AND cw.placement > 0
16+
AND (
17+
c.name ILIKE 'LUX%'
18+
OR c.name ILIKE 'TCO LUX%'
19+
)
20+
),
21+
placements AS (
22+
SELECT
23+
user_id,
24+
handle,
25+
COUNT(*)::int AS placements_count
26+
FROM raw_winners
27+
WHERE handle IS NOT NULL
28+
GROUP BY user_id, handle
29+
)
30+
SELECT
31+
p.handle,
32+
p.placements_count AS wins_count,
33+
p.placements_count AS count,
34+
mmr.rating AS max_rating,
35+
DENSE_RANK() OVER (ORDER BY p.placements_count DESC, p.handle ASC)::int AS rank
36+
FROM placements p
37+
LEFT JOIN members."memberMaxRating" mmr
38+
ON mmr."userId" = p.user_id
39+
ORDER BY wins_count DESC, handle ASC;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
WITH member_placements AS (
2+
SELECT
3+
m."userId" AS member_id,
4+
m.handle AS handle,
5+
COUNT(DISTINCT s."challengeId")::int AS placements_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 IS NOT NULL
14+
AND s.placement > 0
15+
AND tr.abbreviation = 'DS'
16+
AND (
17+
c.name ILIKE 'RUX%'
18+
OR c.name ILIKE 'TCO RUX%'
19+
)
20+
GROUP BY m."userId", m.handle
21+
)
22+
SELECT
23+
member_id,
24+
handle,
25+
NULL::int AS max_rating,
26+
placements_count,
27+
placements_count AS count,
28+
RANK() OVER (ORDER BY placements_count DESC, handle ASC) AS rank
29+
FROM member_placements
30+
ORDER BY placements_count DESC, handle ASC;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
WITH member_wins AS (
2+
SELECT
3+
m."userId" AS member_id,
4+
m.handle AS handle,
5+
COUNT(DISTINCT s."challengeId")::int AS wins_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 (
16+
c.name ILIKE 'RUX%'
17+
OR c.name ILIKE 'TCO RUX%'
18+
)
19+
GROUP BY m."userId", m.handle
20+
)
21+
SELECT
22+
member_id,
23+
handle,
24+
NULL::int AS max_rating,
25+
wins_count,
26+
wins_count AS count,
27+
RANK() OVER (ORDER BY wins_count DESC, handle ASC) AS rank
28+
FROM member_wins
29+
ORDER BY wins_count DESC, handle ASC;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
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;

src/statistics/design-statistics.service.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,32 @@ export class DesignStatisticsService {
4343
);
4444
return this.db.query(q);
4545
}
46+
47+
async getRuxFirstPlaceWins() {
48+
const q = this.sql.load(
49+
"reports/statistics/design/rux-first-place-wins.sql",
50+
);
51+
return this.db.query(q);
52+
}
53+
54+
async getWireframeWins() {
55+
const q = this.sql.load(
56+
"reports/statistics/design/wireframe-wins.sql",
57+
);
58+
return this.db.query(q);
59+
}
60+
61+
async getLuxFirstPlaceWins() {
62+
const q = this.sql.load(
63+
"reports/statistics/design/lux-first-place-wins.sql",
64+
);
65+
return this.db.query(q);
66+
}
67+
68+
async getLuxPlacements() {
69+
const q = this.sql.load(
70+
"reports/statistics/design/lux-placements.sql",
71+
);
72+
return this.db.query(q);
73+
}
4674
}

src/statistics/statistics-design.controller.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ export class StatisticsDesignController {
1919
return this.design.getDesignF2FWins();
2020
}
2121

22+
@Get("/lux-first-place-wins")
23+
@ApiOperation({ summary: "Design LUX first place wins by member (desc)" })
24+
getLuxFirstPlaceWins() {
25+
return this.design.getLuxFirstPlaceWins();
26+
}
27+
28+
@Get("/lux-placements")
29+
@ApiOperation({ summary: "Design LUX placements by member (desc)" })
30+
getLuxPlacements() {
31+
return this.design.getLuxPlacements();
32+
}
33+
2234
@Get("/first-time-submitters")
2335
@ApiOperation({ summary: "First-time design submitters in last 3 months" })
2436
getFirstTimeDesignSubmitters() {
@@ -36,4 +48,20 @@ export class StatisticsDesignController {
3648
getDesignFirstPlaceByCountry() {
3749
return this.design.getFirstPlaceByCountry();
3850
}
51+
52+
@Get("/rux-first-place-wins")
53+
@ApiOperation({
54+
summary: "RUX first place design challenge wins by member (desc)",
55+
})
56+
getRuxFirstPlaceWins() {
57+
return this.design.getRuxFirstPlaceWins();
58+
}
59+
60+
@Get("/wireframe-wins")
61+
@ApiOperation({
62+
summary: "Design wireframe challenge wins by member (desc)",
63+
})
64+
getWireframeWins() {
65+
return this.design.getWireframeWins();
66+
}
3967
}

0 commit comments

Comments
 (0)