Skip to content
Draft
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions components/RatingTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ const isModalOpen = ref(false);
<th
scope="col"
class="px-6 py-3 bg-gray-50 dark:bg-gray-800"
>
submissions
</th>
<th
scope="col"
class="px-6 py-3"
>
kills
</th>
Expand Down Expand Up @@ -137,6 +143,9 @@ const isModalOpen = ref(false);
{{ userRating.gamesPlayed }}
</td>
<td class="px-6 py-4 bg-gray-50 dark:bg-gray-800">
{{ userRating.submissionCount }}
</td>
<td class="px-6 py-4">
{{ userRating.kills }}
</td>
<td class="px-6 py-4">
Expand Down
15 changes: 15 additions & 0 deletions migrations/20250316194552_add_submission_count/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_User" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"password" TEXT NOT NULL,
"username" TEXT NOT NULL,
"submission_count" INTEGER NOT NULL DEFAULT 0
);
INSERT INTO "new_User" ("id", "password", "username") SELECT "id", "password", "username" FROM "User";
DROP TABLE "User";
ALTER TABLE "new_User" RENAME TO "User";
CREATE UNIQUE INDEX "User_username_key" ON "User"("username");
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;
9 changes: 5 additions & 4 deletions schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ generator client {
}

model User {
id Int @id @default(autoincrement())
password String
username String @unique
game_stats GameStats[]
id Int @id @default(autoincrement())
password String
username String @unique
submission_count Int @default(0)
game_stats GameStats[]
}

model Game {
Expand Down
7 changes: 7 additions & 0 deletions server/api/bot/submit.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import * as botCodeStore from "~/other/botCodeStore";
import { HTTP_STATUS_CODES } from "~/other/httpStatusCodes";
import { SUBMIT_COOLDOWN_MS } from "~/other/submitApiRatelimitConstants";
import prisma from "~/other/db";

const submitBotCodeSchema = z.object({
code: z.string(),
Expand All @@ -28,6 +29,12 @@
});
}

// Update the submission count in the database
await prisma.user.update({
where: { id: event.context.user.id },
data: { submission_count: { increment: 1 } }

Check failure on line 35 in server/api/bot/submit.post.ts

View workflow job for this annotation

GitHub Actions / lint

Missing trailing comma
});

botCodeStore.submitBotCode({
username: event.context.user.username,
userId: event.context.user.id,
Expand Down
13 changes: 12 additions & 1 deletion server/api/rating.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
export type UserRating = UserStats & {
userId: number;
username: string;
submissionCount: number;
score7days: number;
score24hours: number;
score1hour: number;
Expand Down Expand Up @@ -45,7 +46,13 @@
oneWeekAgo.setDate(oneWeekAgo.getDate() - 7);

// don't join users to not slow down the games query with another join
const users = await prisma.user.findMany();
const users = await prisma.user.findMany({
select: {
id: true,
username: true,
submission_count: true

Check failure on line 53 in server/api/rating.get.ts

View workflow job for this annotation

GitHub Actions / lint

Missing trailing comma
}

Check failure on line 54 in server/api/rating.get.ts

View workflow job for this annotation

GitHub Actions / lint

Missing trailing comma
});
const games = await prisma.game.findMany({
where: { start_time: { gte: oneWeekAgo } },
include: { game_stats: true },
Expand Down Expand Up @@ -148,10 +155,14 @@
targetLength: expectedDynamicStatCount,
});

// Get the user's submission count
const userSubmissionCount = users.find(u => u.id === rawUserStat.userId)?.submission_count ?? 0;

Check failure on line 160 in server/api/rating.get.ts

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces not allowed
return {
...rawUserStat.stats7days,
userId: rawUserStat.userId,
username: rawUserStat.username,
submissionCount: userSubmissionCount,
maxEndgameSize: Math.max(...rawUserStat.stats7days.endgameSizes),
avgEndgameSize: (
rawUserStat.stats7days.endgameSizes.reduce((acc, size) => acc + size, 0)
Expand Down
Loading