Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear Ruleset & c #379

Open
sabyasachi-basu-i opened this issue Jul 2, 2021 · 0 comments
Open

Clear Ruleset & c #379

sabyasachi-basu-i opened this issue Jul 2, 2021 · 0 comments

Comments

@sabyasachi-basu-i
Copy link

I built a basic flask app, to run the rules using API, the first issue I faced was when I was trying to run, the ruleset does not clear for every call. Resulting in an error. I saw #262 already open. Will await for an update on that.

The second problem I faced was while testing https://github.com/jruizgit/rules/blob/master/docs/py/reference.md#events
Let's say my first API call is to compare below two post:

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

After that I send another two post to test the same rule, example:

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

this will create problem, since in the condition:

 @when_all(c.first << m.t == 'purchase' , c.second << m.location != c.first.location)

c.first is still CA but since I made the second API call my expectation is the condition should assign c.first with US and c.second to US thereby (my custom rule - No Fraud detected)

My rule code is below for reference:

from durable.lang import *

def event(body):
    with ruleset('risk'):
        @when_all(c.first << m.t == 'purchase' , c.second << m.location != c.first.location)
        # this condition is to identify actual fraud cases
        def fraud(c):
            print('Fraud detected -> {0}, {1}'.format(c.first.location, c.second.location))
            c.s.result = ('Fraud detected -> {0}, {1}'.format(c.first.location, c.second.location))
        
        @when_all(c.first << m.t == 'purchase', c.second << m.location == c.first << m.location)
        # this condition is to identify No fraud cases
        def fraudno(c):
            print('No Fraud detected -> {0}, {1}'.format(c.first.location, c.second.location))
            c.s.result = ('No Fraud detected -> {0}, {1}'.format(c.first.location, c.second.location))

I maybe doing something wrong, since, I'm very new to this.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant