From a997a356d2b3e8142e026343301717d7466c7967 Mon Sep 17 00:00:00 2001 From: modeco80 Date: Mon, 21 Oct 2024 21:21:37 -0400 Subject: [PATCH] it kind of works now --- .gitignore | 4 ++- .gitmodules | 3 ++ Makefile | 2 +- indicators | 1 + python_refonly/README.md | 3 ++ vxorg.cpp | 69 ++++++++++++++++++++++++++++++---------- 6 files changed, 63 insertions(+), 19 deletions(-) create mode 100644 .gitmodules create mode 160000 indicators create mode 100644 python_refonly/README.md diff --git a/.gitignore b/.gitignore index 292c875..83d3c3e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ -__pycache__/ +/__pycache__ +/.cache *.o /vxorg /tree_test /testdata +/compile_commands.json \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..58b9452 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "indicators"] + path = indicators + url = https://github.com/p-ranav/indicators diff --git a/Makefile b/Makefile index cddb22e..7ef94aa 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -CXX = g++ -std=c++23 -O3 +CXX = g++ -std=c++23 -O3 -I indicators/include all: vxorg tree_test diff --git a/indicators b/indicators new file mode 160000 index 0000000..9c855c9 --- /dev/null +++ b/indicators @@ -0,0 +1 @@ +Subproject commit 9c855c95e7782541a419597242535562fa9e41d7 diff --git a/python_refonly/README.md b/python_refonly/README.md new file mode 100644 index 0000000..6dd78e9 --- /dev/null +++ b/python_refonly/README.md @@ -0,0 +1,3 @@ +# python + +This was the original vxorg refactor/rewrite. It was abanodoned because the tree algorithms in python were so unbearably slow that even a iffy c++ reimplementation of the same tree is 100x faster \ No newline at end of file diff --git a/vxorg.cpp b/vxorg.cpp index 21715a7..f7c3b8a 100644 --- a/vxorg.cpp +++ b/vxorg.cpp @@ -1,24 +1,47 @@ #include #include +#include +#include #include +#include "indicators/terminal_size.hpp" #include "tree.hpp" #include "vxheaven_parse.hpp" +namespace ind = indicators; + int main() { std::ifstream ifs("./testdata/samples.sort"); vxorg::VxHeavenTree tree; vxorg::parse_into_tree(tree, ifs); - std::filesystem::path root = std::filesystem::current_path() / "testdata"; - std::filesystem::path unorg = root / "unorg"; - std::filesystem::path org = root / "org"; + std::filesystem::path root = std::filesystem::current_path() / "testdata"; + std::filesystem::path unorg = root / "unorg"; + std::filesystem::path org = root / "org"; - if(!std::filesystem::exists(org)) - std::filesystem::create_directories(org); + if(!std::filesystem::exists(org)) + std::filesystem::create_directories(org); - // walk the resulting tree + std::size_t sampleCount = 0; + + // Walk the tree to get the amount of sample nodes + tree.walk([&](auto* node) { + if(node->data().is_sample) + sampleCount++; + }); + + ind::ProgressBar bar { ind::option::BarWidth { indicators::terminal_width() - 64 }, + ind::option::Start { "[" }, + ind::option::Fill { "■" }, + ind::option::Lead { "■" }, + ind::option::Remainder { "-" }, + ind::option::End { " ]" }, + ind::option::ForegroundColor { ind::Color::cyan }, + ind::option::FontStyles { std::vector { ind::FontStyle::bold } }, + ind::option::MaxProgress { sampleCount } }; + + // Walk the tree to perform the operation tree.walk([&](auto* node) { auto tabulation_level = node->parent_count(); auto& data = node->data(); @@ -44,22 +67,34 @@ int main() { #if 1 - if(!node->is_root()) { - if(data.is_sample) { + if(!node->is_root()) { + if(data.is_sample) { std::string sample_name = vxorg::get_sample_name(node); - // paths - auto path = org / vxorg::get_sample_path(node); - auto source_path = unorg / vxorg::get_sample_name(node); + // paths + auto path = org / vxorg::get_sample_path(node); + auto source_path = unorg / vxorg::get_sample_name(node); - if(!std::filesystem::exists(source_path)) { - std::printf("WARNING: sample %s/%s in tree (source disk file %s) does not exist\n", path.string().c_str(), sample_name.c_str(), source_path.string().c_str()); - } + if(!std::filesystem::exists(source_path)) { + std::printf("WARNING: sample %s/%s in tree (source disk file %s) does not exist\n", path.string().c_str(), sample_name.c_str(), + source_path.string().c_str()); + } else { + if(!std::filesystem::exists(path)) { + std::filesystem::create_directories(path); + } + bar.set_option(ind::option::PostfixText { std::format("Moving {}", sample_name) }); - //std::printf("sample %s/%s in tree (source disk file %s)\n", path.string().c_str(), sample_name.c_str(), source_path.string().c_str()); - } - } + // FIXME Make this a move + std::filesystem::copy_file(source_path, path / vxorg::get_sample_name(node)); + + bar.tick(); + } + + // std::printf("sample %s/%s in tree (source disk file %s)\n", path.string().c_str(), sample_name.c_str(), + // source_path.string().c_str()); + } + } #endif }); return 0;