From 0e6355329f241a3e3c8b38cb4146fda4470e6ed0 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 26 Mar 2018 15:33:06 -0400 Subject: Whitespace changes --- generator/generator.cpp | 56 ++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'generator/generator.cpp') diff --git a/generator/generator.cpp b/generator/generator.cpp index eb2750c..54f5d69 100644 --- a/generator/generator.cpp +++ b/generator/generator.cpp @@ -11,7 +11,7 @@ namespace cadence { namespace generator { - + generator::generator( std::string inputpath, std::string outputpath) : @@ -23,23 +23,23 @@ namespace cadence { { inputpath_ += '/'; } - + inputpath_ += "highlevel/"; } - + void generator::run() { // Creates the datafile. writeSchema(); - + // Scans the AcousticBrainz data dump and generates a list of all of the // files in the dump. scanDirectories(); - + // Parses each data file and enters it into the database. parseData(); } - + void generator::writeSchema() { std::ifstream file("schema.sql"); @@ -47,7 +47,7 @@ namespace cadence { { throw std::invalid_argument("Could not find database schema"); } - + std::ostringstream schemaBuilder; std::string line; while (std::getline(file, line)) @@ -56,10 +56,10 @@ namespace cadence { { line.pop_back(); } - + schemaBuilder << line; } - + std::string schema = schemaBuilder.str(); auto queries = split>(schema, ";"); progress ppgs("Writing database schema...", queries.size()); @@ -69,73 +69,73 @@ namespace cadence { { db_.runQuery(query); } - + ppgs.update(); } } - + void generator::scanDirectories() { std::cout << "Scanning AcousticBrainz dump..." << std::endl; - + DIR* topdir; if ((topdir = opendir(inputpath_.c_str())) == nullptr) { throw std::invalid_argument("Invalid AcousticBrainz data directory"); } - + struct dirent* topent; while ((topent = readdir(topdir)) != nullptr) { if (topent->d_name[0] != '.') { std::string directory = inputpath_ + topent->d_name + "/"; - + DIR* subdir; if ((subdir = opendir(directory.c_str())) == nullptr) { throw std::invalid_argument("Invalid AcousticBrainz data directory"); } - + struct dirent* subent; while ((subent = readdir(subdir)) != nullptr) { if (subent->d_name[0] != '.') { std::string subdirectory = directory + subent->d_name + "/"; - + DIR* subsubdir; if ((subsubdir = opendir(subdirectory.c_str())) == nullptr) { throw std::invalid_argument("Invalid AcousticBrainz data directory"); } - + struct dirent* subsubent; while ((subsubent = readdir(subsubdir)) != nullptr) { if (subsubent->d_name[0] != '.') { std::string datafile = subdirectory + subsubent->d_name; - + datafiles_.push_back(datafile); } } - + closedir(subsubdir); } } - + closedir(subdir); } } - + closedir(topdir); } - + void generator::parseData() { progress ppgs("Parsing AcousticBrainz data files...", datafiles_.size()); - + for (std::string datafile : datafiles_) { ppgs.update(); @@ -145,7 +145,7 @@ namespace cadence { std::ifstream dataStream(datafile); dataStream >> jsonData; } - + try { std::vector moods; @@ -158,16 +158,16 @@ namespace cadence { moods.emplace_back(mood::type::relaxed, jsonData["highlevel"]["mood_relaxed"]["all"]["relaxed"]); moods.emplace_back(mood::type::sad, jsonData["highlevel"]["mood_sad"]["all"]["sad"]); moods.emplace_back(mood::type::instrumental, jsonData["highlevel"]["voice_instrumental"]["all"]["instrumental"]); - + std::sort(std::begin(moods), std::end(moods), [] (const mood& left, const mood& right) -> bool { return left.getProbability() > right.getProbability(); }); - + std::list fields; fields.emplace_back("title", jsonData["metadata"]["tags"]["title"][0].get()); fields.emplace_back("artist", jsonData["metadata"]["tags"]["artist"][0].get()); fields.emplace_back("category", moods.front().getCategory()); - + db_.insertIntoTable("songs", std::move(fields)); } catch (const std::domain_error& ex) { @@ -175,6 +175,6 @@ namespace cadence { } } } - + }; }; -- cgit 1.4.1