This commit is contained in:
Daniel Bulant 2026-05-04 11:06:01 +02:00
parent b01eccb447
commit 14ccaee48c
No known key found for this signature in database
5 changed files with 19 additions and 16 deletions

View file

@ -30,10 +30,10 @@ async function getAlbumReleaseYear({
const correct = const correct =
track?.album?.release_date?.getFullYear() ?? track?.album?.release_date?.getFullYear() ??
new Date().getFullYear() - 1 - index; new Date().getFullYear() - 1 - index;
const subject = track?.album?.name ?? track?.name ?? "the album"; const subject = track?.album?.name ?? track?.name ?? "unknown album";
return { return {
type: "numeric", type: "numeric",
text: `What number best matches ${subject}?`, text: `What's the release year of ${subject}?`,
correct, correct,
range: getQuestionRange(correct, 5), range: getQuestionRange(correct, 5),
points: 10, points: 10,

View file

@ -6,15 +6,15 @@ import { db } from "../db";
import { getMemberRecord, getPartyStatus } from "../party-data"; import { getMemberRecord, getPartyStatus } from "../party-data";
import type { PartySocketEvent, QuizState } from "../party-types"; import type { PartySocketEvent, QuizState } from "../party-types";
function userTopic(userId: string) { export function userTopic(userId: string) {
return `user:${userId}`; return `user:${userId}`;
} }
function partyTopic(partyId: string) { export function partyTopic(partyId: string) {
return `party:${partyId}`; return `party:${partyId}`;
} }
const socketPartyId = new WeakMap<object, string>(); export const socketPartyId = new WeakMap<object, string>();
export const pubsub = { export const pubsub = {
_server: null as ReturnType<typeof Bun.serve> | null, _server: null as ReturnType<typeof Bun.serve> | 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({ const partyRecord = await db.query.party.findFirst({
where: { id: partyId }, where: { id: partyId },
}); });

View file

@ -6,6 +6,7 @@ import { generatePartyQuestion } from "../party/question-generator";
import type { PartyAnalytics } from "../party/question-utils"; import type { PartyAnalytics } from "../party/question-utils";
import { updatePartyData } from "../party/state"; import { updatePartyData } from "../party/state";
import type { Question, QuizResponse, QuizRound, QuizState } from "../party-types"; import type { Question, QuizResponse, QuizRound, QuizState } from "../party-types";
import { partyAnalysisWorkflow, PartyAnalysisWorkflow } from "./party-analysis";
const TOTAL_QUESTIONS = 5; const TOTAL_QUESTIONS = 5;
@ -34,13 +35,15 @@ export class QuizWorkflow extends ConfiguredInstance {
answers: {}, answers: {},
scores: {}, scores: {},
history: [], history: [],
}; };
await partyAnalysisWorkflow.analyzeParty(partyId)
// Initialize quiz state // Initialize quiz state
await QuizWorkflow.updatePartyData(partyId, quizState); await QuizWorkflow.updatePartyData(partyId, quizState);
// Get party members to initialize scores // Get party members to initialize scores
const members = await QuizWorkflow.getPartyMembers(partyId); let members = await QuizWorkflow.getPartyMembers(partyId);
for (const member of members) { for (const member of members) {
quizState.scores[member.userId] = 0; quizState.scores[member.userId] = 0;
} }
@ -63,6 +66,7 @@ export class QuizWorkflow extends ConfiguredInstance {
quizState.history.push(round); quizState.history.push(round);
await QuizWorkflow.updatePartyData(partyId, quizState); await QuizWorkflow.updatePartyData(partyId, quizState);
members = await QuizWorkflow.getPartyMembers(partyId);
// Wait for all responses with timeout // Wait for all responses with timeout
const memberIds = new Set(members.map((m) => m.userId)); const memberIds = new Set(members.map((m) => m.userId));
const receivedPlayers = new Set<string>(); const receivedPlayers = new Set<string>();
@ -72,9 +76,10 @@ export class QuizWorkflow extends ConfiguredInstance {
deadlineEpochMS: question.endTimestamp, deadlineEpochMS: question.endTimestamp,
}); });
if (response === null) { if (response === null) {
// Timeout - fill in missing players with no answer // Timeout - fill in missing players with no answer
const now = Date.now(); const now = Date.now();
if (now < question.endTimestamp) continue;
for (const memberId of memberIds) { for (const memberId of memberIds) {
if (!receivedPlayers.has(memberId)) { if (!receivedPlayers.has(memberId)) {
receivedPlayers.add(memberId); receivedPlayers.add(memberId);

View file

@ -22,6 +22,10 @@ Bun.listen({
case "party_status": case "party_status":
const { party: { data: { currentQuestion } } } = data; const { party: { data: { currentQuestion } } } = data;
console.log(currentQuestion) console.log(currentQuestion)
let text = currentQuestion?.text
if (text) {
ws?.send(text)
}
break; break;
} }
} }

View file

@ -132,12 +132,6 @@ export function Question() {
{question.type === "numeric" ? ( {question.type === "numeric" ? (
<Item variant="muted"> <Item variant="muted">
<ItemContent> <ItemContent>
<ItemHeader>
<ItemTitle>Choose a value</ItemTitle>
<ItemDescription>
Closest guesses get more points
</ItemDescription>
</ItemHeader>
<div className="space-y-3"> <div className="space-y-3">
<Slider <Slider
min={numericMin} min={numericMin}
@ -148,7 +142,7 @@ export function Question() {
? [currentNumericSelection] ? [currentNumericSelection]
: undefined : undefined
} }
onValueChange={(value) => setSelectedValue(value[0] ?? null)} onValueChange={(value) => setSelectedValue(typeof value === "number" ? value : value[0] ?? null)}
/> />
<div className="text-sm text-muted-foreground"> <div className="text-sm text-muted-foreground">
Exact value:{" "} Exact value:{" "}