-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
70 lines (61 loc) · 2.45 KB
/
Copy pathtypes.ts
File metadata and controls
70 lines (61 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Popularity-source types.
//
// Each source returns a single number per item: the raw value of whatever
// metric the source measures (Spotify followers, Wikipedia pageviews, etc).
// Within a round we *rank* items per source, then blend the ranks using
// per-category weights. See ./blend.ts.
import type { Category, Item } from "../types";
export type SourceName =
| "wikipedia"
| "spotify"
| "lastfm"
| "tmdb"
| "imdb"
| "openlibrary";
/** Raw values from each source for a single item. */
export type Signals = Partial<Record<SourceName, number>>;
/** Function that fetches a raw value for one item from one source. */
export type SourceFetcher = (item: Item) => Promise<number | null>;
/** What weight does each source carry, per category? Weights need not sum to 1. */
export type CategoryWeights = Partial<Record<SourceName, number>>;
export const CATEGORY_WEIGHTS: Record<Category, CategoryWeights> = {
music: { spotify: 0.5, wikipedia: 0.4, lastfm: 0.1 },
movies: { imdb: 0.6, wikipedia: 0.4 },
tv: { imdb: 0.6, wikipedia: 0.4 },
books: { openlibrary: 0.6, wikipedia: 0.4 },
food: { wikipedia: 1 },
cities: { wikipedia: 1 },
drinks: { wikipedia: 1 },
brands: { wikipedia: 1 },
hobbies: { wikipedia: 1 },
tech: { wikipedia: 1 },
animals: { wikipedia: 1 },
};
/** Which sources we need to query, for a given category. */
export function sourcesFor(category: Category | "mixed"): SourceName[] {
if (category === "mixed") return ["wikipedia"];
return Object.keys(CATEGORY_WEIGHTS[category]) as SourceName[];
}
/** Pretty label + units for each source — used in the reveal UI. */
export const SOURCE_LABEL: Record<SourceName, { label: string; unit: string }> = {
wikipedia: { label: "Wikipedia", unit: "pageviews" },
spotify: { label: "Spotify", unit: "monthly listeners" },
lastfm: { label: "Last.fm", unit: "listeners" },
tmdb: { label: "TMDb", unit: "popularity" },
imdb: { label: "IMDb", unit: "ratings" },
openlibrary: { label: "Open Library", unit: "readers" },
};
/**
* Canonical display order for signal badges. Category-specific sources
* appear first (they're the "interesting" signal for that category),
* Wikipedia last as the universal baseline. Without this the order is
* whatever fetch happened to resolve first.
*/
export const SIGNAL_DISPLAY_ORDER: SourceName[] = [
"spotify",
"tmdb",
"imdb",
"openlibrary",
"lastfm",
"wikipedia",
];