Open excel file automatically when generated
This commit is contained in:
@@ -336,6 +336,7 @@ namespace platform {
|
|||||||
BestResultsExcel excel_report(path, score, datasets);
|
BestResultsExcel excel_report(path, score, datasets);
|
||||||
excel_report.reportSingle(model, path + Paths::bestResultsFile(score, model));
|
excel_report.reportSingle(model, path + Paths::bestResultsFile(score, model));
|
||||||
messageOutputFile("Excel", excel_report.getFileName());
|
messageOutputFile("Excel", excel_report.getFileName());
|
||||||
|
excelFileName = excel_report.getFileName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void BestResults::reportAll(bool excel, bool tex, bool index)
|
void BestResults::reportAll(bool excel, bool tex, bool index)
|
||||||
@@ -373,6 +374,7 @@ namespace platform {
|
|||||||
excel.reportSingle(model, path + Paths::bestResultsFile(score, model));
|
excel.reportSingle(model, path + Paths::bestResultsFile(score, model));
|
||||||
}
|
}
|
||||||
messageOutputFile("Excel", excel.getFileName());
|
messageOutputFile("Excel", excel.getFileName());
|
||||||
|
excelFileName = excel.getFileName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void BestResults::messageOutputFile(const std::string& title, const std::string& fileName)
|
void BestResults::messageOutputFile(const std::string& title, const std::string& fileName)
|
||||||
|
@@ -15,6 +15,7 @@ namespace platform {
|
|||||||
void reportSingle(bool excel);
|
void reportSingle(bool excel);
|
||||||
void reportAll(bool excel, bool tex, bool index);
|
void reportAll(bool excel, bool tex, bool index);
|
||||||
void buildAll();
|
void buildAll();
|
||||||
|
std::string getExcelFileName() const { return excelFileName; }
|
||||||
private:
|
private:
|
||||||
std::vector<std::string> getModels();
|
std::vector<std::string> getModels();
|
||||||
std::vector<std::string> getDatasets(json table);
|
std::vector<std::string> getDatasets(json table);
|
||||||
@@ -33,6 +34,7 @@ namespace platform {
|
|||||||
int maxModelName = 0;
|
int maxModelName = 0;
|
||||||
int maxDatasetName = 0;
|
int maxDatasetName = 0;
|
||||||
int minLength = 13; // Minimum length for scores
|
int minLength = 13; // Minimum length for scores
|
||||||
|
std::string excelFileName;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
@@ -4,6 +4,7 @@
|
|||||||
#include "main/modelRegister.h"
|
#include "main/modelRegister.h"
|
||||||
#include "common/Paths.h"
|
#include "common/Paths.h"
|
||||||
#include "common/Colors.h"
|
#include "common/Colors.h"
|
||||||
|
#include "common/Utils.h"
|
||||||
#include "best/BestResults.h"
|
#include "best/BestResults.h"
|
||||||
#include "common/DotEnv.h"
|
#include "common/DotEnv.h"
|
||||||
#include "config_platform.h"
|
#include "config_platform.h"
|
||||||
@@ -80,6 +81,11 @@ int main(int argc, char** argv)
|
|||||||
std::cout << Colors::GREEN() << fileName << " created!" << Colors::RESET() << std::endl;
|
std::cout << Colors::GREEN() << fileName << " created!" << Colors::RESET() << std::endl;
|
||||||
results.reportSingle(excel);
|
results.reportSingle(excel);
|
||||||
}
|
}
|
||||||
|
if (excel) {
|
||||||
|
auto fileName = results.getExcelFileName();
|
||||||
|
std::cout << "Opening " << fileName << std::endl;
|
||||||
|
platform::openFile(fileName);
|
||||||
|
}
|
||||||
std::cout << Colors::RESET();
|
std::cout << Colors::RESET();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
#include "common/Paths.h"
|
#include "common/Paths.h"
|
||||||
#include "common/Colors.h"
|
#include "common/Colors.h"
|
||||||
#include "common/Datasets.h"
|
#include "common/Datasets.h"
|
||||||
|
#include "common/Utils.h"
|
||||||
#include "reports/DatasetsExcel.h"
|
#include "reports/DatasetsExcel.h"
|
||||||
#include "reports/DatasetsConsole.h"
|
#include "reports/DatasetsConsole.h"
|
||||||
#include "results/ResultsDatasetConsole.h"
|
#include "results/ResultsDatasetConsole.h"
|
||||||
@@ -24,9 +25,13 @@ void list_datasets(argparse::ArgumentParser& program)
|
|||||||
std::cout << report.getOutput();
|
std::cout << report.getOutput();
|
||||||
if (excel) {
|
if (excel) {
|
||||||
auto data = report.getData();
|
auto data = report.getData();
|
||||||
auto report = platform::DatasetsExcel();
|
auto ereport = new platform::DatasetsExcel();
|
||||||
report.report(data);
|
ereport->report(data);
|
||||||
std::cout << std::endl << Colors::GREEN() << "Output saved in " << report.getFileName() << std::endl;
|
std::cout << std::endl << Colors::GREEN() << "Output saved in " << ereport->getFileName() << std::endl;
|
||||||
|
auto fileName = ereport->getExcelFileName();
|
||||||
|
delete ereport;
|
||||||
|
std::cout << "Opening " << fileName << std::endl;
|
||||||
|
platform::openFile(fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,9 +47,13 @@ void list_results(argparse::ArgumentParser& program)
|
|||||||
std::cout << report.getOutput();
|
std::cout << report.getOutput();
|
||||||
if (excel) {
|
if (excel) {
|
||||||
auto data = report.getData();
|
auto data = report.getData();
|
||||||
auto report = platform::ResultsDatasetExcel();
|
auto ereport = new platform::ResultsDatasetExcel();
|
||||||
report.report(data);
|
ereport->report(data);
|
||||||
std::cout << std::endl << Colors::GREEN() << "Output saved in " << report.getFileName() << std::endl;
|
std::cout << std::endl << Colors::GREEN() << "Output saved in " << ereport->getFileName() << std::endl;
|
||||||
|
auto fileName = ereport->getExcelFileName();
|
||||||
|
delete ereport;
|
||||||
|
std::cout << "Opening " << fileName << std::endl;
|
||||||
|
platform::openFile(fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
|
#include <utility>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <utility>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include "common/Paths.h"
|
#include "common/Paths.h"
|
||||||
#include <argparse/argparse.hpp>
|
#include <argparse/argparse.hpp>
|
||||||
#include "manage/ManageScreen.h"
|
#include "manage/ManageScreen.h"
|
||||||
@@ -53,65 +53,7 @@ void handleResize(int sig)
|
|||||||
manager->updateSize(rows, cols);
|
manager->updateSize(rows, cols);
|
||||||
}
|
}
|
||||||
|
|
||||||
void openFile(const std::string& fileName)
|
|
||||||
{
|
|
||||||
// #ifdef __APPLE__
|
|
||||||
// // macOS uses the "open" command
|
|
||||||
// std::string command = "open";
|
|
||||||
// #elif defined(__linux__)
|
|
||||||
// // Linux typically uses "xdg-open"
|
|
||||||
// std::string command = "xdg-open";
|
|
||||||
// #else
|
|
||||||
// // For other OSes, do nothing or handle differently
|
|
||||||
// std::cerr << "Unsupported platform." << std::endl;
|
|
||||||
// return;
|
|
||||||
// #endif
|
|
||||||
// execlp(command.c_str(), command.c_str(), fileName.c_str(), NULL);
|
|
||||||
#ifdef __APPLE__
|
|
||||||
const char* tool = "/usr/bin/open";
|
|
||||||
#elif defined(__linux__)
|
|
||||||
const char* tool = "/usr/bin/xdg-open";
|
|
||||||
#else
|
|
||||||
std::cerr << "Unsupported platform." << std::endl;
|
|
||||||
return;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// We'll build an argv array for execve:
|
|
||||||
std::vector<char*> argv;
|
|
||||||
argv.push_back(const_cast<char*>(tool)); // argv[0]
|
|
||||||
argv.push_back(const_cast<char*>(fileName.c_str())); // argv[1]
|
|
||||||
argv.push_back(nullptr);
|
|
||||||
|
|
||||||
// Make a new environment array, skipping BASH_FUNC_ variables
|
|
||||||
std::vector<std::string> filteredEnv;
|
|
||||||
for (char** env = environ; *env != nullptr; ++env) {
|
|
||||||
// *env is a string like "NAME=VALUE"
|
|
||||||
// We want to skip those starting with "BASH_FUNC_"
|
|
||||||
if (strncmp(*env, "BASH_FUNC_", 10) == 0) {
|
|
||||||
// skip it
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
filteredEnv.push_back(*env);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert filteredEnv into a char* array
|
|
||||||
std::vector<char*> envp;
|
|
||||||
for (auto& var : filteredEnv) {
|
|
||||||
envp.push_back(const_cast<char*>(var.c_str()));
|
|
||||||
}
|
|
||||||
envp.push_back(nullptr);
|
|
||||||
|
|
||||||
// Now call execve with the cleaned environment
|
|
||||||
// NOTE: You may need a full path to the tool if it's not in PATH, or use which() logic
|
|
||||||
// For now, let's assume "open" or "xdg-open" is found in the default PATH:
|
|
||||||
execve(tool, argv.data(), envp.data());
|
|
||||||
|
|
||||||
// If we reach here, execve failed
|
|
||||||
perror("execve failed");
|
|
||||||
// This would terminate your current process if it's not in a child
|
|
||||||
// Usually you'd do something like:
|
|
||||||
_exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
@@ -137,7 +79,7 @@ int main(int argc, char** argv)
|
|||||||
delete manager;
|
delete manager;
|
||||||
if (!fileName.empty()) {
|
if (!fileName.empty()) {
|
||||||
std::cout << "Opening " << fileName << std::endl;
|
std::cout << "Opening " << fileName << std::endl;
|
||||||
openFile(fileName);
|
platform::openFile(fileName);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -49,6 +49,7 @@ namespace platform {
|
|||||||
return "BestResults_" + score + ".xlsx";
|
return "BestResults_" + score + ".xlsx";
|
||||||
}
|
}
|
||||||
static std::string excelResults() { return "some_results.xlsx"; }
|
static std::string excelResults() { return "some_results.xlsx"; }
|
||||||
|
static std::string excelDatasets() { return "datasets.xlsx"; }
|
||||||
static std::string grid_input(const std::string& model)
|
static std::string grid_input(const std::string& model)
|
||||||
{
|
{
|
||||||
return grid() + "grid_" + model + "_input.json";
|
return grid() + "grid_" + model + "_input.json";
|
||||||
@@ -73,6 +74,7 @@ namespace platform {
|
|||||||
{
|
{
|
||||||
return "post_hoc.md";
|
return "post_hoc.md";
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
@@ -1,5 +1,7 @@
|
|||||||
#ifndef UTILS_H
|
#ifndef UTILS_H
|
||||||
#define UTILS_H
|
#define UTILS_H
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -66,5 +68,64 @@ namespace platform {
|
|||||||
oss << std::put_time(timeinfo, "%H:%M:%S");
|
oss << std::put_time(timeinfo, "%H:%M:%S");
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
static void openFile(const std::string& fileName)
|
||||||
|
{
|
||||||
|
// #ifdef __APPLE__
|
||||||
|
// // macOS uses the "open" command
|
||||||
|
// std::string command = "open";
|
||||||
|
// #elif defined(__linux__)
|
||||||
|
// // Linux typically uses "xdg-open"
|
||||||
|
// std::string command = "xdg-open";
|
||||||
|
// #else
|
||||||
|
// // For other OSes, do nothing or handle differently
|
||||||
|
// std::cerr << "Unsupported platform." << std::endl;
|
||||||
|
// return;
|
||||||
|
// #endif
|
||||||
|
// execlp(command.c_str(), command.c_str(), fileName.c_str(), NULL);
|
||||||
|
#ifdef __APPLE__
|
||||||
|
const char* tool = "/usr/bin/open";
|
||||||
|
#elif defined(__linux__)
|
||||||
|
const char* tool = "/usr/bin/xdg-open";
|
||||||
|
#else
|
||||||
|
std::cerr << "Unsupported platform." << std::endl;
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// We'll build an argv array for execve:
|
||||||
|
std::vector<char*> argv;
|
||||||
|
argv.push_back(const_cast<char*>(tool)); // argv[0]
|
||||||
|
argv.push_back(const_cast<char*>(fileName.c_str())); // argv[1]
|
||||||
|
argv.push_back(nullptr);
|
||||||
|
|
||||||
|
// Make a new environment array, skipping BASH_FUNC_ variables
|
||||||
|
std::vector<std::string> filteredEnv;
|
||||||
|
for (char** env = environ; *env != nullptr; ++env) {
|
||||||
|
// *env is a string like "NAME=VALUE"
|
||||||
|
// We want to skip those starting with "BASH_FUNC_"
|
||||||
|
if (strncmp(*env, "BASH_FUNC_", 10) == 0) {
|
||||||
|
// skip it
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
filteredEnv.push_back(*env);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert filteredEnv into a char* array
|
||||||
|
std::vector<char*> envp;
|
||||||
|
for (auto& var : filteredEnv) {
|
||||||
|
envp.push_back(const_cast<char*>(var.c_str()));
|
||||||
|
}
|
||||||
|
envp.push_back(nullptr);
|
||||||
|
|
||||||
|
// Now call execve with the cleaned environment
|
||||||
|
// NOTE: You may need a full path to the tool if it's not in PATH, or use which() logic
|
||||||
|
// For now, let's assume "open" or "xdg-open" is found in the default PATH:
|
||||||
|
execve(tool, argv.data(), envp.data());
|
||||||
|
|
||||||
|
// If we reach here, execve failed
|
||||||
|
perror("execve failed");
|
||||||
|
// This would terminate your current process if it's not in a child
|
||||||
|
// Usually you'd do something like:
|
||||||
|
_exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
@@ -1,8 +1,9 @@
|
|||||||
|
#include "common/Paths.h"
|
||||||
#include "DatasetsExcel.h"
|
#include "DatasetsExcel.h"
|
||||||
namespace platform {
|
namespace platform {
|
||||||
DatasetsExcel::DatasetsExcel()
|
DatasetsExcel::DatasetsExcel()
|
||||||
{
|
{
|
||||||
file_name = "datasets.xlsx";
|
file_name = Paths::excelDatasets();
|
||||||
workbook = workbook_new(getFileName().c_str());
|
workbook = workbook_new(getFileName().c_str());
|
||||||
createFormats();
|
createFormats();
|
||||||
setProperties("Datasets");
|
setProperties("Datasets");
|
||||||
|
@@ -11,6 +11,7 @@ namespace platform {
|
|||||||
DatasetsExcel();
|
DatasetsExcel();
|
||||||
~DatasetsExcel();
|
~DatasetsExcel();
|
||||||
void report(json& data);
|
void report(json& data);
|
||||||
|
std::string getExcelFileName() { return getFileName(); }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
@@ -1,8 +1,9 @@
|
|||||||
|
#include "common/Paths.h"
|
||||||
#include "ResultsDatasetExcel.h"
|
#include "ResultsDatasetExcel.h"
|
||||||
namespace platform {
|
namespace platform {
|
||||||
ResultsDatasetExcel::ResultsDatasetExcel()
|
ResultsDatasetExcel::ResultsDatasetExcel()
|
||||||
{
|
{
|
||||||
file_name = "some_results.xlsx";
|
file_name = Paths::excelResults();
|
||||||
workbook = workbook_new(getFileName().c_str());
|
workbook = workbook_new(getFileName().c_str());
|
||||||
createFormats();
|
createFormats();
|
||||||
setProperties("Results");
|
setProperties("Results");
|
||||||
|
@@ -12,6 +12,7 @@ namespace platform {
|
|||||||
ResultsDatasetExcel();
|
ResultsDatasetExcel();
|
||||||
~ResultsDatasetExcel();
|
~ResultsDatasetExcel();
|
||||||
void report(json& data);
|
void report(json& data);
|
||||||
|
std::string getExcelFileName() { return getFileName(); }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
Reference in New Issue
Block a user