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

A rule that triggers based on the difference between the current and the previous measurement. More...

#include <Rules.hpp>

Inheritance diagram for StepDifferenceRule:
Inheritance graph
Collaboration diagram for StepDifferenceRule:
Collaboration graph

Public Member Functions

 StepDifferenceRule (const RuleConfig &cfg)
 Constructs a StepDifferenceRule from a configuration object.
 
std::string whoAmI () override
 Returns the rule type name.
 
int evaluate (const std::variant< double, std::string > &v) override
 Evaluates the difference between the current sensor value and the previous one.
 
double getLastValue () override
 Gets the last value stored by the rule, which is used for the step difference calculation.
 
void setLastValue (double value) override
 Sets the last value stored by the rule, which is used for the step difference calculation.
 
bool hasPrevious () const override
 Checks if a valid previous measurement exists for the step difference calculation.
 
- Public Member Functions inherited from RuleStrategy
virtual int getConsecutive () const
 
virtual void setConsecutive (int)
 
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 step difference value to compare against.
 
double last_value = 0.0
 The stored value from the previous measurement.
 
bool has_previous = false
 Flag indicating if a valid previous measurement exists.
 

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 triggers based on the difference between the current and the previous measurement.

Constructor & Destructor Documentation

◆ StepDifferenceRule()

StepDifferenceRule::StepDifferenceRule ( const RuleConfig &  cfg)
inlineexplicit

Constructs a StepDifferenceRule from a configuration object.

Parameters
cfgThe configuration containing sensor_id, operator (op), threshold (value), rule_id, and priority.

Member Function Documentation

◆ evaluate()

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

Evaluates the difference between the current sensor value and the previous one.

Parameters
vA variant containing either a valid double reading or a string representing an error state. If an error state is received, the internal state (previous value tracking) is reset.
Returns
int 1 if the step difference threshold is overcome, 0 otherwise.

Reimplemented from RuleStrategy.

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

◆ getLastValue()

double StepDifferenceRule::getLastValue ( )
inlineoverridevirtual

Gets the last value stored by the rule, which is used for the step difference calculation.

Reimplemented from RuleStrategy.

◆ hasPrevious()

bool StepDifferenceRule::hasPrevious ( ) const
inlineoverridevirtual

Checks if a valid previous measurement exists for the step difference calculation.

Returns
true if a previous measurement is available, false otherwise.

Reimplemented from RuleStrategy.

◆ setLastValue()

void StepDifferenceRule::setLastValue ( double  value)
inlineoverridevirtual

Sets the last value stored by the rule, which is used for the step difference calculation.

Parameters
valueThe value to be stored as the last measurement.

Reimplemented from RuleStrategy.

◆ whoAmI()

std::string StepDifferenceRule::whoAmI ( )
inlineoverridevirtual

Returns the rule type name.

Returns
The string "StepDifferenceRule".

Implements RuleStrategy.

Member Data Documentation

◆ has_previous

bool StepDifferenceRule::has_previous = false
private

Flag indicating if a valid previous measurement exists.

◆ last_value

double StepDifferenceRule::last_value = 0.0
private

The stored value from the previous measurement.

◆ op

std::string StepDifferenceRule::op
private

The comparison operator.

◆ sensor_id

std::string StepDifferenceRule::sensor_id
private

The ID of the sensor this rule applies to.

◆ threshold

double StepDifferenceRule::threshold
private

The threshold step difference value to compare against.


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