From e437a33450e58a458a953a006d58fceac4737721 Mon Sep 17 00:00:00 2001 From: Naoko Reeves Date: Sat, 28 Nov 2015 21:03:47 -0700 Subject: [PATCH] format example rule dict properly --- .gitignore | 3 ++ README.md | 95 +++++++++++++++++++++++++++++++----------------------- 2 files changed, 57 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index 8898a0ae..4faf3d96 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,6 @@ nosetests.xml # Vim *.sw[po] + +# PyCharm +.idea/* diff --git a/README.md b/README.md index 3c896a07..ede97b07 100644 --- a/README.md +++ b/README.md @@ -105,49 +105,62 @@ Note that the JSON is expected to be auto-generated by a UI, which makes it simp An example of the resulting python lists/dicts is: ```python -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", +rules = 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, + }, + ] }, - { "name": "current_inventory", - "operator": "less_than", - "value": 20, - } - ]}, - }, - "actions": [ - { "name": "order_more", - "params":{"number_to_order": 40}, + "actions": [ + { + "name": "put_on_sale", + "params": {"sale_percentage": 0.25}, + }, + ] }, - ], -}] + + { + "conditions": { + # current_inventory < 5 OR (current_month = "December" AND current_inventory < 20) + "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}, + }, + ] + }, +] ``` ### Export the available variables, operators and actions