fix(mock): scale visual-cluster fixtures to the scenario

The mock Explore clusters were a fixed 10 regardless of scenario, so the "huge"
dev scenario looked sparse next to its large tag vocabulary. Mirror the backend's
k = (n / 20).clamp(5, 30): the huge scenario now surfaces ~30 clusters with a
long-tailed, big-library-sized count distribution, so Explore looks realistic.
This commit is contained in:
2026-06-30 09:59:50 +01:00
parent 0d9229635b
commit 996bb71375
+15 -5
View File
@@ -252,12 +252,22 @@ function makeProgress(folders: Folder[], scenario: MockScenario): FolderJobProgr
})); }));
} }
function makeVisualClusters(images: ImageRecord[]): VisualClusterEntry[] { function makeVisualClusters(images: ImageRecord[], scenario: MockScenario): VisualClusterEntry[] {
return tags.slice(0, 10).map((_, index) => { if (images.length < 5) return [];
// Mirror the backend's k = (n / 20).clamp(5, 30). Force the full spread for the
// "huge" scenario so Explore shows a realistic field of clusters rather than a
// fixed handful, and size the counts off a large virtual library so the badges
// read like a big collection.
const clusterCount = scenario === "huge" ? 30 : Math.min(30, Math.max(5, Math.round(images.length / 20)));
const virtualTotal = scenario === "huge" ? 12_000 : images.length;
// Long-tailed sizes (a few large clusters, many smaller), like real k-means output.
const weights = Array.from({ length: clusterCount }, (_, i) => 1 / (i + 1.5));
const weightSum = weights.reduce((sum, weight) => sum + weight, 0);
return weights.map((weight, index) => {
const group = images.filter((image) => image.id % (index + 2) === 0).slice(0, 28); const group = images.filter((image) => image.id % (index + 2) === 0).slice(0, 28);
const representative = group[0] ?? images[index]; const representative = group[0] ?? images[index % images.length];
return { return {
count: Math.max(group.length, 1), count: Math.max(1, Math.round((virtualTotal * weight) / weightSum)),
representative_image_id: representative?.id ?? index + 1, representative_image_id: representative?.id ?? index + 1,
thumbnail_path: representative?.thumbnail_path ?? null, thumbnail_path: representative?.thumbnail_path ?? null,
image_ids: group.length ? group.map((image) => image.id) : [representative?.id ?? 1], image_ids: group.length ? group.map((image) => image.id) : [representative?.id ?? 1],
@@ -305,7 +315,7 @@ export function createMockDb(scenario: MockScenario): MockDb {
albums, albums,
albumImageIds, albumImageIds,
tagsByImageId: makeTags(images, scenario), tagsByImageId: makeTags(images, scenario),
visualClusters: makeVisualClusters(images), visualClusters: makeVisualClusters(images, scenario),
exploreTags: makeExploreTags(images, scenario), exploreTags: makeExploreTags(images, scenario),
backgroundJobs: makeProgress(folders, scenario), backgroundJobs: makeProgress(folders, scenario),
duplicateGroups: makeDuplicateGroups(images, scenario), duplicateGroups: makeDuplicateGroups(images, scenario),