I can think of another solution:
For every rule I can maintain a object which will contain the time stamp
value of last data points that have violated that rule. So in next
executions rule will only consider those objects which have greater
timestamp values then the last violated data point.
As sample,
rule "sample_rule"
when
$p4: DataObject(id == 4, stringValue == "230007014", $newTime4 :
timeStamp)
and ( not ProcessedObject(rule==
"sample_rule") or
( $po4: ProcessedObject(rule==
"sample_rule") and eval ( $newTime4.after(
$po4.getLatestTimestamp(4) ) ) )
)
and
$p14: DataObject(id == 14, stringValue == "230007004", $newTime14
: timeStamp)
and (not ProcessedObject(rule==
"sample_rule") or
( $po14: ProcessedObject(rule==
"sample_rule") and eval ( $newTime14.after(
$po14.getLatestTimestamp(14) )
) ) )
and
$p10: DataObject(id == 10, stringValue == "230007005", $newTime10
: timeStamp)
and (not ProcessedObject(rule==
"sample_rule") or
( $po10:
ProcessedObject(rule==
"sample_rule") and eval ( $newTime10.after(
$po14.getLatestTimestamp(10) )
) ) )
then
String ruleID = "sample_rule";
RuleOutput ruleOutput =
RuleEngineHelper.getRuleOutput(ruleSetOutput, ruleID);
ruleOutput.addDataObject($p4);
ruleOutput.addDataObject($p14);
ruleOutput.addDataObject($p10);
ProcessedObject po = ruleOutput.getProcessedObject();
insert(po);
end
[ Here ProcessedObject will have the timestamp of last data points that
has
violated that rule. There will be another rule which will ensure per rule
only one ProcessedObject exists in Working Memory. Not sure if I can avoid
the 2nd Rule. Please provide your suggestions]
Do you see any problem with this solution ? Any opportunity to further
tune
the rule mentioned above ? Feedback/Suggestions are welcome.
Sid,
I think, one can tune this rule a bit. If you think, that this is a good
solution at all to your problem, then you should split this rule into two
rules.
For each DataObject you have the same three lines: either there is a
ProcessedObject or not, then...
Make one rule where you check if there is such an object, and one rule for
having no such object.
Further you could think about creating specific getters in the
ProcessedObject for each of the DataObjects instead of giving a parameter
$po.getLatestTimestamp1(), $po.getLatestTimestamp2(), ...
Then you could bind these values to variables and you can avoid the eval
which costs only performance. Once you have bound timestamps you can
directly add a field constraint to pattern:
$p10 : DataObject(..., timestamp >= $ts10, ...)
This gives you readability and performance.
Alexander