From 8d2f86b3f82647a8e2a5f17542d253abf2f08208 Mon Sep 17 00:00:00 2001 From: Daniel Bulant Date: Thu, 14 May 2026 00:53:03 +0200 Subject: [PATCH] more questions --- api/src/party-types.ts | 1 + api/src/party/audio-question-generator.ts | 48 ++++++++++++++++++++-- api/src/party/social-question-generator.ts | 21 +++++----- web/src/components/party/question.tsx | 18 ++++---- 4 files changed, 63 insertions(+), 25 deletions(-) diff --git a/api/src/party-types.ts b/api/src/party-types.ts index d889b31..9117a1c 100644 --- a/api/src/party-types.ts +++ b/api/src/party-types.ts @@ -35,6 +35,7 @@ type BaseQuestion = { endTimestamp: number; points: number; song?: Song; + hideSongTitle?: boolean; }; export type Question = diff --git a/api/src/party/audio-question-generator.ts b/api/src/party/audio-question-generator.ts index 67103ef..3bcb4c5 100644 --- a/api/src/party/audio-question-generator.ts +++ b/api/src/party/audio-question-generator.ts @@ -7,6 +7,7 @@ import { getMostSharedGenreNames, getTopClusterArtists, getTopClusterTracks, + isUsableText, type PartyAnalytics, pickRandom, resolveQuestionSong, @@ -22,6 +23,27 @@ export async function buildAudioMetadataQuestion( Omit > = []; const topSong = await resolveQuestionSong(dbClient, analytics); + const topSongName = topSong?.name; + const topTracks = getTopClusterTracks(analytics); + const topTrackNames = topTracks.map((track) => track.name); + if (isUsableText(topSongName)) { + const currentSongOptions = buildOptionsWithCorrect( + topSongName, + topTrackNames, + 4, + ); + if (currentSongOptions) { + questions.push({ + type: "choice", + text: "What song is currently playing?", + options: currentSongOptions, + correct: 0, + points: 10, + song: topSong ?? undefined, + hideSongTitle: true, + }); + } + } const genreOptions = buildOrderedOptions( getMostSharedGenreNames(analytics), @@ -54,12 +76,10 @@ export async function buildAudioMetadataQuestion( } } - const topTracks = getTopClusterTracks(analytics); if (topTracks.length > 0) { - const trackNames = topTracks.map((track) => track.name); - const topTrackName = trackNames[0]; + const topTrackName = topTrackNames[0]; const trackOptions = topTrackName - ? buildOptionsWithCorrect(topTrackName, trackNames, 4) + ? buildOptionsWithCorrect(topTrackName, topTrackNames, 4) : null; if (trackOptions) { questions.push({ @@ -115,8 +135,28 @@ export async function buildAudioMetadataQuestion( correct: 0, points: 10, song: randomTrackSong ?? topSong ?? undefined, + hideSongTitle: true, }); } + + if (isUsableText(topSongName) && topSongName !== randomTopTrack.name) { + const alternateSongOptions = buildOptionsWithCorrect( + topSongName, + trackNames, + 4, + ); + if (alternateSongOptions) { + questions.push({ + type: "choice", + text: "Which song is this audio clip from?", + options: alternateSongOptions, + correct: 0, + points: 10, + song: topSong ?? undefined, + hideSongTitle: true, + }); + } + } } if (randomTopTrack.albumName) { diff --git a/api/src/party/social-question-generator.ts b/api/src/party/social-question-generator.ts index 9c9c200..14e27ba 100644 --- a/api/src/party/social-question-generator.ts +++ b/api/src/party/social-question-generator.ts @@ -62,6 +62,15 @@ export async function buildSocialQuestion( points: 10, song: topSong ?? undefined, }); + + questions.push({ + type: "choice", + text: "Who would you ask for a recommendation based on the party taste?", + options: buildMemberOptions(aligned, members), + correct: 0, + points: 10, + song: topSong ?? undefined, + }); } const topTracks = getTopClusterTracks(analytics); @@ -76,15 +85,7 @@ export async function buildSocialQuestion( }); questions.push({ type: "choice", - text: `Who listens the most to "${randomTrack.name}"?`, - options: buildMemberOptions(topListener, members), - correct: 0, - points: 10, - song: randomTrackSong ?? topSong ?? undefined, - }); - questions.push({ - type: "choice", - text: `"${randomTrack.name}" appears most in which player's listening history?`, + text: `Who is most likely to have "${randomTrack.name}" in heavy rotation?`, options: buildMemberOptions(topListener, members), correct: 0, points: 10, @@ -103,7 +104,7 @@ export async function buildSocialQuestion( if (pairOptions) { questions.push({ type: "choice", - text: "Which two players share the most musical taste?", + text: "Which two players would probably agree on the aux?", options: pairOptions, correct: 0, points: 10, diff --git a/web/src/components/party/question.tsx b/web/src/components/party/question.tsx index 22830e2..446f6a9 100644 --- a/web/src/components/party/question.tsx +++ b/web/src/components/party/question.tsx @@ -46,12 +46,8 @@ export function Question() { question?.song?.platform === "spotify" && question.song.platform_id ? `spotify:track:${question.song.platform_id}` : null; - const { - enabled: spotifyEnabled, - setEnabled: setSpotifyEnabled, - status: spotifyStatus, - error: spotifyError, - } = useSpotifyPlayer(spotifyTrackUri); + const { enabled: spotifyEnabled, setEnabled: setSpotifyEnabled } = + useSpotifyPlayer(spotifyTrackUri); useEffect(() => { const timer = window.setInterval(() => { @@ -151,7 +147,7 @@ export function Question() { - {question.song?.name ?? "This question has no associated song."} - {spotifyStatus === "playing" ? " Playing now." : null} - {spotifyStatus === "loading" ? " Connecting Spotify..." : null} - {spotifyError ? ` ${spotifyError}` : null} + {question.hideSongTitle + ? "Listen closely and guess the song." + : (question.song?.name ?? + "This question has no associated song.")}