Skip to content

Instantly share code, notes, and snippets.

View mayhem's full-sized avatar
💭
Hell bent on total world domination!

Robert Kaye mayhem

💭
Hell bent on total world domination!
View GitHub Profile
CREATE VIEW listened_at_max
WITH (timescaledb.continuous, timescaledb.refresh_lag=43200, timescaledb.refresh_interval=3600)
AS SELECT time_bucket(bigint '86400', listened_at) AS listened_at, user_name, max(listened_at)
FROM listen group by time_bucket(bigint '86400', listened_at), user_name;
CREATE VIEW listened_at_min
WITH (timescaledb.continuous, timescaledb.refresh_lag=43200, timescaledb.refresh_interval=3600)
AS SELECT time_bucket(bigint '86400', listened_at) AS listened_at, user_name, min(listened_at)
FROM listen group by time_bucket(bigint '86400', listened_at), user_name;
For Beatles
{
"artist_name": "The Rolling Stones",
"count": 118,
"id": 825
},
{
"artist_name": "Elvis Presley",
"count": 116,
{
"artist_name": "Oasis",
"count": 64,
"id": 20660
},
{
"artist_name": "Massive Attack",
"count": 50,
"id": 4
},
The input recordings were:
59aad Something Just Like This Coldplay
b66b5 2002 Anne‐Marie
74525 Starving Hailee Steinfeld & Grey feat. Zedd
Related to those artists, 48 related artist_credits were loaded (5 shown):
66 Radiohead
20660 Oasis
315753 Katy Perry
359 Moby
(.ve) messybrainz-testing:~/troi-recommendation-playground->./nonsense_example.py 737e3e7c-f502-41f4-a1e2-ec52d11691f7 46766af3-f2ea-4802-967b-4bea1a0679ba
The input recordings were:
737e3e Cypress Hill Hits From the Bong
46766a Peter Tosh Legalize It
Related to those artists, 50 related artist_credits were loaded (5 shown)
154 1626 Jimmy Cliff
132 5880 Dennis Brown
122 92744 A Tribe Called Quest
122 3801 Gregory Isaacs
(.ve) messybrainz-testing:~/troi-recommendation-playground->./nonsense_example.py 8fb519ee-697f-4f42-b462-7af555385150 e95e5009-99b3-42d2-abdd-477967233b08 faa06ef9-caa3-44c2-aadf-0029e3390a06
The input recordings were:
8fb519 The Alarm Rain in the Summertime
e95e50 U2 Sunday Bloody Sunday
faa06e Depeche Mode People Are People
Related to those artists, 62 related artist_credits were loaded (5 shown)
222 236 Elton John
198 192 Queen
180 359 Moby
<html>
<head>
<title>OpenPost Redirector</title>
</head>
<body onLoad="javascript: document.getElementById('postform').submit();">
<p>Loading...</p>
<form method="post" name="postform" id="postform" action="https://listenbrainz.org/player">
<textarea name='listens' id='listens' form='postform' style='display: none;'>[
{
listenbrainz_ts=> explain analyze SELECT listened_at, recording_msid, data FROM listen WHERE user_name = 'rob' and listened_at < 1580085314 order by listened_at desc limit 50;
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=0.42..1289.31 rows=50 width=523) (actual time=0.118..5.925 rows=50 loops=1)
-> Custom Scan (ChunkAppend) on listen (cost=0.42..1701.76 rows=66 width=523) (actual time=0.117..5.920 rows=50 loops=1)
Order: listen.listened_at DESC
-> Index Scan using _hyper_35_5591_chunk_listened_at_user_name_ndx_listen on _hyper_35_5591_chunk (cost=0.42..1701.76 rows=66 width=698) (actual time=0.116..4.832 rows=16 loops=1)
Index Cond: ((listened_at < 1580085314) AND (user_name = 'rob'::text))
-> Index
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=0.42..1289.31 rows=50 width=523)
-> Custom Scan (ChunkAppend) on listen (cost=0.42..1701.76 rows=66 width=523)
Order: listen.listened_at DESC
-> Index Scan using _hyper_35_5591_chunk_listened_at_user_name_ndx_listen on _hyper_35_5591_chunk (cost=0.42..1701.76 rows=66 width=698)
Index Cond: ((listened_at < 1580085314) AND (user_name = 'rob'::text))
-> Index Scan using _hyper_35_5588_chunk_listened_at_user_name_ndx_listen on _hyper_35_5588_chunk (cost=0.42..3196.45 rows=217 width=703)
Index Cond: ((listened_at < 1580085314) AND (user_name = 'rob'::text))
-> Index Scan using _hyper_35_5586_chunk_listened_at_user_name_ndx_listen on _hyper_35_5586_chunk (cost=0.42..3161.08 rows=43 width=700)
-> Index Scan using _hyper_35_4700_chunk_listened_at_user_name_ndx_listen on _hyper_35_4700_chunk (cost=0.42..3089.13 rows=54 width=516)
Index Cond: ((listened_at < 1580085314) AND (user_name = 'rob'::text))
-> Index Scan using _hyper_35_4699_chunk_listened_at_user_name_ndx_listen on _hyper_35_4699_chunk (cost=0.42..2991.26 rows=54 width=516)
Index Cond: ((listened_at < 1580085314) AND (user_name = 'rob'::text))
-> Index Scan using _hyper_35_4698_chunk_listened_at_user_name_ndx_listen on _hyper_35_4698_chunk (cost=0.42..2850.52 rows=50 width=517)
Index Cond: ((listened_at < 1580085314) AND (user_name = 'rob'::text))
-> Index Scan using _hyper_35_4697_chunk_listened_at_user_name_ndx_listen on _hyper_35_4697_chunk (cost=0.42..3241.08 rows=62 width=517)
Index Cond: ((listened_at < 1580085314) AND (user_name = 'rob'::text))
-> Index Scan using _hyper_35_4696_chunk_listened_at_user_name_ndx_listen on _