diff --git a/packages/database/src/BotDatabase.ts b/packages/database/src/BotDatabase.ts index ef9e878..3d32019 100644 --- a/packages/database/src/BotDatabase.ts +++ b/packages/database/src/BotDatabase.ts @@ -15,8 +15,9 @@ import type { const CONFIG_PRIMARY_BOT_USER_ID = "primary_bot_user_id" -export interface NameAndPointTotal { +export interface PointStanding { name: string + rank: number numPoints: number } @@ -422,7 +423,7 @@ export class BotDatabase implements BotStorageLayer { }) } - async getTopPointsWithTwitchNames(): Promise { + async getTopPointsWithTwitchNames(): Promise { const response = await db .selectFrom("points") .innerJoin("users", "points.user_id", "users.id") @@ -432,14 +433,18 @@ export class BotDatabase implements BotStorageLayer { "user_correlation.twitch_id", "twitch_names.twitch_id", ) - .select(["twitch_names.name", "points.num_points"]) - .orderBy("points.num_points", "desc") + .select([ + "twitch_names.name", + "points.num_points", + sql`DENSE_RANK() OVER (ORDER BY num_points DESC)`.as("rank"), + ]) + .orderBy("rank", "asc") .orderBy("twitch_names.name", "asc") .where("points.num_points", ">", 0) .execute() - return response.map(({ name, num_points }) => { - return { name, numPoints: num_points } + return response.map(({ name, num_points, rank }) => { + return { name, numPoints: num_points, rank } }) } } diff --git a/packages/web/src/pages/points.astro b/packages/web/src/pages/points.astro index 22c86ab..2d82c11 100644 --- a/packages/web/src/pages/points.astro +++ b/packages/web/src/pages/points.astro @@ -8,25 +8,96 @@ const topPoints = await botDatabase.getTopPointsWithTwitchNames() --- -

- Point totals in Adam's Twitch channel + -

-
- (note that points are only ever given by Adam or moderators and don't really - mean anything 🤫) + + + + + + + + + + + +
+ +
+
+

+ Point totals in Adam's Twitch channel +

+ + + + + + + + + + + { + topPoints.map(({ name, numPoints, rank }) => { + const medalColors = ["gold", "silver", "bronze"] + const showMedal = rank < 4 + const medalClasses = showMedal + ? `medal-rank medal-${medalColors[rank - 1]}` + : "" + const rankHtml = showMedal ? ( +
+
+ {rank} +
+ + +
+ ) : ( + {rank} + ) + return ( + + + + + + ) + }) + } + +
+ (note that points are only ever given by Adam or moderators and don't + really mean anything 🤫) +
RankUserPoints
{rankHtml}{name}{numPoints}
+
-
    - { - topPoints.map(({ name, numPoints }) => ( -
  1. - {name}: {numPoints} -
  2. - )) - } -