Compare commits

..

No commits in common. "c57bf186273c34be8b19093db67a1a06afde9622" and "62590fee374fab21c36976724d014a5a1b15f787" have entirely different histories.

6 changed files with 37 additions and 78 deletions

View file

@ -9,10 +9,8 @@
</head> </head>
<body> <body>
@partial partials/header @partial partials/header
<h1>{{.album.name}}</h1> <h1>{{.album}}</h1>
<div>{{.album.scrobbles}} scrobbles ({{.album.rank}} place)</div> @partial partials/firstlast_listens(scrobbles: .album.scrobbles, rank: .album.rank, firstlast: .firstlast)
<div>{{.album.song_num}} songs</div>
@partial partials/firstlast_listens(firstlast: .firstlast)
<h3>Yearly Performance</h3> <h3>Yearly Performance</h3>
@partial partials/timescale(range: .yearly) @partial partials/timescale(range: .yearly)
<h2>Songs</h2> <h2>Songs</h2>

View file

@ -10,14 +10,9 @@
<body> <body>
@partial partials/header @partial partials/header
<h1>{{.artist.name}}</h1> <h1>{{.artist.name}}</h1>
<div> @partial partials/firstlast_listens(scrobbles: .artist.scrobbles, rank: .artist.rank, firstlast: .firstlast)
<div>{{.artist.scrobbles}} scrobbles ({{.artist.rank}} place)</div> <h3>Yearly Performance</h3>
<div>{{.artist.song_num}} songs</div>
<div>{{.artist.album_num}} albums</div>
</div>
@partial partials/timescale(range: .yearly) @partial partials/timescale(range: .yearly)
<br>
@partial partials/firstlast_listens(firstlast: .firstlast)
<h2>Albums</h2> <h2>Albums</h2>
@partial partials/newtable(T: ColumnChoices, table_data: .albums, columns: columns) @partial partials/newtable(T: ColumnChoices, table_data: .albums, columns: columns)

View file

@ -1,10 +1,12 @@
@args firstlast: *ZmplValue @args scrobbles: i64, rank: []const u8, firstlast: *ZmplValue
@zig { @zig {
const songs = firstlast.items(.array); const songs = firstlast.items(.array);
} }
<div> <div>
{{scrobbles}} scrobbles ({{rank}} place)
<br>
First listen: <a href="/songs/{{songs[0].song.id}}">{{songs[0].song.name}}</a> ({{songs[0].date}}) First listen: <a href="/songs/{{songs[0].song.id}}">{{songs[0].song.name}}</a> ({{songs[0].date}})
<br> <br>
Most recent listen: <a href="/songs/{{songs[1].song.id}}">{{songs[1].song.name}}</a> ({{songs[1].date}}) Most recent listen: <a href="/songs/{{songs[1].song.id}}">{{songs[1].song.name}}</a> ({{songs[1].date}})

View file

@ -1,6 +1,5 @@
@args range: *ZmplValue @args range: *ZmplValue
<div>
<table> <table>
<thead> <thead>
<tr> <tr>
@ -17,4 +16,3 @@
} }
</tbody> </tbody>
</table> </table>
</div>

View file

@ -9,9 +9,8 @@
</head> </head>
<body> <body>
@partial partials/header @partial partials/header
<h1>{{.song.name}}</h1> <h1>{{.song}}</h1>
<div>{{.song.scrobbles}} scrobbles ({{.song.rank}} place)</div> @partial partials/firstlast_listens(scrobbles: .song.scrobbles, rank: .song.rank, firstlast: .firstlast)
@partial partials/firstlast_listens(firstlast: .firstlast)
<h3>Yearly Performance</h3> <h3>Yearly Performance</h3>
@partial partials/timescale(range: .yearly) @partial partials/timescale(range: .yearly)
<h2>Scrobbles</h2> <h2>Scrobbles</h2>

View file

