Restored similarity dumps in the similarity tool

This commit is contained in:
emeric
2019-11-20 13:47:11 +01:00
parent 6d69fc043b
commit c2ee50ab70
6 changed files with 100 additions and 2 deletions
+9
View File
@@ -86,6 +86,15 @@ Artist::getAll(Session& session, std::optional<std::size_t> offset, std::optiona
return std::vector<pointer>(res.begin(), res.end());
}
std::vector<IdType>
Artist::getAllIds(Session& session)
{
session.checkSharedLocked();
Wt::Dbo::collection<IdType> res = session.getDboSession().query<IdType>("SELECT id FROM artist");
return std::vector<IdType>(res.begin(), res.end());
}
std::vector<Artist::pointer>
Artist::getAllOrphans(Session& session)
{
+1
View File
@@ -62,6 +62,7 @@ class Artist : public Wt::Dbo::Dbo<Artist>
bool& moreExpected);
static std::vector<pointer> getAll(Session& session, std::optional<std::size_t> offset = {}, std::optional<std::size_t> size = {});
static std::vector<IdType> getAllIds(Session& session);
static std::vector<pointer> getAllOrphans(Session& session); // No track related
static std::vector<pointer> getLastAdded(Session& session, Wt::WDateTime after, std::optional<std::size_t> size = {});
+9
View File
@@ -96,6 +96,15 @@ Release::getAll(Session& session, std::optional<std::size_t> offset, std::option
return std::vector<pointer>(res.begin(), res.end());
}
std::vector<IdType>
Release::getAllIds(Session& session)
{
session.checkSharedLocked();
Wt::Dbo::collection<IdType> res = session.getDboSession().query<IdType>("SELECT id FROM release");
return std::vector<IdType>(res.begin(), res.end());
}
std::vector<Release::pointer>
Release::getAllOrderedByArtist(Session& session, std::optional<std::size_t> offset, std::optional<std::size_t> size)
{
+1
View File
@@ -52,6 +52,7 @@ class Release : public Wt::Dbo::Dbo<Release>
static pointer getById(Session& session, IdType id);
static std::vector<pointer> getAllOrphans(Session& session); // no track related
static std::vector<pointer> getAll(Session& session, std::optional<std::size_t> offset = {}, std::optional<std::size_t> size = {});
static std::vector<IdType> getAllIds(Session& session);
static std::vector<pointer> getAllOrderedByArtist(Session& session, std::optional<std::size_t> offset = {}, std::optional<std::size_t> size = {});
static std::vector<pointer> getAllRandom(Session& session, std::optional<std::size_t> size = {});
static std::vector<pointer> getLastAdded(Session& session, const Wt::WDateTime& after, std::optional<std::size_t> offset = {}, std::optional<std::size_t> size = {});
+2 -2
View File
@@ -70,8 +70,8 @@ class Track : public Wt::Dbo::Dbo<Track>
static std::vector<pointer> getAll(Session& session, std::optional<std::size_t> limit = {});
static std::vector<pointer> getAllRandom(Session& session, std::optional<std::size_t> limit = {});
static std::vector<IdType> getAllIds(Session& session); // nested transaction
static std::vector<std::filesystem::path> getAllPaths(Session& session); // nested transaction
static std::vector<IdType> getAllIds(Session& session);
static std::vector<std::filesystem::path> getAllPaths(Session& session);
static std::vector<pointer> getMBIDDuplicates(Session& session);
static std::vector<pointer> getLastAdded(Session& session, const Wt::WDateTime& after, std::optional<std::size_t> size = 1);
static std::vector<pointer> getAllWithMBIDAndMissingFeatures(Session& session);
+78
View File
@@ -3,8 +3,11 @@
#include <stdexcept>
#include <stdlib.h>
#include "database/Artist.hpp"
#include "database/Db.hpp"
#include "database/Release.hpp"
#include "database/Session.hpp"
#include "database/Track.hpp"
#include "utils/Config.hpp"
#include "utils/Service.hpp"
#include "utils/StreamLogger.hpp"
@@ -48,6 +51,81 @@ int main(int argc, char *argv[])
FeaturesSearcher searcher {session, featuresSettings};
std::cout << "Classifying tracks DONE" << std::endl;
const std::vector<Database::IdType> trackIds = std::invoke([&]()
{
auto transaction {session.createSharedTransaction()};
return Database::Track::getAllIds(session);
});
std::cout << "*** Tracks ***" << std::endl;
for (Database::IdType trackId : trackIds)
{
auto trackToString = [&](Database::IdType trackId)
{
std::string res;
auto transaction {session.createSharedTransaction()};
Database::Track::pointer track {Database::Track::getById(session, trackId)};
res += track->getName();
auto artists {track->getArtists()};
for (auto artist : artists )
res += " - " + artist->getName();
if (track->getRelease())
res += " [" + track->getRelease()->getName() + "]";
return res;
};
std::cout << "Processing track '" << trackToString(trackId) << std::endl;
for (Database::IdType similarTrackId : searcher.getSimilarTracks({trackId}, 3))
std::cout << "\t- Similar track '" << trackToString(similarTrackId) << std::endl;
}
const std::vector<Database::IdType> releaseIds = std::invoke([&]()
{
auto transaction {session.createSharedTransaction()};
return Database::Release::getAllIds(session);
});
std::cout << "*** Releases ***" << std::endl;
for (Database::IdType releaseId : releaseIds)
{
auto releaseToString = [&](Database::IdType releaseId)
{
auto transaction {session.createSharedTransaction()};
Database::Release::pointer release {Database::Release::getById(session, releaseId)};
return release->getName();
};
std::cout << "Processing release '" << releaseToString(releaseId) << "'" << std::endl;
for (Database::IdType similarReleaseId : searcher.getSimilarReleases({releaseId}, 3))
std::cout << "\t- Similar release '" << releaseToString(similarReleaseId) << "'" << std::endl;
}
const std::vector<Database::IdType> artistIds = std::invoke([&]()
{
auto transaction {session.createSharedTransaction()};
return Database::Artist::getAllIds(session);
});
std::cout << "*** Artists ***" << std::endl;
for (Database::IdType artistId : artistIds)
{
auto artistToString = [&](Database::IdType artistId)
{
auto transaction {session.createSharedTransaction()};
Database::Artist::pointer artist {Database::Artist::getById(session, artistId)};
return artist->getName();
};
std::cout << "Processing artist '" << artistToString(artistId) << "'" << std::endl;
for (Database::IdType similarArtistId : searcher.getSimilarArtists({artistId}, 3))
std::cout << "\t- Similar artist '" << artistToString(similarArtistId) << "'" << std::endl;
}
}
catch( std::exception& e)
{