Split Result from Results
This commit is contained in:
parent
7bfafe555f
commit
c4d0a5b4e6
@ -1,9 +1,8 @@
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include "platformUtils.h"
|
||||
#include "BestResults.h"
|
||||
#include "Results.h"
|
||||
#include "Result.h"
|
||||
#include "Colors.h"
|
||||
|
||||
namespace platform {
|
||||
@ -33,7 +32,8 @@ namespace platform {
|
||||
}
|
||||
}
|
||||
string bestFileName = path + "/" + bestResultFile();
|
||||
if (file_exists(bestFileName)) {
|
||||
if (FILE* fileTest = fopen(bestFileName.c_str(), "r")) {
|
||||
fclose(fileTest);
|
||||
cout << Colors::MAGENTA() << "File " << bestFileName << " already exists and it shall be overwritten." << Colors::RESET();
|
||||
}
|
||||
ofstream file(bestFileName);
|
||||
|
@ -6,15 +6,14 @@ include_directories(${BayesNet_SOURCE_DIR}/lib/argparse/include)
|
||||
include_directories(${BayesNet_SOURCE_DIR}/lib/json/include)
|
||||
include_directories(${BayesNet_SOURCE_DIR}/lib/libxlsxwriter/include)
|
||||
add_executable(main main.cc Folding.cc platformUtils.cc Experiment.cc Datasets.cc Models.cc ReportConsole.cc ReportBase.cc)
|
||||
add_executable(manage manage.cc Results.cc ReportConsole.cc ReportExcel.cc ReportBase.cc Datasets.cc platformUtils.cc)
|
||||
add_executable(manage manage.cc Results.cc Result.cc ReportConsole.cc ReportExcel.cc ReportBase.cc Datasets.cc platformUtils.cc)
|
||||
add_executable(list list.cc platformUtils Datasets.cc)
|
||||
add_executable(best best.cc BestResults.cc Results.cc ReportBase.cc ReportExcel.cc platformUtils.cc)
|
||||
add_executable(best best.cc BestResults.cc Result.cc)
|
||||
target_link_libraries(main BayesNet ArffFiles mdlp "${TORCH_LIBRARIES}")
|
||||
if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
|
||||
target_link_libraries(manage "${TORCH_LIBRARIES}" libxlsxwriter.so ArffFiles mdlp stdc++fs)
|
||||
target_link_libraries(best "${TORCH_LIBRARIES}" libxlsxwriter.so stdc++fs)
|
||||
target_link_libraries(best stdc++fs)
|
||||
else()
|
||||
target_link_libraries(manage "${TORCH_LIBRARIES}" "${XLSXWRITER_LIB}" ArffFiles mdlp)
|
||||
target_link_libraries(best "${TORCH_LIBRARIES}" "${XLSXWRITER_LIB}")
|
||||
endif()
|
||||
target_link_libraries(list ArffFiles mdlp "${TORCH_LIBRARIES}")
|
50
src/Platform/Result.cc
Normal file
50
src/Platform/Result.cc
Normal file
@ -0,0 +1,50 @@
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include "Result.h"
|
||||
#include "Colors.h"
|
||||
#include "BestScore.h"
|
||||
namespace platform {
|
||||
Result::Result(const string& path, const string& filename)
|
||||
: path(path)
|
||||
, filename(filename)
|
||||
{
|
||||
auto data = load();
|
||||
date = data["date"];
|
||||
score = 0;
|
||||
for (const auto& result : data["results"]) {
|
||||
score += result["score"].get<double>();
|
||||
}
|
||||
scoreName = data["score_name"];
|
||||
if (scoreName == BestScore::scoreName()) {
|
||||
score /= BestScore::score();
|
||||
}
|
||||
title = data["title"];
|
||||
duration = data["duration"];
|
||||
model = data["model"];
|
||||
complete = data["results"].size() > 1;
|
||||
}
|
||||
|
||||
json Result::load() const
|
||||
{
|
||||
ifstream resultData(path + "/" + filename);
|
||||
if (resultData.is_open()) {
|
||||
json data = json::parse(resultData);
|
||||
return data;
|
||||
}
|
||||
throw invalid_argument("Unable to open result file. [" + path + "/" + filename + "]");
|
||||
}
|
||||
|
||||
string Result::to_string() const
|
||||
{
|
||||
stringstream oss;
|
||||
oss << date << " ";
|
||||
oss << setw(12) << left << model << " ";
|
||||
oss << setw(11) << left << scoreName << " ";
|
||||
oss << right << setw(11) << setprecision(7) << fixed << score << " ";
|
||||
auto completeString = isComplete() ? "C" : "P";
|
||||
oss << setw(1) << " " << completeString << " ";
|
||||
oss << setw(9) << setprecision(3) << fixed << duration << " ";
|
||||
oss << setw(50) << left << title << " ";
|
||||
return oss.str();
|
||||
}
|
||||
}
|
37
src/Platform/Result.h
Normal file
37
src/Platform/Result.h
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef RESULT_H
|
||||
#define RESULT_H
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <nlohmann/json.hpp>
|
||||
namespace platform {
|
||||
using namespace std;
|
||||
using json = nlohmann::json;
|
||||
|
||||
class Result {
|
||||
public:
|
||||
Result(const string& path, const string& filename);
|
||||
json load() const;
|
||||
string to_string() const;
|
||||
string getFilename() const { return filename; };
|
||||
string getDate() const { return date; };
|
||||
double getScore() const { return score; };
|
||||
string getTitle() const { return title; };
|
||||
double getDuration() const { return duration; };
|
||||
string getModel() const { return model; };
|
||||
string getScoreName() const { return scoreName; };
|
||||
bool isComplete() const { return complete; };
|
||||
private:
|
||||
string path;
|
||||
string filename;
|
||||
string date;
|
||||
double score;
|
||||
string title;
|
||||
double duration;
|
||||
string model;
|
||||
string scoreName;
|
||||
bool complete;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
@ -6,34 +6,6 @@
|
||||
#include "BestScore.h"
|
||||
#include "Colors.h"
|
||||
namespace platform {
|
||||
Result::Result(const string& path, const string& filename)
|
||||
: path(path)
|
||||
, filename(filename)
|
||||
{
|
||||
auto data = load();
|
||||
date = data["date"];
|
||||
score = 0;
|
||||
for (const auto& result : data["results"]) {
|
||||
score += result["score"].get<double>();
|
||||
}
|
||||
scoreName = data["score_name"];
|
||||
if (scoreName == BestScore::scoreName()) {
|
||||
score /= BestScore::score();
|
||||
}
|
||||
title = data["title"];
|
||||
duration = data["duration"];
|
||||
model = data["model"];
|
||||
complete = data["results"].size() > 1;
|
||||
}
|
||||
json Result::load() const
|
||||
{
|
||||
ifstream resultData(path + "/" + filename);
|
||||
if (resultData.is_open()) {
|
||||
json data = json::parse(resultData);
|
||||
return data;
|
||||
}
|
||||
throw invalid_argument("Unable to open result file. [" + path + "/" + filename + "]");
|
||||
}
|
||||
void Results::load()
|
||||
{
|
||||
using std::filesystem::directory_iterator;
|
||||
@ -52,19 +24,6 @@ namespace platform {
|
||||
max = files.size();
|
||||
}
|
||||
}
|
||||
string Result::to_string() const
|
||||
{
|
||||
stringstream oss;
|
||||
oss << date << " ";
|
||||
oss << setw(12) << left << model << " ";
|
||||
oss << setw(11) << left << scoreName << " ";
|
||||
oss << right << setw(11) << setprecision(7) << fixed << score << " ";
|
||||
auto completeString = isComplete() ? "C" : "P";
|
||||
oss << setw(1) << " " << completeString << " ";
|
||||
oss << setw(9) << setprecision(3) << fixed << duration << " ";
|
||||
oss << setw(50) << left << title << " ";
|
||||
return oss.str();
|
||||
}
|
||||
void Results::show() const
|
||||
{
|
||||
cout << Colors::GREEN() << "Results found: " << files.size() << endl;
|
||||
|
@ -5,34 +5,11 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "Result.h"
|
||||
namespace platform {
|
||||
using namespace std;
|
||||
using json = nlohmann::json;
|
||||
|
||||
class Result {
|
||||
public:
|
||||
Result(const string& path, const string& filename);
|
||||
json load() const;
|
||||
string to_string() const;
|
||||
string getFilename() const { return filename; };
|
||||
string getDate() const { return date; };
|
||||
double getScore() const { return score; };
|
||||
string getTitle() const { return title; };
|
||||
double getDuration() const { return duration; };
|
||||
string getModel() const { return model; };
|
||||
string getScoreName() const { return scoreName; };
|
||||
bool isComplete() const { return complete; };
|
||||
private:
|
||||
string path;
|
||||
string filename;
|
||||
string date;
|
||||
double score;
|
||||
string title;
|
||||
double duration;
|
||||
string model;
|
||||
string scoreName;
|
||||
bool complete;
|
||||
};
|
||||
class Results {
|
||||
public:
|
||||
Results(const string& path, const int max, const string& model, const string& score, bool complete, bool partial, bool compare) :
|
||||
|
Loading…
Reference in New Issue
Block a user