From 5e466cbe98496bafc2a90e2942026bc01538ae30 Mon Sep 17 00:00:00 2001 From: spl0k Date: Fri, 14 Jun 2013 13:02:43 +0200 Subject: [PATCH] Implemented the last missing search type og getAlbumList (and why the fuck did I use 'sum / count' rather than 'avg'?) --- api/albums_songs.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/api/albums_songs.py b/api/albums_songs.py index 99ef850..0e7c565 100755 --- a/api/albums_songs.py +++ b/api/albums_songs.py @@ -1,7 +1,7 @@ # coding: utf-8 from flask import request -from sqlalchemy import desc, func, cast, Float +from sqlalchemy import desc, func from sqlalchemy.orm import aliased import random import uuid @@ -62,9 +62,9 @@ def album_list(): elif ltype == 'newest': query = query.order_by(desc(Folder.created)) elif ltype == 'highest': - return request.error_formatter(0, 'Not implemented') + query = query.join(RatingFolder).group_by(Folder.id).order_by(desc(func.avg(RatingFolder.rating))) elif ltype == 'frequent': - query = query.join(Track, Folder.tracks).group_by(Folder.id).order_by(desc(cast(func.sum(Track.play_count), Float) / func.count())) + query = query.join(Track, Folder.tracks).group_by(Folder.id).order_by(desc(func.avg(Track.play_count))) elif ltype == 'recent': query = query.join(Track, Folder.tracks).group_by(Folder.id).order_by(desc(func.max(Track.last_play))) elif ltype == 'starred': @@ -103,7 +103,7 @@ def album_list_id3(): elif ltype == 'newest': query = query.join(Track, Album.tracks).group_by(Album.id).order_by(desc(func.min(Track.created))) elif ltype == 'frequent': - query = query.join(Track, Album.tracks).group_by(Album.id).order_by(desc(cast(func.sum(Track.play_count), Float) / func.count())) + query = query.join(Track, Album.tracks).group_by(Album.id).order_by(desc(func.avg(Track.play_count))) elif ltype == 'recent': query = query.join(Track, Album.tracks).group_by(Album.id).order_by(desc(func.max(Track.last_play))) elif ltype == 'starred':