ObjDecisionSwitchEdit extends ObjDecisionSwitch to provide YAML export,
simulation execution, and CRUD functionality for decision tree configurations.
Decision trees define branching logic used by the workflow engine to route
execution based on SQL-evaluated conditions.
This module handles all simulation and management operations while
ObjDecisionSwitch retains only the core evaluation logic (read,
evaluate, compute_decision).
Exported files are written to local.documents/decision_trees/ (path from
DecisionSwitchConstants.PATH_DECISION_TREES).
ObjDecisionSwitch.ObjDecisionSwitch
-> ObjDecisionSwitchEdit.ObjDecisionSwitchEdit <- this module
| Table | Purpose |
|---|---|
def_decision_tree |
One row per DecisionName/Package |
def_decision_treenodes |
One row per node/condition |
bloom_sim_{name} |
Simulation output results |
The simulate() method reads input data from the decision tree's configured
DataTable, applies the decision logic to each record, and stores results in
bloom_sim_{decision_name}. Supports both single-process and multiprocessing
modes.
Multiprocessing uses _init_worker_process() to create per-process database
connections and _simulation_worker() to execute each record in isolation.
def_decision_treeDataTable (with optional SetGuid filter)bloom_sim_{decision_name} is created or updatedcompute_decision() (single or multi-process)Package is stripped from both the tree and all nodes.DecisionName is stripped from nodes (redundant).decision_tree key.snake_case.|).decision_tree:
decision_name: CreditScoring
description: Score-based credit routing
active: 'Y'
nodes:
- guid: abc-123
rank: 1
condition_sql: |
SELECT CASE WHEN score > 700 THEN 1 ELSE 0 END
result: APPROVED
# Run simulation
python factory.core/extend.edit/ObjDecisionSwitchEdit.py simulate CreditScoring
python factory.core/extend.edit/ObjDecisionSwitchEdit.py simulate CreditScoring \
--input-guid "TEST_001"
# Create input table
python factory.core/extend.edit/ObjDecisionSwitchEdit.py create-input-table \
CreditScoring data_sim_credit_input
# Show tree info
python factory.core/extend.edit/ObjDecisionSwitchEdit.py info CreditScoring
# List all trees
python factory.core/extend.edit/ObjDecisionSwitchEdit.py list-trees
# Export to YAML
python factory.core/extend.edit/ObjDecisionSwitchEdit.py export-yaml CreditScoring
python factory.core/extend.edit/ObjDecisionSwitchEdit.py export-yaml CreditScoring \
--filename backup.yaml --package homechoice
| Method | Purpose |
|---|---|
load(decision_name, package) |
Load tree + nodes from DB |
export_to_file(decision_name, filename, package) |
Export to YAML |
simulate(decision_name, input_guid) |
Run full simulation |
create_simulation_data_table(decision_name, table_name) |
Create input table |
verify_outcomes(decision_name, test_set) |
Verify simulation results |
_get_output_columns() |
Collect calc output column names |
_get_primary_key_fields(context_keys) |
Resolve PrimaryKeys from input |
get_sim_key(input_table) |
Find simulation key column |
_to_snake_case(text) |
Convert PascalCase to snake_case |
_normalize_keys(data) |
Lowercase all dict keys |
_convert_keys_to_snake_case(data) |
Recursively snake_case all keys |
_format_and_convert_sql(data, parent_key) |
Prettify SQL/text fields |
_remove_null_values(data) |
Strip None values |
| Function | Purpose |
|---|---|
_json_serializer_default(obj) |
JSON serializer for Decimal types |
_init_worker_process(...) |
Multiprocessing pool worker initializer |
_simulation_worker(context) |
Per-record simulation worker function |