A new model (internal/affinity) splits my listening into sittings (plays less than 30 minutes apart) and links the artists that are often played in the same sitting. It is built from my listening events and from the plays of artists I have no music of that an import kept, on my server, with no provider, and is built again when plays are added (migration 0032 keeps it as a cache). GET /me/suggestions gives two lists, each artist with the artists it goes with: the ones I have and did not play for two months, and the ones I played at least three times and have no music of. It needs discover_from_listening. POST /me/suggestions/wishlist puts an artist I played on my wishlist by name. Discover has a "From your listening" tab for both lists.
35 lines
1.4 KiB
SQL
35 lines
1.4 KiB
SQL
-- What Sonda learned about which artists a person plays together (see internal/affinity), built again from the
|
|
-- listening events and the plays of artists outside the library. It is only a cache of that: it can be dropped and
|
|
-- built again. Artists are known by their search key, so one that is not in the library has a place too.
|
|
|
|
CREATE TABLE affinity_builds (
|
|
user_id INTEGER PRIMARY KEY REFERENCES users(id) ON DELETE CASCADE,
|
|
built_at INTEGER NOT NULL, -- unix seconds
|
|
plays INTEGER NOT NULL, -- the plays it was built from
|
|
sessions INTEGER NOT NULL,
|
|
artists INTEGER NOT NULL,
|
|
links INTEGER NOT NULL
|
|
);
|
|
|
|
CREATE TABLE affinity_artists (
|
|
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
artist_key TEXT NOT NULL,
|
|
name TEXT NOT NULL,
|
|
plays INTEGER NOT NULL,
|
|
sessions INTEGER NOT NULL,
|
|
last_played_at INTEGER NOT NULL, -- unix seconds
|
|
weight REAL NOT NULL,
|
|
PRIMARY KEY (user_id, artist_key)
|
|
);
|
|
|
|
CREATE INDEX idx_affinity_artists_weight ON affinity_artists(user_id, weight DESC);
|
|
|
|
CREATE TABLE affinity_links (
|
|
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
a_key TEXT NOT NULL, -- a_key < b_key
|
|
b_key TEXT NOT NULL,
|
|
score REAL NOT NULL,
|
|
PRIMARY KEY (user_id, a_key, b_key)
|
|
);
|
|
|
|
CREATE INDEX idx_affinity_links_b ON affinity_links(user_id, b_key);
|