Skip to content

Commit

Permalink
Merge pull request #107 from edinstance/main
Browse files Browse the repository at this point in the history
Ranking changes
  • Loading branch information
delasy authored Oct 19, 2024
2 parents 66c749f + 19010c9 commit a10520e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/prompts/[promptId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function editPromtPage({
const prompt = useQuery(api.prompts.getPromptById, {
promptId: params.promptId,
});
console.log(prompt);

const updatePrompt = useMutation(api.prompts.updatePrompt);
const isAdmin = useQuery(api.users.isAdmin);

Expand Down
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
9 changes: 5 additions & 4 deletions convex/prompts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { v } from "convex/values";
import { internalMutation, mutation, query } from "./_generated/server";
import { Id } from "./_generated/dataModel";
import { adminMutationBuilder } from "./users";

const defaultPrompt = `
Your task is to play a game. We will give you a 2d array of characters that represent the game board. Before the game starts, you have these two tasks:
Expand Down Expand Up @@ -106,7 +107,7 @@ export const getAllPrompts = query({
},
});

export const createPrompt = mutation({
export const createPrompt = adminMutationBuilder({
args: {
promptName: v.string(),
prompt: v.string(),
Expand All @@ -121,7 +122,7 @@ export const createPrompt = mutation({
},
});

export const updatePrompt = mutation({
export const updatePrompt = adminMutationBuilder({
args: {
promptId: v.id("prompts"),
promptName: v.string(),
Expand All @@ -135,7 +136,7 @@ export const updatePrompt = mutation({
},
});

export const deletePrompt = mutation({
export const deletePrompt = adminMutationBuilder({
args: {
promptId: v.id("prompts"),
},
Expand All @@ -144,7 +145,7 @@ export const deletePrompt = mutation({
},
});

export const enablePrompt = mutation({
export const enablePrompt = adminMutationBuilder({
args: {
promptId: v.id("prompts"),
},
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 a10520e

Please sign in to comment.