more questions

This commit is contained in:
Daniel Bulant 2026-05-14 00:53:03 +02:00
parent a3913cb9b1
commit 8d2f86b3f8
No known key found for this signature in database
4 changed files with 63 additions and 25 deletions

View file

@ -35,6 +35,7 @@ type BaseQuestion = {
endTimestamp: number; endTimestamp: number;
points: number; points: number;
song?: Song; song?: Song;
hideSongTitle?: boolean;
}; };
export type Question = export type Question =

View file

@ -7,6 +7,7 @@ import {
getMostSharedGenreNames, getMostSharedGenreNames,
getTopClusterArtists, getTopClusterArtists,
getTopClusterTracks, getTopClusterTracks,
isUsableText,
type PartyAnalytics, type PartyAnalytics,
pickRandom, pickRandom,
resolveQuestionSong, resolveQuestionSong,
@ -22,6 +23,27 @@ export async function buildAudioMetadataQuestion(
Omit<ChoiceQuestion, "startTimestamp" | "endTimestamp"> Omit<ChoiceQuestion, "startTimestamp" | "endTimestamp">
> = []; > = [];
const topSong = await resolveQuestionSong(dbClient, analytics); 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( const genreOptions = buildOrderedOptions(
getMostSharedGenreNames(analytics), getMostSharedGenreNames(analytics),
@ -54,12 +76,10 @@ export async function buildAudioMetadataQuestion(
} }
} }
const topTracks = getTopClusterTracks(analytics);
if (topTracks.length > 0) { if (topTracks.length > 0) {
const trackNames = topTracks.map((track) => track.name); const topTrackName = topTrackNames[0];
const topTrackName = trackNames[0];
const trackOptions = topTrackName const trackOptions = topTrackName
? buildOptionsWithCorrect(topTrackName, trackNames, 4) ? buildOptionsWithCorrect(topTrackName, topTrackNames, 4)
: null; : null;
if (trackOptions) { if (trackOptions) {
questions.push({ questions.push({
@ -115,8 +135,28 @@ export async function buildAudioMetadataQuestion(
correct: 0, correct: 0,
points: 10, points: 10,
song: randomTrackSong ?? topSong ?? undefined, 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) { if (randomTopTrack.albumName) {

View file

@ -62,6 +62,15 @@ export async function buildSocialQuestion(
points: 10, points: 10,
song: topSong ?? undefined, 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); const topTracks = getTopClusterTracks(analytics);
@ -76,15 +85,7 @@ export async function buildSocialQuestion(
}); });
questions.push({ questions.push({
type: "choice", type: "choice",
text: `Who listens the most to "${randomTrack.name}"?`, text: `Who is most likely to have "${randomTrack.name}" in heavy rotation?`,
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?`,
options: buildMemberOptions(topListener, members), options: buildMemberOptions(topListener, members),
correct: 0, correct: 0,
points: 10, points: 10,
@ -103,7 +104,7 @@ export async function buildSocialQuestion(
if (pairOptions) { if (pairOptions) {
questions.push({ questions.push({
type: "choice", type: "choice",
text: "Which two players share the most musical taste?", text: "Which two players would probably agree on the aux?",
options: pairOptions, options: pairOptions,
correct: 0, correct: 0,
points: 10, points: 10,

View file

@ -46,12 +46,8 @@ export function Question() {
question?.song?.platform === "spotify" && question.song.platform_id question?.song?.platform === "spotify" && question.song.platform_id
? `spotify:track:${question.song.platform_id}` ? `spotify:track:${question.song.platform_id}`
: null; : null;
const { const { enabled: spotifyEnabled, setEnabled: setSpotifyEnabled } =
enabled: spotifyEnabled, useSpotifyPlayer(spotifyTrackUri);
setEnabled: setSpotifyEnabled,
status: spotifyStatus,
error: spotifyError,
} = useSpotifyPlayer(spotifyTrackUri);
useEffect(() => { useEffect(() => {
const timer = window.setInterval(() => { const timer = window.setInterval(() => {
@ -151,7 +147,7 @@ export function Question() {
<ItemContent> <ItemContent>
<ItemHeader> <ItemHeader>
<Label htmlFor="spotify-playback" className="cursor-pointer"> <Label htmlFor="spotify-playback" className="cursor-pointer">
Spotify playback Audio playback
</Label> </Label>
<Switch <Switch
id="spotify-playback" id="spotify-playback"
@ -162,10 +158,10 @@ export function Question() {
/> />
</ItemHeader> </ItemHeader>
<ItemDescription> <ItemDescription>
{question.song?.name ?? "This question has no associated song."} {question.hideSongTitle
{spotifyStatus === "playing" ? " Playing now." : null} ? "Listen closely and guess the song."
{spotifyStatus === "loading" ? " Connecting Spotify..." : null} : (question.song?.name ??
{spotifyError ? ` ${spotifyError}` : null} "This question has no associated song.")}
</ItemDescription> </ItemDescription>
</ItemContent> </ItemContent>
</Item> </Item>