Git Product home page Git Product logo

Comments (5)

Seraf avatar Seraf commented on September 24, 2024
{
  "name": "Rule Name",
  "order": 999,
  "conditions": [
                       [
                         {
                            "name": " Condition1 name",
                            "if": "plugin",
                            "operator": "=",
                            "compare": "chat"
                          },
                          {
                            "operator": "AND",
                          },
                          {
                            "name": " Condition2 name",
                            "if": "jsonData['zone']",
                            "operator": "=",
                            "compare": "2"
                          }
                       ],
                       [
                         {
                            "name": " Condition3 name",
                            "if": "plugin",
                            "operator": "=",
                            "compare": "chat"
                          },
                          {
                            "operator": "OR",
                          },
                          {
                            "name": " Condition4 name",
                            "if": "jsonData['zone']",
                            "operator": ">",
                            "compare": "2"
                           }
                        ]
                      ]
  "then": "python code",
  "end": True
}

from lisa.

Seraf avatar Seraf commented on September 24, 2024

Should work with something like this for the interface : http://www.youtube.com/watch?v=2VwHQUMu6fE

from lisa.

Seraf avatar Seraf commented on September 24, 2024

I will go without json document (only a string containing python code).
This will allow the user to code directly his rule in python.
I will need to parse the code to do a visual representation of the code. But can be implemented later.

from lisa.

joehakimrahme avatar joehakimrahme commented on September 24, 2024

Trying to understand the JSON example

The second example you give is ambiguous. The way I understand it is:

(Cond1 AND Cond 2) OR (Cond3 OR Cond4)

In this case the syntax would be a bit redundant. Do you need an explicit operator? Why not something like that?

    {
        "name": "Rule Name",
        "order": 999,
        "conditions": [
        [
            {
                "name": " Condition1 name",
                "if": "plugin",
                "operator": "=",
                "compare": "chat"
            },
            {
                "name": " Condition2 name",
                "if": "jsonData['zone']",
                "operator": "=",
                "compare": "2"
            }
        ],
        [
            {
                "name": " Condition3 name",
                "if": "plugin",
                "operator": "=",
                "compare": "chat"
            }
        ],
        [
            {
                "name": " Condition4 name",
                "if": "jsonData['zone']",
                "operator": ">",
                "compare": "2"
            }
        ]
        ]
        "then": "python code",
        "end": True
    }

This would represent the equivalent (OR is associative):

(Cond1 AND Cond2) OR Cond3 OR Cond4

A few remarks about it:

  • why would you feed the numerical "compare" values as strings ("2")?
  • I don't understand what the "end" property is about.

Beyond JSON

If you consider dropping the JSON representation for python, keep in mind the security implications this may have. Usually you don't want to give the user the ability to inject arbitrary code that will run through eval(). And it's not worth the hassle trying to sanitize your output manually.

That being said, if you persist on having the python representation, maybe you can provide examples we could work with for prototyping?

I didn't have much more time to look into it today, but I have an idea of a simple prototype of a rule engine. I'll show you some more tomorrow. However my number one advice is to keep parsing to a minimum; you have python libraries that are thoroughly tested to deal with common formats like JSON or CSV, take advantage of them. Parsing can be a bitch...

from lisa.

Seraf avatar Seraf commented on September 24, 2024

This issue is a little old and your comment too, sorry for not replying earlier. We discussed about it in real life so I put a little bit informations here before closing this issue.
I will go with python code. Yes the user will be able to inject his own python code, playing with a jsonInput or a jsonOutput document.
But as not everyone know python, I will go with this project : https://code.google.com/p/blockly/.
Each plugin will provide his own blocks adding to those shipped by default with LISA.
The goal is to generate python for simple rule in a graphical way, but let advanced user writting directly their own python code.
There's a lot of work to do on this part, but it will be great I think !

Anyway thanks a lot @RahMu for your help/advices.

from lisa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.