improved gen

This commit is contained in:
Daniel Bulant 2026-05-13 11:27:32 +02:00
parent 93861bb7ce
commit aaff97aeb1
No known key found for this signature in database
4 changed files with 19 additions and 14 deletions

View file

@ -13,7 +13,7 @@ import {
export function buildAudioMetadataQuestion( export function buildAudioMetadataQuestion(
analytics: PartyAnalytics, analytics: PartyAnalytics,
index: number, index: number,
): Question { ): Question | null {
type ChoiceQuestion = Extract<Question, { type: "choice" }>; type ChoiceQuestion = Extract<Question, { type: "choice" }>;
const questions: Array< const questions: Array<
Omit<ChoiceQuestion, "startTimestamp" | "endTimestamp"> Omit<ChoiceQuestion, "startTimestamp" | "endTimestamp">
@ -126,8 +126,8 @@ export function buildAudioMetadataQuestion(
} }
} }
if (questions.length === 0) { if (questions.length === 0) {
throw new Error("Question not found"); return null
} }
const question = questions[index % questions.length]; const question = questions[index % questions.length];

View file

@ -113,7 +113,7 @@ async function countFavouriteArtistListeners({
export async function buildNumericQuestion( export async function buildNumericQuestion(
input: BuildNumericQuestionInput, input: BuildNumericQuestionInput,
): Promise<Question> { ): Promise<Question|null> {
const questions: NumericQuestion[] = []; const questions: NumericQuestion[] = [];
questions.push(await getAlbumReleaseYear(input)); questions.push(await getAlbumReleaseYear(input));
@ -125,6 +125,6 @@ export async function buildNumericQuestion(
if (artistQ) questions.push(artistQ); if (artistQ) questions.push(artistQ);
const question = questions[input.index % questions.length] ?? questions[0]; const question = questions[input.index % questions.length] ?? questions[0];
if (!question) throw new Error("Question not found"); if (!question) return null;
return buildQuestionWindow(question); return buildQuestionWindow(question);
} }

View file

@ -22,13 +22,18 @@ export async function generatePartyQuestion({
quizState, quizState,
analytics, analytics,
index, index,
}: GenerateQuestionInput): Promise<Question> { }: GenerateQuestionInput): Promise<Question | null> {
const members = await fetchPartyMembers(dbClient, partyId); const members = await fetchPartyMembers(dbClient, partyId);
const type: PartyQuestionType = const type: PartyQuestionType =
index === 2 ? "numeric" : index % 2 === 0 ? "audio-metadata" : "social"; index === 2 ? "numeric" : index % 2 === 0 ? "audio-metadata" : "social";
return type === "audio-metadata"
? buildAudioMetadataQuestion(analytics, index) if (type === "audio-metadata") {
: type === "numeric" let q = buildAudioMetadataQuestion(analytics, index);
? buildNumericQuestion({ db: dbClient, analytics, index, members }) if (q) return q;
: buildSocialQuestion(quizState, analytics, members, index); }
if (type === "numeric") {
let q = await buildNumericQuestion({ db: dbClient, analytics, index, members });
if (q) return q;
}
return buildSocialQuestion(quizState, analytics, members, index);
} }

View file

@ -19,7 +19,7 @@ export function buildSocialQuestion(
analytics: PartyAnalytics, analytics: PartyAnalytics,
members: PartyQuestionMember[], members: PartyQuestionMember[],
index: number, index: number,
): Question { ): Question | null {
type ChoiceQuestion = Extract<Question, { type: "choice" }>; type ChoiceQuestion = Extract<Question, { type: "choice" }>;
const questions: Array< const questions: Array<
Omit<ChoiceQuestion, "startTimestamp" | "endTimestamp"> Omit<ChoiceQuestion, "startTimestamp" | "endTimestamp">
@ -98,8 +98,8 @@ export function buildSocialQuestion(
} }
} }
if (questions.length === 0) { if (questions.length === 0) {
throw new Error("Question not found"); return null
} }
const question = questions[index % questions.length]; const question = questions[index % questions.length];