Skip to content

Commit be4a0f0

Browse files
committed
docs: update value sharing
Signed-off-by: develop-cs <43383361+develop-cs@users.noreply.github.com>
1 parent 673610f commit be4a0f0

File tree

4 files changed

+56
-27
lines changed

4 files changed

+56
-27
lines changed

docs/pages/a_simple_example.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ An **action** is triggered when the conditions are verified (i.e., `True`).
106106
**Actions** are defined by the following *keys* in the previous YAML file:
107107

108108
```yaml
109-
action: set_admission # (1)
110-
action_parameters: # (2)
109+
action: set_admission # (1)!
110+
action_parameters: # (2)!
111111
value: true
112112
```
113113

@@ -201,11 +201,11 @@ Now, let's apply the **rules** on a single applicant:
201201
```python
202202
from arta import RulesEngine
203203
204-
eng = RulesEngine(config_path="/to/my/config/dir") # (1)
204+
eng = RulesEngine(config_path="/to/my/config/dir") # (1)!
205205
206206
result = eng.apply_rules(input_data=applicants[0])
207207
208-
print(result) # (2)
208+
print(result) # (2)!
209209
# {
210210
# "admission": {"is_admitted": True},
211211
# "course": {"course_id": "senior"},

docs/pages/home.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,19 @@
1212

1313
Want to discover what is **Arta**? :arrow_right: [Get Started](a_simple_example.md)
1414

15-
1615
Want to know how to use it? :arrow_right: [User Guide](how_to.md)
1716

18-
1917
!!! info inline "New feature"
2018

21-
Use **Arta** as a *process execution engine* :zap:
22-
23-
Read [this page](rule_activation_mode.md) for more details.
19+
Use [value sharing](value_sharing.md) to customize actions and conditions :tools:
2420

2521
!!! tip "Releases"
2622

2723
Check the [Release notes](https://github.com/MAIF/arta/releases) :rocket:
2824

29-
!!! warning "Pydantic 1 compatibility is deprecated"
25+
!!! warning "Pydantic v1"
3026

31-
**Arta** is working with [Pydantic 2](https://docs.pydantic.dev/latest/) and Pydantic 1 but compatibility with V1 will be removed in the next **major** release.
27+
Compatibility with *Pydantic v1* will be removed in next **major** release.
3228

3329
**Arta** is working and automatically tested with:
3430

docs/pages/how_to.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ rules:
4343
value: KO
4444

4545
actions_source_modules:
46-
- my_folder.actions # (1)
46+
- my_folder.actions # (1)!
4747
```
4848
4949
1. Contains *action function* implementations, no need of the key `conditions_source_modules` here.
@@ -112,10 +112,10 @@ Create a YAML file and define your rules like this:
112112
```yaml hl_lines="6 16-26"
113113
---
114114
rules:
115-
default_rule_set: # (1)
115+
default_rule_set: # (1)!
116116
check_admission:
117117
ADMITTED_RULE:
118-
condition: HAS_SCHOOL_AUTHORIZED_POWER # (2)
118+
condition: HAS_SCHOOL_AUTHORIZED_POWER # (2)!
119119
action: set_admission
120120
action_parameters:
121121
value: true
@@ -125,16 +125,16 @@ rules:
125125
action_parameters:
126126
value: false
127127
128-
conditions: # (3)
128+
conditions: # (3)!
129129
HAS_SCHOOL_AUTHORIZED_POWER:
130130
description: "Does applicant have a school authorized power?"
131131
validation_function: has_authorized_super_power
132132
condition_parameters:
133133
power: input.super_power
134134
135-
conditions_source_modules: # (4)
135+
conditions_source_modules: # (4)!
136136
- my_folder.conditions
137-
actions_source_modules: # (5)
137+
actions_source_modules: # (5)!
138138
- my_folder.actions
139139
```
140140

@@ -289,9 +289,9 @@ A **rule set** is composed of **rule groups** which are themselves composed of *
289289
```yaml
290290
---
291291
rules:
292-
default_rule_set: # (1)
293-
check_admission: # (2)
294-
ADMITTED_RULE: # (3)
292+
default_rule_set: # (1)!
293+
check_admission: # (2)!
294+
ADMITTED_RULE: # (3)!
295295
condition: HAS_SCHOOL_AUTHORIZED_POWER
296296
action: set_admission
297297
action_parameters:

docs/pages/value_sharing.md

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
!!! note
1+
!!! info
22

3-
Only available with `arta>=0.10.0`.
3+
Needs `arta>=0.10.0`.
44

5+
## Between conditions and actions
56

67
It is possible to share some informations between **condition** and **action** implementations.
78

@@ -22,12 +23,12 @@ In the following example, a **condition** is computing the *median* of some *inp
2223
def is_median_above(
2324
values: list[float],
2425
limit: float,
25-
**kwargs: Any, # (1)
26+
**kwargs: Any, # (1)!
2627
) -> bool:
2728
"""Check if the median of some values is above limit."""
2829
median = statistics.median(values)
2930
# Store the value for later use by an action function
30-
kwargs["input_data"]["median"] = median # (2)
31+
kwargs["input_data"]["median"] = median # (2)!
3132
kwargs["input_data"]["median_limit"] = limit
3233
return median > limit
3334
```
@@ -39,13 +40,45 @@ def is_median_above(
3940
**Get the value (in an action for example):**
4041

4142
```python hl_lines="1 4"
42-
def alert_on_median(**kwargs: Any) -> str: # (1)
43+
def alert_on_median(**kwargs: Any) -> str: # (1)!
4344
"""Alert: "Median is too high: 13, limit is: 10."""
4445
return (
45-
f"Median is too high: {kwargs['input_data']['median']}, " # (2)
46+
f"Median is too high: {kwargs['input_data']['median']}, " # (2)!
4647
f"limit is: {kwargs['input_data']['median_limit']}."
4748
)
4849
```
4950

5051
1. Add the ****kwargs** parameter.
51-
2. Get the value.
52+
2. Get the value.
53+
54+
## User extra arguments
55+
56+
The following code shows how to set custom **user extra arguments** (e.g., `add_details`) within the `.apply_rules()` method:
57+
58+
```python hl_lines="5"
59+
from arta import RulesEngine
60+
61+
eng = RulesEngine(config_path="/to/my/config/dir")
62+
63+
result = eng.apply_rules(input_data={...}, add_details=True)
64+
```
65+
66+
Used inside **action** and/or **condition functions**:
67+
68+
```python hl_lines="4"
69+
def my_action(**kwargs: Any) -> str: # (1)!
70+
"""A simple action function."""
71+
72+
if kwargs["add_details"]: # (2)!
73+
action_result = (
74+
f"Median is too high: {kwargs['input_data']['median']}, "
75+
f"limit is: {kwargs['input_data']['median_limit']}."
76+
)
77+
else:
78+
action_result = "Median is too high."
79+
80+
return action_result
81+
```
82+
83+
1. Don't forget to add the ****kwargs** parameter.
84+
2. Straight use of the corresponding extra argument.

0 commit comments

Comments
 (0)