feat: add 3 boolean signal models
This commit is contained in:
parent
2ef663af81
commit
3ce03911c3
17
TestProject/RNG/model/BoolCsvModel.h
Normal file
17
TestProject/RNG/model/BoolCsvModel.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <TestProject/RNG/model/IModel.h>
|
||||||
|
#include <TestProject/RNG/read_csv.hpp>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <string>
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
struct BoolCsvModel : IModel {
|
||||||
|
ReadCSV::IntData data;
|
||||||
|
int column;
|
||||||
|
|
||||||
|
BoolCsvModel(const json& params, float)
|
||||||
|
: data(params["file"].get<std::string>())
|
||||||
|
, column(params["column"].get<int>()) {}
|
||||||
|
|
||||||
|
bool evaluateBool(size_t t) override { return (bool)data(t, column); }
|
||||||
|
};
|
||||||
14
TestProject/RNG/model/BoolRandomModel.h
Normal file
14
TestProject/RNG/model/BoolRandomModel.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <TestProject/RNG/model/IModel.h>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <cstdlib>
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
struct BoolRandomModel : IModel {
|
||||||
|
float prob_true;
|
||||||
|
BoolRandomModel(const json& params, float defaultVal)
|
||||||
|
: prob_true(params.value("prob_true", 0.5f)) {}
|
||||||
|
bool evaluateBool(size_t) override {
|
||||||
|
return (double)rand() / RAND_MAX < prob_true;
|
||||||
|
}
|
||||||
|
};
|
||||||
13
TestProject/RNG/model/BoolToggleModel.h
Normal file
13
TestProject/RNG/model/BoolToggleModel.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <TestProject/RNG/model/IModel.h>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
struct BoolToggleModel : IModel {
|
||||||
|
int period_ticks;
|
||||||
|
BoolToggleModel(const json& params, float)
|
||||||
|
: period_ticks(params.value("period_ms", 2000) / 20) {}
|
||||||
|
bool evaluateBool(size_t t) override {
|
||||||
|
return (t / period_ticks) % 2 == 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue
Block a user