diff --git a/api/src/party/numeric-question-generator.ts b/api/src/party/numeric-question-generator.ts index ec4349b..d26bd3c 100644 --- a/api/src/party/numeric-question-generator.ts +++ b/api/src/party/numeric-question-generator.ts @@ -30,10 +30,10 @@ async function getAlbumReleaseYear({ const correct = track?.album?.release_date?.getFullYear() ?? new Date().getFullYear() - 1 - index; - const subject = track?.album?.name ?? track?.name ?? "the album"; + const subject = track?.album?.name ?? track?.name ?? "unknown album"; return { type: "numeric", - text: `What number best matches ${subject}?`, + text: `What's the release year of ${subject}?`, correct, range: getQuestionRange(correct, 5), points: 10, diff --git a/api/src/routes/party-socket.ts b/api/src/routes/party-socket.ts index a7a152a..cb9e04c 100644 --- a/api/src/routes/party-socket.ts +++ b/api/src/routes/party-socket.ts @@ -6,15 +6,15 @@ import { db } from "../db"; import { getMemberRecord, getPartyStatus } from "../party-data"; import type { PartySocketEvent, QuizState } from "../party-types"; -function userTopic(userId: string) { +export function userTopic(userId: string) { return `user:${userId}`; } -function partyTopic(partyId: string) { +export function partyTopic(partyId: string) { return `party:${partyId}`; } -const socketPartyId = new WeakMap(); +export const socketPartyId = new WeakMap(); export const pubsub = { _server: null as ReturnType | null, @@ -29,7 +29,7 @@ export const pubsub = { }, }; -async function broadcastQuizState(ws: any, partyId: string) { +export async function broadcastQuizState(ws: any, partyId: string) { const partyRecord = await db.query.party.findFirst({ where: { id: partyId }, }); diff --git a/api/src/workflows/quiz.ts b/api/src/workflows/quiz.ts index f35f3dd..680a35a 100644 --- a/api/src/workflows/quiz.ts +++ b/api/src/workflows/quiz.ts @@ -6,6 +6,7 @@ import { generatePartyQuestion } from "../party/question-generator"; import type { PartyAnalytics } from "../party/question-utils"; import { updatePartyData } from "../party/state"; import type { Question, QuizResponse, QuizRound, QuizState } from "../party-types"; +import { partyAnalysisWorkflow, PartyAnalysisWorkflow } from "./party-analysis"; const TOTAL_QUESTIONS = 5; @@ -34,13 +35,15 @@ export class QuizWorkflow extends ConfiguredInstance { answers: {}, scores: {}, history: [], - }; + }; + + await partyAnalysisWorkflow.analyzeParty(partyId) // Initialize quiz state await QuizWorkflow.updatePartyData(partyId, quizState); // Get party members to initialize scores - const members = await QuizWorkflow.getPartyMembers(partyId); + let members = await QuizWorkflow.getPartyMembers(partyId); for (const member of members) { quizState.scores[member.userId] = 0; } @@ -63,6 +66,7 @@ export class QuizWorkflow extends ConfiguredInstance { quizState.history.push(round); await QuizWorkflow.updatePartyData(partyId, quizState); + members = await QuizWorkflow.getPartyMembers(partyId); // Wait for all responses with timeout const memberIds = new Set(members.map((m) => m.userId)); const receivedPlayers = new Set(); @@ -72,9 +76,10 @@ export class QuizWorkflow extends ConfiguredInstance { deadlineEpochMS: question.endTimestamp, }); - if (response === null) { + if (response === null) { // Timeout - fill in missing players with no answer const now = Date.now(); + if (now < question.endTimestamp) continue; for (const memberId of memberIds) { if (!receivedPlayers.has(memberId)) { receivedPlayers.add(memberId); diff --git a/dev-proxy/index.ts b/dev-proxy/index.ts index 5442734..dd373c5 100644 --- a/dev-proxy/index.ts +++ b/dev-proxy/index.ts @@ -22,6 +22,10 @@ Bun.listen({ case "party_status": const { party: { data: { currentQuestion } } } = data; console.log(currentQuestion) + let text = currentQuestion?.text + if (text) { + ws?.send(text) + } break; } } diff --git a/web/src/components/party/question.tsx b/web/src/components/party/question.tsx index 81da99a..74e10cf 100644 --- a/web/src/components/party/question.tsx +++ b/web/src/components/party/question.tsx @@ -132,12 +132,6 @@ export function Question() { {question.type === "numeric" ? ( - - Choose a value - - Closest guesses get more points - -
setSelectedValue(value[0] ?? null)} + onValueChange={(value) => setSelectedValue(typeof value === "number" ? value : value[0] ?? null)} />
Exact value:{" "}