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

syntax error in example in README? #50

Open
luofanghao opened this issue Feb 19, 2019 · 3 comments
Open

syntax error in example in README? #50

luofanghao opened this issue Feb 19, 2019 · 3 comments

Comments

@luofanghao
Copy link

luofanghao commented Feb 19, 2019

rules = [
# expiration_days < 5 AND current_inventory > 20
{ "conditions": { "all": [
      { "name": "expiration_days",
        "operator": "less_than",
        "value": 5,
      },
      { "name": "current_inventory",
        "operator": "greater_than",
        "value": 20,
      },
  ]},
  "actions": [
      { "name": "put_on_sale",
        "params": {"sale_percentage": 0.25},
      },
  ],
},

# current_inventory < 5 OR (current_month = "December" AND current_inventory < 20)
{ "conditions": { "any": [
      { "name": "current_inventory",
        "operator": "less_than",
        "value": 5,
      },
    ]},
      { "all": [
        {  "name": "current_month",
          "operator": "equal_to",
          "value": "December",
        },
        { "name": "current_inventory",
          "operator": "less_than",
          "value": 20,
        }
      ]},
  },
  "actions": [
    { "name": "order_more",
      "params":{"number_to_order": 40},
    },
  ],
}]

some syntax alert in the second conditions part. Should the all part be put under the any?

@prav1234567
Copy link

there are extra ',' in the json. try doing it. :P

@vishnu-dev
Copy link

vishnu-dev commented May 12, 2020

How do we fix this? I'm not able to figure out nested conditions. @dcosson

@bharat-Kundapur
Copy link

@luofanghao try this rule definition and let me know if it works.

[

{"conditions": {"all": [
    {"name": "expiration_days",
     "operator": "less_than",
     "value": 5
     },
    {"name": "current_inventory",
     "operator": "greater_than",
     "value": 20
     }
]},
    "actions": [
        {"name": "put_on_sale",
         "params": {"sale_percentage": 0.25}
         }
    ]
},


{"conditions": {"any": [
    {"name": "current_inventory",
     "operator": "less_than",
     "value": 5
     }
],
    "all": [
        {"name": "current_month",
         "operator": "equal_to",
         "value": "December"
         },
        {"name": "current_inventory",
         "operator": "less_than",
         "value": 20
         }
    ]}
},
{"actions": [
    {"name": "order_more",
     "params": {"number_to_order": 40}
     }
]
}]

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

4 participants