Skip to content

Commit

Permalink
Add readme description
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielguarisa committed Feb 15, 2023
1 parent 715acec commit 88c9110
Show file tree
Hide file tree
Showing 3 changed files with 355 additions and 3 deletions.
62 changes: 59 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p align="center">
<a href="https://github.com/gabrielguarisa/brdata"><img src="https://raw.githubusercontent.com/gabrielguarisa/retrack/main/logo.png" alt="brdata"></a>
<a href="https://github.com/gabrielguarisa/retrack"><img src="https://raw.githubusercontent.com/gabrielguarisa/retrack/main/logo.png" alt="retrack"></a>
</p>
<p align="center">
<em>A business rules engine</em>
Expand All @@ -9,5 +9,61 @@

[![Package version](https://img.shields.io/pypi/v/retrack?color=%2334D058&label=pypi%20package)](https://pypi.org/project/retrack/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Semantic Versions](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--versions-e10079.svg)](https://github.com/gabrielguarisa/brdata/releases)
[![License](https://img.shields.io/github/license/gabrielguarisa/brdata)](https://github.com/gabrielguarisa/brdata/blob/main/LICENSE)
[![Semantic Versions](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--versions-e10079.svg)](https://github.com/gabrielguarisa/retrack/releases)
[![License](https://img.shields.io/github/license/gabrielguarisa/retrack)](https://github.com/gabrielguarisa/retrack/blob/main/LICENSE)

</div>


## Installation

```bash
pip install retrack
```

## Usage

```python
from retack.engine.parser import Parser
from retack.engine.runner import Runner

# Parse the rule/model
parser = Parser(rule)

# Create a runner
runner = Runner(parser)

# Run the rule/model passing the data
runner(data)
```

### Creating a rule/model

A rule is a set of conditions and actions that are executed when the conditions are met. The conditions are evaluated using the data passed to the runner. The actions are executed when the conditions are met.

Each rule is composed of many nodes. To see each node type, check the [nodes](https://github.com/gabrielguarisa/retrack/tree/main/retrack/nodes) folder. To see some examples, check the [examples](https://github.com/gabrielguarisa/retrack/tree/main/examples) folder.

To create a rule, you need to create a JSON file with the following structure:

```json
{
"nodes": {
"node id": {
"id": "node id",
"data": {},
"inputs": {},
"outputs": {},
"name": "node name",
},
... more nodes
}
}
```

The `nodes` key is a dictionary of nodes. Each node has the following properties:

- `id`: The node id. This is used to reference the node in the `inputs` and `outputs` properties.
- `data`: The node data. This is used as a metadata for the node.
- `inputs`: The node inputs. This is used to reference the node inputs.
- `outputs`: The node outputs. This is used to reference the node outputs.
- `name`: The node name. This is used to define the node type.
296 changes: 296 additions & 0 deletions examples/age-check.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,296 @@
{
"id": "demo@0.1.0",
"nodes": {
"0": {
"id": 0,
"data": {},
"inputs": {},
"outputs": {
"output_up_void": {
"connections": [
{
"node": 2,
"input": "input_void",
"data": {}
}
]
},
"output_down_void": {
"connections": [
{
"node": 3,
"input": "input_void",
"data": {}
}
]
}
},
"position": [
-570.16015625,
-16.7578125
],
"name": "Start"
},
"2": {
"id": 2,
"data": {
"name": "age",
"default": null
},
"inputs": {
"input_void": {
"connections": [
{
"node": 0,
"output": "output_up_void",
"data": {}
}
]
}
},
"outputs": {
"output_value": {
"connections": [
{
"node": 4,
"input": "input_value_0",
"data": {}
}
]
}
},
"position": [
-262.082231911288,
-229.52363816128795
],
"name": "Input"
},
"3": {
"id": 3,
"data": {
"value": "18"
},
"inputs": {
"input_void": {
"connections": [
{
"node": 0,
"output": "output_down_void",
"data": {}
}
]
}
},
"outputs": {
"output_value": {
"connections": [
{
"node": 4,
"input": "input_value_1",
"data": {}
}
]
}
},
"position": [
-266.79444352384587,
85.59488398537597
],
"name": "Constant"
},
"4": {
"id": 4,
"data": {
"operator": ">="
},
"inputs": {
"input_value_0": {
"connections": [
{
"node": 2,
"output": "output_value",
"data": {}
}
]
},
"input_value_1": {
"connections": [
{
"node": 3,
"output": "output_value",
"data": {}
}
]
}
},
"outputs": {
"output_bool": {
"connections": [
{
"node": 6,
"input": "input_bool",
"data": {}
}
]
}
},
"position": [
83.84765625,
-146.80078125
],
"name": "Check"
},
"6": {
"id": 6,
"data": {},
"inputs": {
"input_bool": {
"connections": [
{
"node": 4,
"output": "output_bool",
"data": {}
}
]
}
},
"outputs": {
"output_then_filter": {
"connections": [
{
"node": 9,
"input": "input_void",
"data": {}
}
]
},
"output_else_filter": {
"connections": [
{
"node": 8,
"input": "input_void",
"data": {}
}
]
}
},
"position": [
387.98276806872417,
-127.24641593097007
],
"name": "If"
},
"7": {
"id": 7,
"data": {
"message": "invalid age"
},
"inputs": {
"input_bool": {
"connections": [
{
"node": 8,
"output": "output_bool",
"data": {}
}
]
}
},
"outputs": {},
"position": [
972.3247551810931,
-8.462733235746624
],
"name": "BoolOutput"
},
"8": {
"id": 8,
"data": {
"value": null
},
"inputs": {
"input_void": {
"connections": [
{
"node": 6,
"output": "output_else_filter",
"data": {}
}
]
}
},
"outputs": {
"output_bool": {
"connections": [
{
"node": 7,
"input": "input_bool",
"data": {}
}
]
}
},
"position": [
696.7790861556878,
-16.077469330043932
],
"name": "Bool"
},
"9": {
"id": 9,
"data": {
"value": true
},
"inputs": {
"input_void": {
"connections": [
{
"node": 6,
"output": "output_then_filter",
"data": {}
}
]
}
},
"outputs": {
"output_bool": {
"connections": [
{
"node": 10,
"input": "input_bool",
"data": {}
}
]
}
},
"position": [
693.7214037048345,
-194.67415220412568
],
"name": "Bool"
},
"10": {
"id": 10,
"data": {
"message": "valid age"
},
"inputs": {
"input_bool": {
"connections": [
{
"node": 9,
"output": "output_bool",
"data": {}
}
]
}
},
"outputs": {},
"position": [
974.0269089794663,
-190.8242802623253
],
"name": "BoolOutput"
}
}
}
Binary file modified logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 88c9110

Please sign in to comment.