AstraLog-HPC
Loading...
Searching...
No Matches
StatefulRule Class Reference

A rule that requires a condition to be met for a specified number of consecutive measurements. More...

#include <Rules.hpp>

Inheritance diagram for StatefulRule:
Inheritance graph
Collaboration diagram for StatefulRule:
Collaboration graph

Public Member Functions

 StatefulRule (const RuleConfig &cfg)
 Constructs a StatefulRule from a configuration object.
 
std::string whoAmI () override
 Returns the rule type name.
 
int getConsecutive () const override
 Gets the number of consecutive measurements required for the rule to trigger.
 
void setConsecutive (int value) override
 Sets the number of consecutive measurements required for the rule to trigger.
 
int evaluate (const std::variant< double, std::string > &v) override
 Evaluates the sensor value and updates the consecutive match counter.
 
- Public Member Functions inherited from RuleStrategy
virtual double getLastValue ()
 
virtual void setLastValue (double)
 
virtual bool hasPrevious () const
 
virtual int evaluate (const ResultMap &results)
 Evaluates correlation rules based on the results of other primary rules.
 
virtual ~RuleStrategy ()=default
 Virtual destructor for safe polymorphic deletion.
 
const std::string & id () const
 Gets the unique identifier of the rule.
 
const std::string & priority () const
 Gets the priority level of the rule.
 

Private Attributes

std::string sensor_id
 The ID of the sensor this rule applies to.
 
std::string op
 The comparison operator.
 
double threshold
 The threshold value to compare against.
 
int consecutive
 The target number of consecutive condition matches required.
 
int current_consecutive = 0
 The current sequence length of consecutive matches.
 

Additional Inherited Members

- Static Protected Member Functions inherited from RuleStrategy
static bool compare (double left, double right, const std::string &op)
 A static helper function to perform logical comparisons.
 
- Protected Attributes inherited from RuleStrategy
std::string rule_id
 The unique identifier for this rule instance.
 
std::string rule_priority
 The execution priority of this rule.
 

Detailed Description

A rule that requires a condition to be met for a specified number of consecutive measurements.

Constructor & Destructor Documentation

◆ StatefulRule()

StatefulRule::StatefulRule ( const RuleConfig &  cfg)
inlineexplicit

Constructs a StatefulRule from a configuration object.

Parameters
cfgThe configuration containing consecutive_measurements along with standard rule parameters.

Member Function Documentation

◆ evaluate()

int StatefulRule::evaluate ( const std::variant< double, std::string > &  v)
inlineoverridevirtual

Evaluates the sensor value and updates the consecutive match counter.

Parameters
vA variant containing either a valid double reading or a string representing an error state.
Returns
int 1 if the consecutive count reaches the threshold, 0 otherwise.

Reimplemented from RuleStrategy.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getConsecutive()

int StatefulRule::getConsecutive ( ) const
inlineoverridevirtual

Gets the number of consecutive measurements required for the rule to trigger.

Reimplemented from RuleStrategy.

◆ setConsecutive()

void StatefulRule::setConsecutive ( int  value)
inlineoverridevirtual

Sets the number of consecutive measurements required for the rule to trigger.

Parameters
valueThe number of consecutive measurements to be set.

Reimplemented from RuleStrategy.

◆ whoAmI()

std::string StatefulRule::whoAmI ( )
inlineoverridevirtual

Returns the rule type name.

Returns
The string "StatefulRule".

Implements RuleStrategy.

Member Data Documentation

◆ consecutive

int StatefulRule::consecutive
private

The target number of consecutive condition matches required.

◆ current_consecutive

int StatefulRule::current_consecutive = 0
private

The current sequence length of consecutive matches.

◆ op

std::string StatefulRule::op
private

The comparison operator.

◆ sensor_id

std::string StatefulRule::sensor_id
private

The ID of the sensor this rule applies to.

◆ threshold

double StatefulRule::threshold
private

The threshold value to compare against.


The documentation for this class was generated from the following file: