syntax error in example in README?
luofanghao opened this issue · 3 comments
luofanghao commented
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 commented
there are extra ',' in the json. try doing it. :P
vishnu-dev commented
How do we fix this? I'm not able to figure out nested conditions. @dcosson
bharat-Kundapur commented
@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}
}
]
}]