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;
points: number;
song?: Song;
hideSongTitle?: boolean;
};
export type Question =

View file

@ -7,6 +7,7 @@ import {
getMostSharedGenreNames,
getTopClusterArtists,
getTopClusterTracks,
isUsableText,
type PartyAnalytics,
pickRandom,
resolveQuestionSong,
@ -22,6 +23,27 @@ export async function buildAudioMetadataQuestion(
Omit<ChoiceQuestion, "startTimestamp" | "endTimestamp">
> = [];
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) {

View file

@ -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,

View file

@ -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() {
<ItemContent>
<ItemHeader>
<Label htmlFor="spotify-playback" className="cursor-pointer">
Spotify playback
Audio playback
</Label>
<Switch
id="spotify-playback"
@ -162,10 +158,10 @@ export function Question() {
/>
</ItemHeader>
<ItemDescription>
{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.")}
</ItemDescription>
</ItemContent>
</Item>