Skip to content

Commit

Permalink
feat: updated ranking schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
edinstance committed Oct 19, 2024
1 parent 41a457c commit 19010c9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions convex/leaderboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { api } from "./_generated/api";

export const getGlobalRankings = query({
handler: async ({ db }) => {
const res = await db.query("globalrankings").collect();
const res = await db.query("globalRankings").collect();
// Sort the results by wins/losses ratio

const sortedResults = res.sort((a, b) => {
Expand All @@ -23,7 +23,7 @@ export const getGlobalRankings = query({

export const getLevelRankings = query({
handler: async ({ db }) => {
const res = await db.query("levelrankings").collect();
const res = await db.query("levelRankings").collect();

const sortedResults = res.sort((a, b) => {
if (a.level < b.level) {
Expand Down Expand Up @@ -53,14 +53,14 @@ export const updateRankings = internalMutation({
}

const globalRanking = await ctx.db
.query("globalrankings")
.query("globalRankings")
.withIndex("by_modelId_promptId", (q) =>
q.eq("modelId", args.modelId).eq("promptId", activePrompt._id),
)
.first();

const levelRanking = await ctx.db
.query("levelrankings")
.query("levelRankings")
.withIndex("by_modelId_level_promptId", (q) =>
q
.eq("modelId", args.modelId)
Expand All @@ -70,7 +70,7 @@ export const updateRankings = internalMutation({
.first();

if (!globalRanking) {
await ctx.db.insert("globalrankings", {
await ctx.db.insert("globalRankings", {
modelId: args.modelId,
wins: args.isWin ? 1 : 0,
losses: args.isWin ? 0 : 1,
Expand All @@ -84,7 +84,7 @@ export const updateRankings = internalMutation({
}

if (!levelRanking) {
await ctx.db.insert("levelrankings", {
await ctx.db.insert("levelRankings", {
modelId: args.modelId,
level: args.level,
wins: args.isWin ? 1 : 0,
Expand Down
4 changes: 2 additions & 2 deletions convex/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ export default defineSchema({
})
.index("by_gameId_level", ["gameId", "level"])
.index("by_status", ["status"]),
globalrankings: defineTable({
globalRankings: defineTable({
modelId: v.string(),
wins: v.number(),
losses: v.number(),
promptId: v.optional(v.id("prompts")),
}).index("by_modelId_promptId", ["modelId", "promptId"]),
levelrankings: defineTable({
levelRankings: defineTable({
modelId: v.string(),
level: v.number(),
wins: v.number(),
Expand Down

0 comments on commit 19010c9

Please sign in to comment.