chore: auto-commit (6 archivos)
- CMakeLists.txt - main.cpp - data_collectors.cpp - data_collectors.h - runner.cpp - runner.h Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -12,19 +12,34 @@
|
||||
#include "core/logger.h"
|
||||
|
||||
#include "data_registry.h"
|
||||
#include "data_collectors.h"
|
||||
#include "runner.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
static OdrRegistry g_registry;
|
||||
static std::string g_db_path;
|
||||
static std::string g_app_dir; // dir de odr_console (collectors/, ops db)
|
||||
static std::string g_python_exe; // resolved al arrancar
|
||||
static std::string g_registry_root; // FN_REGISTRY_ROOT
|
||||
static std::string g_ops_db_path; // <app_dir>/operations.db
|
||||
|
||||
static char g_search_buf[256] = "";
|
||||
static std::vector<RegistryRow> g_results;
|
||||
static int g_selected = -1;
|
||||
|
||||
static std::vector<Collector> g_collectors;
|
||||
static int g_coll_selected = -1;
|
||||
static int g_coll_param_limit = 30;
|
||||
static std::string g_last_run_summary; // texto status del ultimo run
|
||||
static bool g_running = false;
|
||||
|
||||
static void do_search() {
|
||||
g_results.clear();
|
||||
g_selected = -1;
|
||||
@@ -35,9 +50,126 @@ static void do_search() {
|
||||
}
|
||||
}
|
||||
|
||||
static bool g_show_launcher = true;
|
||||
static bool g_show_jobs = true;
|
||||
static bool g_show_datasets = true;
|
||||
static bool g_show_launcher = true;
|
||||
static bool g_show_collectors = true;
|
||||
static bool g_show_jobs = true;
|
||||
static bool g_show_datasets = true;
|
||||
|
||||
static void run_selected_collector() {
|
||||
if (g_coll_selected < 0 ||
|
||||
g_coll_selected >= (int)g_collectors.size()) return;
|
||||
const Collector& c = g_collectors[g_coll_selected];
|
||||
if (!c.has_run) return;
|
||||
|
||||
std::ostringstream ctx;
|
||||
ctx << "{"
|
||||
<< "\"ops_db_path\":\"" << g_ops_db_path << "\","
|
||||
<< "\"app_dir\":\"" << g_app_dir << "\","
|
||||
<< "\"registry_root\":\"" << g_registry_root << "\","
|
||||
<< "\"params\":{\"limit\":" << g_coll_param_limit << "}"
|
||||
<< "}";
|
||||
|
||||
std::string tmp_dir = std::string(fn::local_path("runner_tmp"));
|
||||
g_running = true;
|
||||
auto res = odr::run_collector(g_python_exe, c.run_py, tmp_dir, ctx.str());
|
||||
g_running = false;
|
||||
|
||||
std::ostringstream s;
|
||||
s << "exit=" << res.exit_code
|
||||
<< " ms=" << res.duration_ms
|
||||
<< "\nstdout: " << res.stdout_str
|
||||
<< "\nstderr (last):\n";
|
||||
// Solo ultimas 10 lineas de stderr para no inundar UI.
|
||||
std::vector<std::string> lines;
|
||||
std::istringstream ss(res.stderr_str);
|
||||
std::string ln;
|
||||
while (std::getline(ss, ln)) lines.push_back(ln);
|
||||
int start = (int)lines.size() - 10;
|
||||
if (start < 0) start = 0;
|
||||
for (int i = start; i < (int)lines.size(); ++i) s << lines[i] << "\n";
|
||||
g_last_run_summary = s.str();
|
||||
}
|
||||
|
||||
static void draw_collectors() {
|
||||
if (!g_show_collectors) return;
|
||||
if (!ImGui::Begin(TI_PLAYER_PLAY " Collectors", &g_show_collectors)) {
|
||||
ImGui::End();
|
||||
return;
|
||||
}
|
||||
if (ImGui::Button("Refresh")) {
|
||||
std::string root = g_app_dir + "/collectors";
|
||||
collectors_discover(root, g_collectors);
|
||||
g_coll_selected = -1;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled("%zu collectors", g_collectors.size());
|
||||
|
||||
if (g_collectors.empty()) {
|
||||
ImGui::TextDisabled("No collectors found in %s/collectors/",
|
||||
g_app_dir.c_str());
|
||||
ImGui::End();
|
||||
return;
|
||||
}
|
||||
|
||||
if (ImGui::BeginTable("##collectors", 3,
|
||||
ImGuiTableFlags_RowBg | ImGuiTableFlags_Borders |
|
||||
ImGuiTableFlags_Resizable)) {
|
||||
ImGui::TableSetupColumn("ID", ImGuiTableColumnFlags_WidthFixed, 180);
|
||||
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, 200);
|
||||
ImGui::TableSetupColumn("Description", ImGuiTableColumnFlags_WidthStretch);
|
||||
ImGui::TableHeadersRow();
|
||||
|
||||
for (int i = 0; i < (int)g_collectors.size(); ++i) {
|
||||
const auto& c = g_collectors[i];
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
bool sel = (i == g_coll_selected);
|
||||
if (ImGui::Selectable(c.id.c_str(), sel,
|
||||
ImGuiSelectableFlags_SpanAllColumns)) {
|
||||
g_coll_selected = i;
|
||||
}
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
ImGui::TextUnformatted(c.name.c_str());
|
||||
ImGui::TableSetColumnIndex(2);
|
||||
ImGui::TextUnformatted(c.description.c_str());
|
||||
}
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
if (g_coll_selected >= 0 &&
|
||||
g_coll_selected < (int)g_collectors.size()) {
|
||||
const auto& c = g_collectors[g_coll_selected];
|
||||
ImGui::Separator();
|
||||
ImGui::Text("Selected: %s", c.id.c_str());
|
||||
ImGui::TextDisabled("%s", c.run_py.c_str());
|
||||
|
||||
ImGui::PushItemWidth(120);
|
||||
ImGui::InputInt("limit", &g_coll_param_limit);
|
||||
ImGui::PopItemWidth();
|
||||
if (g_coll_param_limit < 1) g_coll_param_limit = 1;
|
||||
if (g_coll_param_limit > 500) g_coll_param_limit = 500;
|
||||
|
||||
ImGui::BeginDisabled(g_running || !c.has_run);
|
||||
if (ImGui::Button(g_running ? "Running..." : (TI_PLAYER_PLAY " Run"))) {
|
||||
run_selected_collector();
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
if (!c.has_run) {
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled("(missing run.py)");
|
||||
}
|
||||
}
|
||||
|
||||
if (!g_last_run_summary.empty()) {
|
||||
ImGui::Separator();
|
||||
ImGui::TextUnformatted("Last run:");
|
||||
ImGui::BeginChild("##run_summary", ImVec2(0, 200), true);
|
||||
ImGui::TextUnformatted(g_last_run_summary.c_str());
|
||||
ImGui::EndChild();
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
static void draw_launcher() {
|
||||
if (!g_show_launcher) return;
|
||||
@@ -130,14 +262,16 @@ static void draw_datasets() {
|
||||
|
||||
static void render() {
|
||||
static fn_ui::PanelToggle panels[] = {
|
||||
{ "Launcher", nullptr, &g_show_launcher },
|
||||
{ "Jobs", nullptr, &g_show_jobs },
|
||||
{ "Datasets", nullptr, &g_show_datasets },
|
||||
{ "Launcher", nullptr, &g_show_launcher },
|
||||
{ "Collectors", nullptr, &g_show_collectors },
|
||||
{ "Jobs", nullptr, &g_show_jobs },
|
||||
{ "Datasets", nullptr, &g_show_datasets },
|
||||
};
|
||||
fn_ui::app_menubar(panels,
|
||||
sizeof(panels) / sizeof(panels[0]),
|
||||
nullptr);
|
||||
draw_launcher();
|
||||
draw_collectors();
|
||||
draw_jobs();
|
||||
draw_datasets();
|
||||
}
|
||||
@@ -170,6 +304,44 @@ int main(int argc, char** argv) {
|
||||
registry_list_recent(g_registry, 50, g_results);
|
||||
}
|
||||
|
||||
// Resolver registry_root, app_dir, python_exe.
|
||||
if (const char* root = std::getenv("FN_REGISTRY_ROOT"); root && *root) {
|
||||
g_registry_root = root;
|
||||
} else if (!g_db_path.empty()) {
|
||||
// Asume registry.db esta en raiz del registry.
|
||||
std::filesystem::path p(g_db_path);
|
||||
g_registry_root = p.parent_path().string();
|
||||
}
|
||||
|
||||
if (const char* d = std::getenv("ODR_APP_DIR"); d && *d) {
|
||||
g_app_dir = d;
|
||||
} else if (!g_registry_root.empty()) {
|
||||
g_app_dir = g_registry_root +
|
||||
"/projects/online_data_recopilation/apps/odr_console";
|
||||
}
|
||||
g_ops_db_path = g_app_dir + "/operations.db";
|
||||
|
||||
if (const char* py = std::getenv("FN_PYTHON"); py && *py) {
|
||||
g_python_exe = py;
|
||||
} else if (!g_registry_root.empty()) {
|
||||
g_python_exe = g_registry_root + "/python/.venv/bin/python3";
|
||||
} else {
|
||||
g_python_exe = "python3";
|
||||
}
|
||||
|
||||
// Discover collectors: prefer app_dir/collectors, fallback a
|
||||
// <exe_dir>/assets/collectors/ (Windows distribuible).
|
||||
if (!g_app_dir.empty()) {
|
||||
collectors_discover(g_app_dir + "/collectors", g_collectors);
|
||||
}
|
||||
if (g_collectors.empty()) {
|
||||
const char* assets = fn::asset_dir();
|
||||
if (assets && *assets) {
|
||||
std::string assets_collectors = std::string(assets) + "/collectors";
|
||||
collectors_discover(assets_collectors, g_collectors);
|
||||
}
|
||||
}
|
||||
|
||||
fn::AppConfig cfg;
|
||||
cfg.title = "odr_console — online data recopilation";
|
||||
cfg.width = 1400;
|
||||
|
||||
Reference in New Issue
Block a user