rules icon indicating copy to clipboard operation
rules copied to clipboard

Question: Understanding Events

Open RG-arulprashanth opened this issue 4 years ago • 4 comments

Based on my understanding two events satisfying the condition are retracted once triggered. Can the second event be used (as first) to validate the third and so on?

RG-arulprashanth avatar Mar 26 '20 08:03 RG-arulprashanth

Hi, thanks for asking the question. Do you have an example of what you have in mind?

jruizgit avatar Mar 30 '20 04:03 jruizgit

Using the rules from the documentation here,

with ruleset('risk'): @when_all(c.first << m.t == 'purchase', c.second << m.location != c.first.location) # the event pair will only be observed once def fraud(c): print('Fraud detected -> {0}, {1}'.format(c.first.location, c.second.location))

post('risk', {'t': 'purchase', 'location': 'US'})
post('risk', {'t': 'purchase', 'location': 'CA'})
post('risk', {'t': 'purchase', 'location': 'UK'})

Upon execution, the rule is triggered once when an anomaly is detected from US -> CA but then my expectation/usecase is that the same anomaly be detected when the 3rd event is posted CA - UK without me adding a new condition like c.third.

Also I see a discrepancies in reference to the documentation https://github.com/jruizgit/rules/blob/master/docs/py/reference.md#events, the actual output I get when I run the defined example is

Fraud detected -> CA, US

and not

Fraud detected -> US, CA Fraud detected -> CA, US

Further am not sure if this statement is correct "In the example both facts satisfy the first condition m.t == 'purchase' and each fact satisfies the second condition m.location != c.first.location in relation to the facts which satisfied the first."

Based on my observation its not necessary for the second event to satisfy the first condition, even if second event is post('risk', {'t': 'declined', 'location': 'CA'}) which doesn't satisfy the first condition, the event will be triggered just because the second condition matches the second event.

Am using python3 and durable-rules==2.0.19 for my testing

RG-arulprashanth avatar Mar 30 '20 05:03 RG-arulprashanth

@jruizgit were you able to review this

RG-arulprashanth avatar Apr 14 '20 04:04 RG-arulprashanth

Hi, thanks for asking the question. Do you have an example of what you have in mind?

it is a bug?dear sir ,are you still on earth?

introspection3 avatar Feb 14 '21 13:02 introspection3