@ -17,18 +17,13 @@ pub fn entityQueryResult(request: *jetzig.Request, query: GeneratedQuery, args:
if (query.query_type == .entity_info) { if (query.query_type == .entity_info) {
var out: *jetzig.Data.Value = try Data.object(); var out: *jetzig.Data.Value = try Data.object();
const entity = try (try result.next()).?.to(struct { name: []const u8, id: i32, scrobbles: i64, album_num: ?i64 = null, song_num: ?i64 = null, rank: []const u8 }, .{ .dupe = true, .allocator = request.allocator, .map = .name }); const entity = try (try result.next()).?.to(struct { name: []const u8, id: i32, scrobbles: i64, rank: []const u8 }, .{ .dupe = true, .allocator = request.allocator });
try out.put("entity_info", entity); const entity_struct = .{ .name = entity.name, .id = entity.id, .scrobbles = entity.scrobbles, .rank = entity.rank };
try out.put("entity_info", entity_struct);
try result.drain(); try result.drain();
return out.get("entity_info").?; return out.get("entity_info").?;
} }
//if (query.query_type == .datestreak) {
// var out: *jetzig.Data.Value = try Data.object();
// const entity = try (try result.next()).?.to(struct { name: []const u8, id: i32, scrobbles: i64, rank: []const u8 }, .{ .dupe = true, .allocator = request.allocator });
//
//}
var out: *jetzig.Data.Value = try Data.array(); var out: *jetzig.Data.Value = try Data.array();
var mapper = result.mapper(UnifiedResult, .{ .dupe = true, .allocator = request.allocator }); var mapper = result.mapper(UnifiedResult, .{ .dupe = true, .allocator = request.allocator });
@ -173,17 +168,14 @@ pub fn loadQuery(entity: EntityType, query_type: QueryTypeEnum) GeneratedQuery {
, ,
.artist => .artist =>
\\SELECT y.year AS date, COALESCE(DT.scrobbles, 0) AS scrobbles \\SELECT TO_CHAR(date_trunc('year', datetime), 'YYYY') AS date, COUNT(*) as scrobbles
\\FROM (SELECT GENERATE_SERIES(2016,date_part('year',now())::int)::text) AS y(year)
\\LEFT JOIN (SELECT TO_CHAR(date_trunc('year', datetime), 'YYYY') AS date, COUNT(*) as scrobbles
\\FROM scrobbles \\FROM scrobbles
\\INNER JOIN albumsongs ON albumsongs.id = scrobbles.albumsong \\INNER JOIN albumsongs ON albumsongs.id = scrobbles.albumsong
\\INNER JOIN albumsongsartists ON albumsongsartists.albumsong_id = albumsongs.id \\INNER JOIN albumsongsartists ON albumsongsartists.albumsong_id = albumsongs.id
\\INNER JOIN artists ON artists.id = albumsongsartists.artist_id \\INNER JOIN artists ON artists.id = albumsongsartists.artist_id
\\WHERE artists.id = $1 \\WHERE artists.id = $1
\\GROUP BY date \\GROUP BY date
\\ORDER BY date ASC) AS DT \\ORDER BY date ASC;
\\ON DT.date = y.year;
, ,
}, },
@ -311,24 +303,21 @@ pub fn loadQuery(entity: EntityType, query_type: QueryTypeEnum) GeneratedQuery {
.album => .album =>
\\SELECT * FROM \\SELECT * FROM
\\(SELECT *, TO_CHAR(ROW_NUMBER() OVER (ORDER BY scrobbles DESC),'FM9999th') AS rank FROM \\(SELECT *, TO_CHAR(ROW_NUMBER() OVER (ORDER BY scrobbles DESC),'FM9999th') AS rank FROM
\\(SELECT albums.name AS name, albums.id AS id, COUNT(DISTINCT songs.id) AS song_num, COUNT(scrobbles) AS scrobbles \\(SELECT albums.name AS name, albums.id AS id, COUNT(scrobbles) AS scrobbles
\\FROM albumsongs \\FROM albumsongs
\\INNER JOIN albums ON albumsongs.album_id = albums.id \\INNER JOIN albums ON albumsongs.album_id = albums.id
\\INNER JOIN scrobbles ON scrobbles.albumsong = albumsongs.id \\INNER JOIN scrobbles ON scrobbles.albumsong = albumsongs.id
\\INNER JOIN songs ON songs.id = albumsongs.song_id
\\GROUP BY albums.id)) \\GROUP BY albums.id))
\\WHERE id = $1; \\WHERE id = $1
, ,
.artist => .artist =>
\\SELECT * FROM \\SELECT * FROM
\\(SELECT *, TO_CHAR(ROW_NUMBER() OVER (ORDER BY scrobbles DESC),'FM9999th') AS rank FROM \\(SELECT *, TO_CHAR(ROW_NUMBER() OVER (ORDER BY scrobbles DESC),'FM9999th') AS rank FROM
\\(SELECT artists.name AS name, artists.id AS id, COUNT(scrobbles) AS scrobbles, COUNT(DISTINCT albums.id) AS album_num, COUNT(DISTINCT songs.id) AS song_num \\(SELECT artists.name AS name, artists.id AS id, COUNT(scrobbles) AS scrobbles
\\FROM albumsongsartists \\FROM albumsongsartists
\\INNER JOIN artists ON albumsongsartists.artist_id = artists.id \\INNER JOIN artists ON albumsongsartists.artist_id = artists.id
\\INNER JOIN albumsongs ON albumsongsartists.albumsong_id = albumsongs.id \\INNER JOIN albumsongs ON albumsongsartists.albumsong_id = albumsongs.id
\\INNER JOIN scrobbles ON scrobbles.albumsong = albumsongs.id \\INNER JOIN scrobbles ON scrobbles.albumsong = albumsongs.id
\\INNER JOIN albums ON albums.id = albumsongs.album_id
\\INNER JOIN songs ON songs.id = albumsongs.song_id
\\GROUP BY artists.id)) \\GROUP BY artists.id))
\\WHERE id = $1 \\WHERE id = $1
, ,
@ -336,44 +325,22 @@ pub fn loadQuery(entity: EntityType, query_type: QueryTypeEnum) GeneratedQuery {
.datestreak => switch (entity) { .datestreak => switch (entity) {
.song => .song =>
\\SELECT maxseq AS streak, FORMAT('%s - %s', ds, de) AS date FROM (SELECT MAX(numdays) AS maxseq, ds, de \\SELECT songs.name AS song_name, albums.name AS album_name, streak.maxseq AS intval, FORMAT('%s - %s, streak.ds, streak.de) AS date FROM (SELECT albumsong, MAX(numdays) AS maxseq, ds, de
\\FROM (SELECT grp, MIN(datetime::date) AS ds, MAX(datetime::date) AS de, \\FROM (SELECT albumsong, grp, MIN(datetime::date) AS ds, MAX(datetime::date) AS de,
\\COUNT(DISTINCT datetime::date) AS numdays \\COUNT(DISTINCT datetime::date) AS numdays
\\FROM (SELECT scrobbles.datetime, \\FROM (SELECT scrobbles.*,
\\((datetime::date - '1970-01-01'::date) - DENSE_RANK() OVER (PARTITION BY songs.id ORDER BY datetime::date)) AS grp \\((datetime::date - '1970-01-01'::date) - DENSE_RANK() OVER (PARTITION BY albumsong ORDER BY datetime::date)) AS grp
\\FROM scrobbles INNER JOIN albumsongs ON albumsongs.id = albumsong INNER JOIN songs ON songs.id = albumsongs.song_id \\FROM scrobbles
\\WHERE songs.id = $1) scrobbles
\\GROUP BY grp
\\) scrobbles \\) scrobbles
\\GROUP BY ds, de) \\GROUP BY albumsong, grp
\\ORDER BY maxseq DESC;
,
.artist =>
\\SELECT maxseq AS streak, FORMAT('%s - %s' ,ds,de) AS date FROM (SELECT MAX(numdays) AS maxseq, ds, de
\\FROM (SELECT grp, MIN(datetime::date) AS ds, MAX(datetime::date) AS de,
\\COUNT(DISTINCT datetime::date) AS numdays
\\FROM (SELECT scrobbles.datetime,
\\((scrobbles.datetime::date - '1970-01-01'::date) - DENSE_RANK() OVER (PARTITION BY artists.id ORDER BY scrobbles.datetime::date)) AS grp
\\FROM scrobbles INNER JOIN albumsongsartists ON albumsongsartists.albumsong_id = scrobbles.albumsong INNER JOIN artists ON artists.id = albumsongsartists.artist_id
\\WHERE artists.id = $1) scrobbles
\\GROUP BY grp
\\) scrobbles \\) scrobbles
\\GROUP BY ds, de) \\GROUP BY albumsong, ds, de) AS streak
\\ORDER BY maxseq DESC; \\INNER JOIN albumsongs ON albumsongs.id = streak.albumsong
\\INNER JOIN albums ON albums.id = albumsongs.album_id
\\INNER JOIN songs ON songs.id = albumsongs.song_id
\\ORDER BY streak.maxseq DESC;
, ,
.album => else => unreachable,
\\SELECT maxseq AS streak, FORMAT('%s - %s', ds, de) AS date FROM (SELECT MAX(numdays) AS maxseq, ds, de
\\FROM (SELECT grp, MIN(datetime::date) AS ds, MAX(datetime::date) AS de,
\\COUNT(DISTINCT datetime::date) AS numdays
\\FROM (SELECT scrobbles.datetime,
\\((datetime::date - '1970-01-01'::date) - DENSE_RANK() OVER (PARTITION BY albums.id ORDER BY datetime::date)) AS grp FROM scrobbles INNER JOIN albumsongs ON albumsongs.id = albumsong INNER JOIN albums ON albums.id = albumsongs.album_id
\\WHERE albums.id = $1) scrobbles
\\GROUP BY grp
\\) scrobbles
\\GROUP BY ds, de)
\\ORDER BY maxseq DESC;
,
.scrobble => unreachable,
}, },
}, },
}; };