diff options
Diffstat (limited to 'generator/generator.cpp')
| -rw-r--r-- | generator/generator.cpp | 27 |
1 files changed, 14 insertions, 13 deletions
| diff --git a/generator/generator.cpp b/generator/generator.cpp index 54f5d69..19eba70 100644 --- a/generator/generator.cpp +++ b/generator/generator.cpp | |||
| @@ -4,9 +4,8 @@ | |||
| 4 | #include <fstream> | 4 | #include <fstream> |
| 5 | #include <dirent.h> | 5 | #include <dirent.h> |
| 6 | #include <json.hpp> | 6 | #include <json.hpp> |
| 7 | #include "progress.h" | 7 | #include <hkutil/progress.h> |
| 8 | #include "field.h" | 8 | #include <hkutil/string.h> |
| 9 | #include "../util.h" | ||
| 10 | #include "mood.h" | 9 | #include "mood.h" |
| 11 | 10 | ||
| 12 | namespace cadence { | 11 | namespace cadence { |
| @@ -16,7 +15,7 @@ namespace cadence { | |||
| 16 | std::string inputpath, | 15 | std::string inputpath, |
| 17 | std::string outputpath) : | 16 | std::string outputpath) : |
| 18 | inputpath_(inputpath), | 17 | inputpath_(inputpath), |
| 19 | db_(outputpath) | 18 | db_(outputpath, hatkirby::dbmode::create) |
| 20 | { | 19 | { |
| 21 | // Add directory separator to input path | 20 | // Add directory separator to input path |
| 22 | if ((inputpath_.back() != '/') && (inputpath_.back() != '\\')) | 21 | if ((inputpath_.back() != '/') && (inputpath_.back() != '\\')) |
| @@ -61,13 +60,13 @@ namespace cadence { | |||
| 61 | } | 60 | } |
| 62 | 61 | ||
| 63 | std::string schema = schemaBuilder.str(); | 62 | std::string schema = schemaBuilder.str(); |
| 64 | auto queries = split<std::list<std::string>>(schema, ";"); | 63 | auto queries = hatkirby::split<std::list<std::string>>(schema, ";"); |
| 65 | progress ppgs("Writing database schema...", queries.size()); | 64 | hatkirby::progress ppgs("Writing database schema...", queries.size()); |
| 66 | for (std::string query : queries) | 65 | for (std::string query : queries) |
| 67 | { | 66 | { |
| 68 | if (!queries.empty()) | 67 | if (!queries.empty()) |
| 69 | { | 68 | { |
| 70 | db_.runQuery(query); | 69 | db_.execute(query); |
| 71 | } | 70 | } |
| 72 | 71 | ||
| 73 | ppgs.update(); | 72 | ppgs.update(); |
| @@ -134,7 +133,9 @@ namespace cadence { | |||
| 134 | 133 | ||
| 135 | void generator::parseData() | 134 | void generator::parseData() |
| 136 | { | 135 | { |
| 137 | progress ppgs("Parsing AcousticBrainz data files...", datafiles_.size()); | 136 | hatkirby::progress ppgs( |
| 137 | "Parsing AcousticBrainz data files...", | ||
| 138 | datafiles_.size()); | ||
| 138 | 139 | ||
| 139 | for (std::string datafile : datafiles_) | 140 | for (std::string datafile : datafiles_) |
| 140 | { | 141 | { |
| @@ -163,12 +164,12 @@ namespace cadence { | |||
| 163 | return left.getProbability() > right.getProbability(); | 164 | return left.getProbability() > right.getProbability(); |
| 164 | }); | 165 | }); |
| 165 | 166 | ||
| 166 | std::list<field> fields; | 167 | std::list<hatkirby::column> columns; |
| 167 | fields.emplace_back("title", jsonData["metadata"]["tags"]["title"][0].get<std::string>()); | 168 | columns.emplace_back("title", jsonData["metadata"]["tags"]["title"][0].get<std::string>()); |
| 168 | fields.emplace_back("artist", jsonData["metadata"]["tags"]["artist"][0].get<std::string>()); | 169 | columns.emplace_back("artist", jsonData["metadata"]["tags"]["artist"][0].get<std::string>()); |
| 169 | fields.emplace_back("category", moods.front().getCategory()); | 170 | columns.emplace_back("category", moods.front().getCategory()); |
| 170 | 171 | ||
| 171 | db_.insertIntoTable("songs", std::move(fields)); | 172 | db_.insertIntoTable("songs", std::move(columns)); |
| 172 | } catch (const std::domain_error& ex) | 173 | } catch (const std::domain_error& ex) |
| 173 | { | 174 | { |
| 174 | // Weird data. Ignore silently. | 175 | // Weird data. Ignore silently. |
