Made the cluster types that are displayed configurable in the release and artist view

This commit is contained in:
emeric
2018-05-11 13:42:25 +02:00
parent 6a96af5d48
commit 070d466380
15 changed files with 194 additions and 58 deletions
+2 -2
View File
@@ -16,11 +16,11 @@
} }
.Lms-cluster-type-4 { .Lms-cluster-type-4 {
background-color: darkslateblue; background-color: darkgoldenrod;
} }
.Lms-cluster-type-5 { .Lms-cluster-type-5 {
background-color: darkslateblue; background-color: darkkhaki;
} }
.Lms-cluster-type-6 { .Lms-cluster-type-6 {
+35 -10
View File
@@ -182,23 +182,48 @@ Artist::getReleases(const std::set<id_type>& clusterIds) const
return std::vector< Wt::Dbo::ptr<Release> > (res.begin(), res.end()); return std::vector< Wt::Dbo::ptr<Release> > (res.begin(), res.end());
} }
std::vector<Wt::Dbo::ptr<Cluster>> std::vector<std::vector<Wt::Dbo::ptr<Cluster>>>
Artist::getClusters(int size) const Artist::getClusterGroups(std::vector<ClusterType::pointer> clusterTypes, std::size_t size) const
{ {
assert(self()); assert(self());
assert(self()->id() != Wt::Dbo::dbo_traits<Artist>::invalidId() ); assert(self()->id() != Wt::Dbo::dbo_traits<Artist>::invalidId() );
assert(session()); assert(session());
Wt::Dbo::Query<Cluster::pointer> query = session()->query<Cluster::pointer> WhereClause where;
("select c from cluster c INNER JOIN track t ON c.id = t_c.cluster_id INNER JOIN track_cluster t_c ON t_c.track_id = t.id INNER JOIN artist a ON t.artist_id = a.id")
.where("a.id = ?").bind(self()->id())
.groupBy("c.id")
.orderBy("COUNT(c.id) DESC")
.limit(size);
Wt::Dbo::collection<Cluster::pointer> res = query; std::ostringstream oss;
oss << "SELECT c from cluster c INNER JOIN track t ON c.id = t_c.cluster_id INNER JOIN track_cluster t_c ON t_c.track_id = t.id INNER JOIN cluster_type c_type ON c.cluster_type_id = c_type.id INNER JOIN artist a ON t.artist_id = a.id";
return std::vector<Cluster::pointer>(res.begin(), res.end()); where.And(WhereClause("a.id = ?")).bind(std::to_string(self()->id()));
{
WhereClause clusterClause;
for (auto clusterType : clusterTypes)
clusterClause.Or(WhereClause("c_type.id = ?")).bind(std::to_string(clusterType.id()));
where.And(clusterClause);
}
oss << " " << where.get();
oss << "GROUP BY c.id ORDER BY COUNT(c.id) DESC";
Wt::Dbo::Query<Cluster::pointer> query = session()->query<Cluster::pointer>( oss.str() );
for (const std::string& bindArg : where.getBindArgs())
query.bind(bindArg);
Wt::Dbo::collection<Cluster::pointer> queryRes = query;
std::map<ClusterType::id_type, std::vector<Cluster::pointer>> clusters;
for (auto cluster : queryRes)
{
if (clusters[cluster->getType().id()].size() < size)
clusters[cluster->getType().id()].push_back(cluster);
}
std::vector<std::vector<Cluster::pointer>> res;
for (auto cluster_list : clusters)
res.push_back(cluster_list.second);
return res;
} }
} // namespace Database } // namespace Database
+4 -1
View File
@@ -31,6 +31,7 @@ namespace Database
class Track; class Track;
class Cluster; class Cluster;
class ClusterType;
class Release; class Release;
class Artist : public Wt::Dbo::Dbo<Artist> class Artist : public Wt::Dbo::Dbo<Artist>
@@ -65,7 +66,9 @@ class Artist : public Wt::Dbo::Dbo<Artist>
std::vector<Wt::Dbo::ptr<Release>> getReleases(const std::set<id_type>& clusterIds = std::set<id_type>()) const; std::vector<Wt::Dbo::ptr<Release>> getReleases(const std::set<id_type>& clusterIds = std::set<id_type>()) const;
// Get the cluster of the tracks made by this artist // Get the cluster of the tracks made by this artist
std::vector<Wt::Dbo::ptr<Cluster>> getClusters(int size) const; // Each clusters are grouped by cluster type, sorted by the number of occurence
// size is the max number of cluster per cluster type
std::vector<std::vector<Wt::Dbo::ptr<Cluster>>> getClusterGroups(std::vector<Wt::Dbo::ptr<ClusterType>> clusterTypes, std::size_t size) const;
void setMBID(std::string mbid) { _MBID = mbid; } void setMBID(std::string mbid) { _MBID = mbid; }
+35 -10
View File
@@ -226,23 +226,48 @@ Release::getTracks(const std::set<id_type>& clusterIds) const
return std::vector< Wt::Dbo::ptr<Track> > (res.begin(), res.end()); return std::vector< Wt::Dbo::ptr<Track> > (res.begin(), res.end());
} }
std::vector<Wt::Dbo::ptr<Cluster>> std::vector<std::vector<Wt::Dbo::ptr<Cluster>>>
Release::getClusters(int size) const Release::getClusterGroups(std::vector<ClusterType::pointer> clusterTypes, std::size_t size) const
{ {
assert(self()); assert(self());
assert(self()->id() != Wt::Dbo::dbo_traits<Artist>::invalidId() ); assert(self()->id() != Wt::Dbo::dbo_traits<Artist>::invalidId() );
assert(session()); assert(session());
Wt::Dbo::Query<Cluster::pointer> query = session()->query<Cluster::pointer> WhereClause where;
("select c from cluster c INNER JOIN track t ON c.id = t_c.cluster_id INNER JOIN track_cluster t_c ON t_c.track_id = t.id INNER JOIN release r ON t.release_id = r.id")
.where("r.id = ?").bind(self()->id())
.groupBy("c.id")
.orderBy("COUNT(c.id) DESC")
.limit(size);
Wt::Dbo::collection<Cluster::pointer> res = query; std::ostringstream oss;
return std::vector<Cluster::pointer>(res.begin(), res.end()); oss << "SELECT c from cluster c INNER JOIN track t ON c.id = t_c.cluster_id INNER JOIN track_cluster t_c ON t_c.track_id = t.id INNER JOIN cluster_type c_type ON c.cluster_type_id = c_type.id INNER JOIN release r ON t.release_id = r.id";
where.And(WhereClause("r.id = ?")).bind(std::to_string(self()->id()));
{
WhereClause clusterClause;
for (auto clusterType : clusterTypes)
clusterClause.Or(WhereClause("c_type.id = ?")).bind(std::to_string(clusterType.id()));
where.And(clusterClause);
}
oss << " " << where.get();
oss << "GROUP BY c.id ORDER BY COUNT(c.id) DESC";
Wt::Dbo::Query<Cluster::pointer> query = session()->query<Cluster::pointer>( oss.str() );
for (const std::string& bindArg : where.getBindArgs())
query.bind(bindArg);
Wt::Dbo::collection<Cluster::pointer> queryRes = query;
std::map<ClusterType::id_type, std::vector<Cluster::pointer>> clusters;
for (auto cluster : queryRes)
{
if (clusters[cluster->getType().id()].size() < size)
clusters[cluster->getType().id()].push_back(cluster);
}
std::vector<std::vector<Cluster::pointer>> res;
for (auto cluster_list : clusters)
res.push_back(cluster_list.second);
return res;
} }
} // namespace Database } // namespace Database
+4 -1
View File
@@ -55,7 +55,10 @@ class Release : public Wt::Dbo::Dbo<Release>
bool& moreExpected); bool& moreExpected);
std::vector<Wt::Dbo::ptr<Track>> getTracks(const std::set<id_type>& clusters = std::set<id_type>()) const; std::vector<Wt::Dbo::ptr<Track>> getTracks(const std::set<id_type>& clusters = std::set<id_type>()) const;
std::vector<Wt::Dbo::ptr<Cluster>> getClusters(int size) const; // Get the cluster of the tracks that belong to this release
// Each clusters are grouped by cluster type, sorted by the number of occurence
// size is the max number of cluster per cluster type
std::vector<std::vector<Wt::Dbo::ptr<Cluster>>> getClusterGroups(std::vector<Wt::Dbo::ptr<ClusterType>> clusterTypes, std::size_t size) const;
// Create // Create
static pointer create(Wt::Dbo::Session& session, const std::string& name, const std::string& MBID = ""); static pointer create(Wt::Dbo::Session& session, const std::string& name, const std::string& MBID = "");
+5 -4
View File
@@ -36,7 +36,7 @@ AvFormat::AvFormat(const ClusterTypes& clusterTypes)
} }
boost::optional<Items> boost::optional<Items>
AvFormat::parse(const boost::filesystem::path& p) AvFormat::parse(const boost::filesystem::path& p, bool debug)
{ {
Items items; Items items;
@@ -73,9 +73,10 @@ AvFormat::parse(const boost::filesystem::path& p)
{ {
const std::string tag = boost::to_upper_copy<std::string>(metadata.first); const std::string tag = boost::to_upper_copy<std::string>(metadata.first);
const std::string value = metadata.second; const std::string value = metadata.second;
#if 0
std::cout << "TAG = " << tag << ", VAL = " << value << std::endl; if (debug)
#endif std::cout << "TAG = " << tag << ", VAL = " << value << std::endl;
if (tag == "ARTIST") if (tag == "ARTIST")
items.insert( std::make_pair(MetaData::Type::Artist, stringTrim( value) )); items.insert( std::make_pair(MetaData::Type::Artist, stringTrim( value) ));
else if (tag == "ALBUM") else if (tag == "ALBUM")
+1 -1
View File
@@ -34,7 +34,7 @@ class AvFormat : public Parser
AvFormat(const ClusterTypes& clusterTypes = defaultClusterTypes); AvFormat(const ClusterTypes& clusterTypes = defaultClusterTypes);
boost::optional<Items> parse(const boost::filesystem::path& p); boost::optional<Items> parse(const boost::filesystem::path& p, bool debug = false);
}; };
} // namespace MetaData } // namespace MetaData
+5 -2
View File
@@ -23,8 +23,11 @@ namespace MetaData {
const ClusterTypes Parser::defaultClusterTypes = const ClusterTypes Parser::defaultClusterTypes =
{ {
{"GENRE"}, "GENRE",
{"ALBUMGROUPING"}, "ALBUMGROUPING",
"MOOD",
"ALBUMMOOD",
"COMMENT:SONGS-DB_OCCASION",
}; };
} // namespace MetaData } // namespace MetaData
+1 -1
View File
@@ -73,7 +73,7 @@ namespace MetaData
// Provide a map for tag name -> Cluster name // Provide a map for tag name -> Cluster name
Parser(const ClusterTypes& clusterTypes) : _clusterTypes(clusterTypes) {} Parser(const ClusterTypes& clusterTypes) : _clusterTypes(clusterTypes) {}
virtual boost::optional<Items> parse(const boost::filesystem::path& p) = 0; virtual boost::optional<Items> parse(const boost::filesystem::path& p, bool debug = false) = 0;
void updateClusterTypes(const ClusterTypes& clusterTypes) { _clusterTypes = clusterTypes; } void updateClusterTypes(const ClusterTypes& clusterTypes) { _clusterTypes = clusterTypes; }
const ClusterTypes& getClusterTypes() const { return _clusterTypes; } const ClusterTypes& getClusterTypes() const { return _clusterTypes; }
+6 -6
View File
@@ -38,7 +38,7 @@ TagLibParser::TagLibParser(const ClusterTypes& clusterTypes)
} }
boost::optional<Items> boost::optional<Items>
TagLibParser::parse(const boost::filesystem::path& p) TagLibParser::parse(const boost::filesystem::path& p, bool debug)
{ {
TagLib::FileRef f(p.string().c_str(), TagLib::FileRef f(p.string().c_str(),
true, // read audio properties true, // read audio properties
@@ -89,13 +89,13 @@ TagLibParser::parse(const boost::filesystem::path& p)
// TODO validate MBID format // TODO validate MBID format
#if 0 if (debug)
std::cout << "TAG = '" << tag << "'" << std::endl;
for (auto value : values)
{ {
std::cout << "\t'" << value.to8Bit(true) << "'" << std::endl; std::cout << "TAG = '" << tag << "', VALUES = ";
for (auto value : values)
std::cout << "'" << value.to8Bit(true) << "',";
std::cout << std::endl;
} }
#endif
if (tag == "ARTIST") if (tag == "ARTIST")
items.insert( std::make_pair(MetaData::Type::Artist, stringTrim( values.front().to8Bit(true)))); items.insert( std::make_pair(MetaData::Type::Artist, stringTrim( values.front().to8Bit(true))));
+1 -1
View File
@@ -34,7 +34,7 @@ class TagLibParser : public Parser
TagLibParser(const ClusterTypes& clusterTypes = defaultClusterTypes); TagLibParser(const ClusterTypes& clusterTypes = defaultClusterTypes);
boost::optional<Items> parse(const boost::filesystem::path& p); boost::optional<Items> parse(const boost::filesystem::path& p, bool debug = false);
}; };
} // namespace MetaData } // namespace MetaData
+4 -4
View File
@@ -39,7 +39,7 @@ namespace {
const std::string updatePeriodSetting = "update_period"; const std::string updatePeriodSetting = "update_period";
const std::string updateStartTimeSetting = "update_start_time"; const std::string updateStartTimeSetting = "update_start_time";
const std::string clustersSetting = "clusters"; const std::string clusterTypesSetting = "cluster_types";
const std::string fileExtensionsSetting = "file_extensions"; const std::string fileExtensionsSetting = "file_extensions";
const std::vector<std::string> defaultFileExtensions = const std::vector<std::string> defaultFileExtensions =
@@ -152,10 +152,10 @@ _db(connectionPool)
if (!Setting::exists(_db.getSession(), fileExtensionsSetting)) if (!Setting::exists(_db.getSession(), fileExtensionsSetting))
Setting::setString(_db.getSession(), fileExtensionsSetting, joinStrings(defaultFileExtensions, " ")); Setting::setString(_db.getSession(), fileExtensionsSetting, joinStrings(defaultFileExtensions, " "));
if (!Setting::exists(_db.getSession(), clustersSetting)) if (!Setting::exists(_db.getSession(), clusterTypesSetting))
{ {
std::vector<std::string> defaultClusterTypes(MetaData::Parser::defaultClusterTypes.begin(), MetaData::Parser::defaultClusterTypes.end()); std::vector<std::string> defaultClusterTypes(MetaData::Parser::defaultClusterTypes.begin(), MetaData::Parser::defaultClusterTypes.end());
Setting::setString(_db.getSession(), clustersSetting, joinStrings(defaultClusterTypes, " ")); Setting::setString(_db.getSession(), clusterTypesSetting, joinStrings(defaultClusterTypes, " "));
} }
refreshScanSettings(); refreshScanSettings();
@@ -324,7 +324,7 @@ MediaScanner::refreshScanSettings()
_rootDirectories.push_back(rootDir->getPath()); _rootDirectories.push_back(rootDir->getPath());
MetaData::ClusterTypes clusterTypes; MetaData::ClusterTypes clusterTypes;
for (auto cluster : splitString(Setting::getString(_db.getSession(), clustersSetting), " ")) for (auto cluster : splitString(Setting::getString(_db.getSession(), clusterTypesSetting), " "))
clusterTypes.insert(cluster); clusterTypes.insert(cluster);
_metadataParser.updateClusterTypes(clusterTypes); _metadataParser.updateClusterTypes(clusterTypes);
+46 -7
View File
@@ -23,6 +23,7 @@
#include <Wt/WText.h> #include <Wt/WText.h>
#include "database/Types.hpp" #include "database/Types.hpp"
#include "database/Setting.hpp"
#include "utils/Logger.hpp" #include "utils/Logger.hpp"
#include "utils/Utils.hpp" #include "utils/Utils.hpp"
@@ -33,11 +34,44 @@
#include "Filters.hpp" #include "Filters.hpp"
#include "ArtistView.hpp" #include "ArtistView.hpp"
using namespace Database;
namespace {
const std::string artistClusterTypesSetting = "artist_cluster_types";
const std::vector<std::string> defaultArtistClusterTypes =
{
"GENRE",
"ALBUMGROUPING",
"ALBUMMOOD",
"COMMENT:SONGS-DB_OCCASION",
};
std::vector<ClusterType::pointer> getArtistClusterTypes(Wt::Dbo::Session& session)
{
Wt::Dbo::Transaction transaction(session);
std::vector<ClusterType::pointer> res;
for (auto clusterTypeName : splitString(Setting::getString(session, artistClusterTypesSetting), " "))
{
auto clusterType = ClusterType::getByName(session, clusterTypeName);
if (clusterType)
res.push_back(clusterType);
}
return res;
}
} // namespace
namespace UserInterface { namespace UserInterface {
Artist::Artist(Filters* filters) Artist::Artist(Filters* filters)
: _filters(filters) : _filters(filters)
{ {
if (!Setting::exists(LmsApp->getDboSession(), artistClusterTypesSetting))
Setting::setString(LmsApp->getDboSession(), artistClusterTypesSetting, joinStrings(defaultArtistClusterTypes, " "));
wApp->internalPathChanged().connect(std::bind([=] wApp->internalPathChanged().connect(std::bind([=]
{ {
refresh(); refresh();
@@ -64,6 +98,7 @@ Artist::refresh()
Wt::Dbo::Transaction transaction(LmsApp->getDboSession()); Wt::Dbo::Transaction transaction(LmsApp->getDboSession());
auto artist = Database::Artist::getById(LmsApp->getDboSession(), *artistId); auto artist = Database::Artist::getById(LmsApp->getDboSession(), *artistId);
if (!artist) if (!artist)
{ {
LmsApp->goHome(); LmsApp->goHome();
@@ -76,16 +111,20 @@ Artist::refresh()
Wt::WContainerWidget* clusterContainers = t->bindNew<Wt::WContainerWidget>("clusters"); Wt::WContainerWidget* clusterContainers = t->bindNew<Wt::WContainerWidget>("clusters");
{ {
auto clusters = artist->getClusters(3); auto clusterTypes = getArtistClusterTypes(LmsApp->getDboSession());
auto clusterGroups = artist->getClusterGroups(clusterTypes, 3);
for (auto cluster : clusters) for (auto clusters : clusterGroups)
{ {
auto clusterId = cluster.id(); for (auto cluster : clusters)
auto entry = clusterContainers->addWidget(LmsApp->createCluster(cluster));
entry->clicked().connect([=]
{ {
_filters->add(clusterId); auto clusterId = cluster.id();
}); auto entry = clusterContainers->addWidget(LmsApp->createCluster(cluster));
entry->clicked().connect([=]
{
_filters->add(clusterId);
});
}
} }
} }
+44 -7
View File
@@ -24,6 +24,7 @@
#include <Wt/WText.h> #include <Wt/WText.h>
#include "database/Types.hpp" #include "database/Types.hpp"
#include "database/Setting.hpp"
#include "utils/Logger.hpp" #include "utils/Logger.hpp"
#include "utils/Utils.hpp" #include "utils/Utils.hpp"
@@ -34,11 +35,43 @@
#include "Filters.hpp" #include "Filters.hpp"
#include "ReleaseView.hpp" #include "ReleaseView.hpp"
using namespace Database;
namespace {
const std::string releaseClusterTypesSetting = "release_cluster_types";
const std::vector<std::string> defaultReleaseClusterTypes =
{
"GENRE",
"ALBUMGROUPING",
"ALBUMMOOD",
"COMMENT:SONGS-DB_OCCASION",
};
std::vector<ClusterType::pointer> getReleaseClusterTypes(Wt::Dbo::Session& session)
{
Wt::Dbo::Transaction transaction(session);
std::vector<ClusterType::pointer> res;
for (auto clusterTypeName : splitString(Setting::getString(session, releaseClusterTypesSetting), " "))
{
auto clusterType = ClusterType::getByName(session, clusterTypeName);
if (clusterType)
res.push_back(clusterType);
}
return res;
}
} // namespace
namespace UserInterface { namespace UserInterface {
Release::Release(Filters* filters) Release::Release(Filters* filters)
: _filters(filters) : _filters(filters)
{ {
if (!Setting::exists(LmsApp->getDboSession(), releaseClusterTypesSetting))
Setting::setString(LmsApp->getDboSession(), releaseClusterTypesSetting, joinStrings(defaultReleaseClusterTypes, " "));
wApp->internalPathChanged().connect(std::bind([=] wApp->internalPathChanged().connect(std::bind([=]
{ {
refresh(); refresh();
@@ -109,16 +142,20 @@ Release::refresh()
Wt::WContainerWidget* clusterContainers = t->bindNew<Wt::WContainerWidget>("clusters"); Wt::WContainerWidget* clusterContainers = t->bindNew<Wt::WContainerWidget>("clusters");
{ {
auto clusters = release->getClusters(3); auto clusterTypes = getReleaseClusterTypes(LmsApp->getDboSession());
auto clusterGroups = release->getClusterGroups(clusterTypes, 3);
for (auto cluster : clusters) for (auto clusters : clusterGroups)
{ {
auto clusterId = cluster.id(); for (auto cluster : clusters)
auto entry = clusterContainers->addWidget(LmsApp->createCluster(cluster));
entry->clicked().connect([=]
{ {
_filters->add(clusterId); auto clusterId = cluster.id();
}); auto entry = clusterContainers->addWidget(LmsApp->createCluster(cluster));
entry->clicked().connect([=]
{
_filters->add(clusterId);
});
}
} }
} }
+1 -1
View File
@@ -30,7 +30,7 @@ int main(int argc, char *argv[])
for (auto& parser : parsers) for (auto& parser : parsers)
{ {
boost::optional<MetaData::Items> items = parser->parse(argv[1]); boost::optional<MetaData::Items> items = parser->parse(argv[1], true);
if (!items) if (!items)
{ {