10#include <unordered_map>
18using ResultMap = std::unordered_map<std::string, bool>;
37 [[nodiscard]]
virtual bool hasPrevious()
const {
return false; }
47 virtual int evaluate([[maybe_unused]]
const std::variant<double,std::string>& v) {
return 0; }
66 [[nodiscard]]
const std::string&
id()
const {
return rule_id; }
84 static bool compare(
double left,
double right,
const std::string& op) {
85 static const std::unordered_map<std::string, std::function<bool(
double,
double)>> ops = {
86 {
"<", std::less<>() },
87 {
">", std::greater<>() },
88 {
"<=", std::less_equal<>() },
89 {
">=", std::greater_equal<>() },
90 {
"==", std::equal_to<>() }
93 auto it = ops.find(op);
94 if (it != ops.end()) {
95 return it->second(left, right);
std::unordered_map< std::string, bool > ResultMap
Alias for a map containing the boolean evaluation results of rules, keyed by rule ID.
Definition Strategy.hpp:18
Abstract base class that defines the interface for all rule evaluation strategies.
Definition Strategy.hpp:25
virtual int getConsecutive() const
Definition Strategy.hpp:33
virtual bool hasPrevious() const
Definition Strategy.hpp:37
virtual int evaluate(const ResultMap &results)
Evaluates correlation rules based on the results of other primary rules.
Definition Strategy.hpp:55
virtual int evaluate(const std::variant< double, std::string > &v)
Evaluates the rule based on a sensor measurement or error state.
Definition Strategy.hpp:47
const std::string & priority() const
Gets the priority level of the rule.
Definition Strategy.hpp:72
virtual std::string whoAmI()=0
Returns the rule type name (e.g. "SimpleRule").
const std::string & id() const
Gets the unique identifier of the rule.
Definition Strategy.hpp:66
virtual void setConsecutive(int)
Definition Strategy.hpp:35
static bool compare(double left, double right, const std::string &op)
A static helper function to perform logical comparisons.
Definition Strategy.hpp:84
virtual void setLastValue(double)
Definition Strategy.hpp:36
virtual double getLastValue()
Definition Strategy.hpp:34
std::string rule_id
The unique identifier for this rule instance.
Definition Strategy.hpp:99
virtual ~RuleStrategy()=default
Virtual destructor for safe polymorphic deletion.
std::string rule_priority
The execution priority of this rule.
Definition Strategy.hpp:100
A configuration structure used to instantiate any type of RuleStrategy.
Definition Strategy.hpp:107
double value
The numerical threshold value used for comparisons.
Definition Strategy.hpp:113
std::string sensor_id
The ID of the sensor this rule applies to.
Definition Strategy.hpp:110
std::string op
The comparison operator used for standard rules (default: ">").
Definition Strategy.hpp:117
std::string priority
The execution priority level (default: "LOW").
Definition Strategy.hpp:112
std::string logic
The logical operator used for correlation rules (default: "AND").
Definition Strategy.hpp:118
std::string type
The type of the rule (e.g., "simple", "stateful", "correlation").
Definition Strategy.hpp:109
std::string rule_id
The unique identifier for the rule.
Definition Strategy.hpp:111
int consecutive_measurements
The required consecutive steps for stateful rules to trigger.
Definition Strategy.hpp:115
std::vector< std::string > conditions
A list of dependent rule IDs for correlation rules.
Definition Strategy.hpp:116