Python DSL用于建立商业智能规则,该规则可以在没有代码历史的情况下配置---1.0.1 SudioStayPosiy发布20163-16-修复了安装在某些平台上的1.0的包装错误。1.0.0+++2016年3月16日发布-删除规则装饰器上的缓存层

business-rules的Python项目详细描述


业务规则[构建状态](https://travis-ci.org/venmo/business-rules.svg?branch=master)(https://travis ci.org/venmo/business rules)


此业务规则引擎的目标是提供一个简单的
接口,允许任何人捕获定义系统行为的新规则和逻辑,以及在后端处理这些规则的方法。发现这是分析师定义
营销逻辑的一种有用方法,当某些客户或项目有资格享受
折扣时,或者在用户进入特定状态或经历
特定事件序列后自动发送电子邮件。

<;p align="center">;
<;img src="http://cdn.memegenerator.net/instances/400x/36514579.jpg"/>;
<;/p>;


定义变量集


变量表示系统中的值,通常是某些特定对象的值。您可以通过设置阈值条件来创建规则,以便在计算触发该条件的变量时采取某些操作。

然后动态设置条件和阈值。

例如:

`` python
类productvariables(basevariables):

def\uu init(self,产品:
self.product=product

@数值规则库存变量
定义当前库存(self):
返回自身。产品。当前库存变量

@数值规则库存变量(label='到期天数')
定义到期天数(self)
上一个订单=self.product.orders[-1]
返回(上一个订单.到期日期-datetime.date.today()).days

@string\u rule\u variable()
定义当前月份(self):
return datetime.datetime.now().strftime("%b")

@选择规则变量(options=products.top_holiday_items())
def与(self)
return products.related_products
````

2。定义一组操作

这些是触发条件时可以执行的操作。

例如:

`` python
类产品操作(baseactions):

def初始(self,产品:
self.product=product

@规则操作(params={"销售百分比":field_numeric})
def put_on_sale(self,销售百分比:
self.product.price=(1.0-销售百分比)*self.product.price
self.product.save()

@规则操作(params={"数字到订单":字段数字})
定义更多订单(self,数字顺序:
productOrder.objects.create(product_id=self.product.id,
quantity=number_to_order)
````

另一个-更详细-语法可用:

`` python
类productactions(baseactions):


def初始(self,product):
self.product=product

@规则操作(params=[{fieldtype':字段选择,
"名称":"库存状态",
'label':'stock state',
'options':[
{'label':'available','name':'available'},
{'label':'last items','name':'last'items'},
{'label':'缺货','name':'缺货'}
]])
def change_stock_state(self,stock_state):
self.product.stock_state=stock_state
self.product.save()
```

3.构建规则

y业务规则引擎。

请注意,json预计将由ui自动生成,这使得任何人都可以在不了解代码的情况下轻松设置和调整业务规则。可在[此处](https://github.com/venmo/business rules ui)找到用于在web上生成这些内容的javascript库。

"all":[
{"name":"过期天数",
"operator":"小于",
"value":5,
},
{"name":"当前库存",
"operator":"大于",
"value":20,
},
],
"actions":[
{"name":"put_on庠sale",
"params":{"sale庠percentage":0.25},
},
],
},


;current庠inventory<;5或(current庠month="december"和current庠inventory<;20)
{"条件":{"任意":[
{"名称":"当前库存"、
"运算符":"小于"、
"值":5、
}、
]}、
{"全部":[
{"名称":"当前月份"、
"运算符":"等于"、
"值":"十二月",
},
{"name":"当前库存",
"operator":"少于",
"value":20,
}
]},
},
"actions":[
{"name":"订单多于",
"params":{"订单数量":40},
},

],
}
```

productactions)
```



``python
{"variables":[
{"name":"expiration\u days",
"label":"days until expiration",
"field\u type":"numeric",
"options":[]},
"name":"current\u month",
"label":"current month",
"field\u type":"string",
"options":[]},
{"name":"goes\u well\u with",
"label":"goes well with",
"field\u type":"select",
"options":["eggnog","cookies","beef jerrey"]}

"actions":[
{"name":"put_on廑sale",
"label":"put on sale",
"params":{"sale廑percentage":"numeric"},
{"name":"order廑more",
"label":"order more",
"params":{"number廑to廑order":"numeric"}
],
"variable廑type廑operators":{
"数值":[{"名称":"等于",
"标签":"等于",
"输入类型":"数值"},
{"名称":"小于",
"标签":"小于",
"输入类型":"数值"},
{"名称":"大于"、
"标签":"大于"、
"输入类型":"数值"}、
"字符串":[{"名称":"等于"、
"标签":"等于"、
"输入类型":"文本"}、
{"名称":"非空"、
"label":"非空",
"inpu-type":"none"}




````



35 35 35 35 35 35 35










"inpu type"输入法"inpu"输入法"输入法"输入法"输入法"输入法"输入法"















>定义的变量=产品变量(Product),
定义的操作=产品操作(Product),
stop_on_first_trigger=true

`````

不同的类型,生成规则的前端需要知道哪些运算符可用。

所有装饰器都可以选择使用一个标签:
-`label`-在前端显示的可读标签。默认情况下,我们只是将变量名拆分为下划线并大写。

或python decimal。

`@数值规则`变量运算符:

*`等于`
*`大于`
*`小于`
*`大于`
*`或等于`
*`小于`

注意:要比较浮点等式,我们只需检查差值是否小于某个小值epsilon

**string**-python bytestring或unicode字符串。

`@string_rule_variable`运算符:

*`equal_to`
*`starts_with`
*`ends_with`
*`contains`
*`matches_regex`
*`non_empty`

**boolean**-true或false值。

`@boolean\u rule\u variable`运算符:

*`为真`
*`为假`

**select**-一组值,其中阈值为单个项。

`@select\u rule\u variable`运算符:

*`包含`
*`不包含`

**select\u multiple**-一组值的值,其中阈值将是一组项的值。


>`@选择多个规则变量的运算符:


*`包含所有`
*`被`
>*`包含在`
>*`至少一个元素的共享`
*`完全一个元素的共享`
>






返回数据的数据返回返回数据。是的向您的客户




设置开发环境(假设您使用的是[virtualenvwrapper](http://docs.python guide.org/en/latest/dev/virtualenvs/virtualenvwrapper)):

`` bash
$mkvirtualenv业务规则
$pip install-r dev requirements.txt
$noests
````

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java与Groovy正则表达式匹配混淆   java控制台未定义为JSNI   主目录中的java指针异常   java如何获取hashmap中的arrayList的大小   ApachePOI用于文本,Java代码中的word doc(.docx)中没有进行追加   Ruby对象到Java对象   JavaSpringJPA哈希集只返回一个值   Java在执行由配置了精确类路径参数的mavenjarpluin生成的可执行jar时无法找到依赖项   java我试图在画布上写一个文本,但什么也没发生   java HTTP 404源服务器找不到目标资源的当前表示形式,或者不愿意透露存在该表示形式。不起作用   java提取小数点后的最后一个数字   oop Java:无法访问对象的元素   PHP URL中RecyclerView中的java句柄空异常   不调用OnCreateViewHolder的java Update RecyclerView适配器项