feat(discover): suggestions learned from my own listening
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.
This commit is contained in:
parent
7b18478fe4
commit
7c961028bb
2 changed files with 2588 additions and 5 deletions
33
migrations/postgres/0032_affinity.sql
Normal file
33
migrations/postgres/0032_affinity.sql
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
-- PostgreSQL flavour of sqlite/0032_affinity.sql.
|
||||
|
||||
CREATE TABLE affinity_builds (
|
||||
user_id BIGINT PRIMARY KEY REFERENCES users(id) ON DELETE CASCADE,
|
||||
built_at BIGINT NOT NULL,
|
||||
plays INTEGER NOT NULL,
|
||||
sessions INTEGER NOT NULL,
|
||||
artists INTEGER NOT NULL,
|
||||
links INTEGER NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE affinity_artists (
|
||||
user_id BIGINT 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 BIGINT NOT NULL,
|
||||
weight DOUBLE PRECISION 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 BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
a_key TEXT NOT NULL,
|
||||
b_key TEXT NOT NULL,
|
||||
score DOUBLE PRECISION NOT NULL,
|
||||
PRIMARY KEY (user_id, a_key, b_key)
|
||||
);
|
||||
|
||||
CREATE INDEX idx_affinity_links_b ON affinity_links(user_id, b_key);
|
||||
35
migrations/sqlite/0032_affinity.sql
Normal file
35
migrations/sqlite/0032_affinity.sql
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
-- 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);
|
||||
Loading…
Reference in a new issue