Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitris-athanasiou committed Jun 12, 2018
1 parent ec1db1a commit 2181d41
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 31 deletions.
6 changes: 1 addition & 5 deletions include/model/CDetectionRule.h
Expand Up @@ -37,10 +37,6 @@ class MODEL_EXPORT CDetectionRule {
enum ERuleAction { E_SkipResult = 1, E_SkipModelUpdate = 2 };

public:
//! Default constructor.
//! The rule's action defaults to SKIP_RESULT.
CDetectionRule();

//! Set the rule's action.
void action(int ruleAction);

Expand Down Expand Up @@ -73,7 +69,7 @@ class MODEL_EXPORT CDetectionRule {
//! The rule action. It works as a bit mask so its value
//! may not match any of the declared enum values but the
//! corresponding bit will be 1 when an action is enabled.
int m_Action;
int m_Action{E_SkipResult};

//! The rule scope.
CRuleScope m_Scope;
Expand Down
2 changes: 1 addition & 1 deletion include/model/CRuleScope.h
Expand Up @@ -41,7 +41,7 @@ class MODEL_EXPORT CRuleScope {

public:
//! Default constructor.
CRuleScope();
CRuleScope() = default;

//! Adds a requirement for \p field to be in \p filter for the rule to apply
void include(std::string field, const core::CPatternSet& filter);
Expand Down
7 changes: 2 additions & 5 deletions lib/model/CDetectionRule.cc
Expand Up @@ -12,9 +12,6 @@
namespace ml {
namespace model {

CDetectionRule::CDetectionRule() : m_Action(E_SkipResult), m_Conditions() {
}

void CDetectionRule::action(int action) {
m_Action = action;
}
Expand Down Expand Up @@ -46,8 +43,8 @@ bool CDetectionRule::apply(ERuleAction action,
return false;
}

for (std::size_t i = 0; i < m_Conditions.size(); ++i) {
if (m_Conditions[i].test(model, feature, resultType, pid, cid, time) == false) {
for (const auto& condition : m_Conditions) {
if (condition.test(model, feature, resultType, pid, cid, time) == false) {
return false;
}
}
Expand Down
35 changes: 15 additions & 20 deletions lib/model/CRuleScope.cc
Expand Up @@ -14,21 +14,18 @@
namespace ml {
namespace model {

CRuleScope::CRuleScope() : m_Scope() {
}

void CRuleScope::include(std::string field, const core::CPatternSet& filter) {
m_Scope.push_back({field, TPatternSetCRef(filter), E_Include});
m_Scope.emplace_back(field, TPatternSetCRef(filter), E_Include);
}

void CRuleScope::exclude(std::string field, const core::CPatternSet& filter) {
m_Scope.push_back({field, TPatternSetCRef(filter), E_Exclude});
m_Scope.emplace_back(field, TPatternSetCRef(filter), E_Exclude);
}

bool CRuleScope::check(const CAnomalyDetectorModel& model, std::size_t pid, std::size_t cid) const {

const CDataGatherer& gatherer = model.dataGatherer();
for (auto& scopeField : m_Scope) {
for (const auto& scopeField : m_Scope) {
bool containsValue{false};
if (scopeField.first == gatherer.partitionFieldName()) {
containsValue = scopeField.second.get().contains(gatherer.partitionFieldValue());
Expand All @@ -51,21 +48,19 @@ bool CRuleScope::check(const CAnomalyDetectorModel& model, std::size_t pid, std:

std::string CRuleScope::print() const {
std::string result{""};
if (m_Scope.empty() == false) {
auto itr = m_Scope.begin();
while (itr != m_Scope.end()) {
result += "'" + itr->first + "'";
if (itr->third == E_Include) {
result += " IN ";
} else {
result += " NOT IN ";
}
result += "FILTER";
auto itr = m_Scope.begin();
while (itr != m_Scope.end()) {
result += "'" + itr->first + "'";
if (itr->third == E_Include) {
result += " IN ";
} else {
result += " NOT IN ";
}
result += "FILTER";

++itr;
if (itr != m_Scope.end()) {
result += " AND ";
}
++itr;
if (itr != m_Scope.end()) {
result += " AND ";
}
}
return result;
Expand Down

0 comments on commit 2181d41

Please sign in to comment.