added randomisation

This commit is contained in:
2025-11-11 00:11:03 +01:00
parent ca5fedd65c
commit 9cbef20644
3 changed files with 26 additions and 3 deletions

18
package-lock.json generated
View File

@@ -16,7 +16,8 @@
"@sveltejs/adapter-node": "^5.2.13", "@sveltejs/adapter-node": "^5.2.13",
"chart.js": "^4.5.0", "chart.js": "^4.5.0",
"drizzle-orm": "^0.40.0", "drizzle-orm": "^0.40.0",
"exceljs": "^4.4.0" "exceljs": "^4.4.0",
"knuth-shuffle-seeded": "^1.0.6"
}, },
"devDependencies": { "devDependencies": {
"@eslint/compat": "^1.2.5", "@eslint/compat": "^1.2.5",
@@ -6462,6 +6463,15 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/knuth-shuffle-seeded": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/knuth-shuffle-seeded/-/knuth-shuffle-seeded-1.0.6.tgz",
"integrity": "sha512-9pFH0SplrfyKyojCLxZfMcvkhf5hH0d+UwR9nTVJ/DDQJGuzcXjTwB7TP7sDfehSudlGGaOLblmEWqv04ERVWg==",
"license": "Apache-2.0",
"dependencies": {
"seed-random": "~2.2.0"
}
},
"node_modules/lazystream": { "node_modules/lazystream": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/lazystream/-/lazystream-1.0.1.tgz", "resolved": "https://registry.npmjs.org/lazystream/-/lazystream-1.0.1.tgz",
@@ -7750,6 +7760,12 @@
"node": ">=10" "node": ">=10"
} }
}, },
"node_modules/seed-random": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/seed-random/-/seed-random-2.2.0.tgz",
"integrity": "sha512-34EQV6AAHQGhoc0tn/96a9Fsi6v2xdqe/dMUwljGRaFOzR3EgRmECvD0O8vi8X+/uQ50LGHfkNu/Eue5TPKZkQ==",
"license": "MIT"
},
"node_modules/semver": { "node_modules/semver": {
"version": "7.7.2", "version": "7.7.2",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz", "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz",

View File

@@ -46,6 +46,7 @@
"@sveltejs/adapter-node": "^5.2.13", "@sveltejs/adapter-node": "^5.2.13",
"chart.js": "^4.5.0", "chart.js": "^4.5.0",
"drizzle-orm": "^0.40.0", "drizzle-orm": "^0.40.0",
"exceljs": "^4.4.0" "exceljs": "^4.4.0",
"knuth-shuffle-seeded": "^1.0.6"
} }
} }

View File

@@ -4,6 +4,7 @@ import { inviteLink, participant, audioFile, rating, overallRating } from '$lib/
import { eq, isNull, and, inArray } from 'drizzle-orm'; import { eq, isNull, and, inArray } from 'drizzle-orm';
import { parseStoredTags, matchesInviteTags } from '$lib/server/tag-utils.js'; import { parseStoredTags, matchesInviteTags } from '$lib/server/tag-utils.js';
import { env } from '$env/dynamic/private'; import { env } from '$env/dynamic/private';
import shuffle from 'knuth-shuffle-seeded';
export async function load({ url, cookies }) { export async function load({ url, cookies }) {
const token = url.searchParams.get('token'); const token = url.searchParams.get('token');
@@ -81,7 +82,7 @@ export async function load({ url, cookies }) {
.from(audioFile) .from(audioFile)
.where(isNull(audioFile.deletedAt)); // Only show active audio files .where(isNull(audioFile.deletedAt)); // Only show active audio files
const filteredAudio = audioRows const baseAudioList = audioRows
.map((audio) => ({ .map((audio) => ({
data: { data: {
id: audio.id, id: audio.id,
@@ -96,6 +97,11 @@ export async function load({ url, cookies }) {
.filter(({ tags }) => matchesInviteTags(tags, inviteTags)) .filter(({ tags }) => matchesInviteTags(tags, inviteTags))
.map(({ data }) => data); .map(({ data }) => data);
const shuffleSeed = participantId || token;
const filteredAudio = baseAudioList.length > 0
? shuffle([...baseAudioList], shuffleSeed)
: baseAudioList;
const allowedAudioIds = filteredAudio.map((file) => file.id); const allowedAudioIds = filteredAudio.map((file) => file.id);
const displayContinuousRating = env.DISPLAY_CONT_RATING !== 'false'; const displayContinuousRating = env.DISPLAY_CONT_RATING !== 'false';