Add env to enable test data

This commit is contained in:
2024-04-19 10:02:59 +02:00
parent 018c94bfe6
commit 1caa39c071
10 changed files with 91 additions and 71 deletions

View File

@@ -6,37 +6,9 @@
#include <string>
#include <CPPFImdlp.h>
#include "Utils.h"
#include "SourceData.h"
namespace platform {
enum fileType_t { CSV, ARFF, RDATA };
class SourceData {
public:
SourceData(std::string source)
{
if (source == "Surcov") {
path = "datasets/";
fileType = CSV;
} else if (source == "Arff") {
path = "datasets/";
fileType = ARFF;
} else if (source == "Tanveer") {
path = "data/";
fileType = RDATA;
} else {
throw std::invalid_argument("Unknown source.");
}
}
std::string getPath()
{
return path;
}
fileType_t getFileType()
{
return fileType;
}
private:
std::string path;
fileType_t fileType;
};
class Dataset {
private:
std::string path;

View File

@@ -14,8 +14,15 @@ namespace platform {
private:
std::map<std::string, std::string> env;
public:
DotEnv()
DotEnv(bool create = false)
{
if (create) {
// For testing purposes
std::ofstream file(".env");
file << "source_data = Test" << std::endl;
file << "margin = 0.1" << std::endl;
file.close();
}
std::ifstream file(".env");
if (!file.is_open()) {
std::cerr << "File .env not found" << std::endl;
@@ -30,7 +37,7 @@ namespace platform {
std::istringstream iss(line);
std::string key, value;
if (std::getline(iss, key, '=') && std::getline(iss, value)) {
env[key] = value;
env[trim(key)] = trim(value);
}
}
}

View File

@@ -0,0 +1,38 @@
#ifndef SOURCEDATA_H
#define SOURCEDATA_H
namespace platform {
enum fileType_t { CSV, ARFF, RDATA };
class SourceData {
public:
SourceData(std::string source)
{
if (source == "Surcov") {
path = "datasets/";
fileType = CSV;
} else if (source == "Arff") {
path = "datasets/";
fileType = ARFF;
} else if (source == "Tanveer") {
path = "data/";
fileType = RDATA;
} else if (source == "Test") {
path = "@TEST_DATA_PATH@/";
fileType = ARFF;
} else {
throw std::invalid_argument("Unknown source.");
}
}
std::string getPath()
{
return path;
}
fileType_t getFileType()
{
return fileType;
}
private:
std::string path;
fileType_t fileType;
};
}
#endif

View File

@@ -69,6 +69,10 @@ namespace platform {
mark = 0.9995;
}
status = result < mark ? Symbols::cross : result > mark ? Symbols::upward_arrow : "=";
if (status == Symbols::cross) {
std::cout << "ZeroR mark: " << mark << " result=" << result << " dataset = " << dataset << std::endl;
exit(1);
}
}
}
}