This guide shows you how to manage and execute decision trees using the command-line interface.
All commands are run from the project root:
# View available commands
python factory.core/ObjDecisionSwitch.py --help
# Get help for specific command
python factory.core/ObjDecisionSwitch.py simulate --help
python factory.core/ObjDecisionSwitch.py list-trees
Output shows all trees in your current package with node counts:
Decision Trees in HOMECHOICE:
• CreditScoring v1 (15 nodes)
• ProductRecommendation v2 (23 nodes)
python factory.core/ObjDecisionSwitch.py info CreditScoring
Shows metadata including:
# Process all records from configured DataTable
python factory.core/ObjDecisionSwitch.py simulate CreditScoring
# Process specific test set
python factory.core/ObjDecisionSwitch.py simulate CreditScoring --input-guid "TEST_001"
Results are stored in bloom_sim_{decision_name}_sim_output table.
python factory.core/ObjDecisionSwitch.py distribution CreditScoring
Shows bar chart of results:
Outcome Distribution:
O_APPROVED | ████████████████████ 450 (45.00%)
O_DECLINED | ████████████ 300 (30.00%)
# Print to console
python factory.core/ObjDecisionSwitch.py diagram CreditScoring
# Save to file
python factory.core/ObjDecisionSwitch.py diagram CreditScoring > docs/credit_flow.mmd
Creates a flowchart showing nodes, conditions, and outcomes.
# Preview SQL
python factory.core/ObjDecisionSwitch.py generate-sql CreditScoring
# Save to database
python factory.core/ObjDecisionSwitch.py store-sql CreditScoring
# Use custom table
python factory.core/ObjDecisionSwitch.py generate-sql CreditScoring --input-table data_applicants
The generated SQL uses nested CASE statements to replicate decision tree logic.
python factory.core/ObjDecisionSwitch.py create-input-table MyDecision data_sim_test
This creates a table with:
After creation, populate the table with test data:
INSERT INTO data_sim_test
(GUID, SetGuid, Field1, Field2, Expected_Outcome)
VALUES ('TEST_001', 'BATCH_1', 'value1', 'value2', 'O_APPROVED');
Compare Python simulation results with SQL execution:
python factory.core/ObjDecisionSwitch.py compare CreditScoring data_test_cases
Output shows:
Use this before production deployment to ensure correctness.
Export decision tree to industry-standard format:
python factory.core/ObjDecisionSwitch.py export-pmml CreditScoring credit_model.pmml
Use cases:
Load a decision tree from PMML file:
python factory.core/ObjDecisionSwitch.py import-pmml credit_model.pmml
This creates entries in def_decision_tree and def_decision_treenodes tables.
# 1. Create test data table
python factory.core/ObjDecisionSwitch.py create-input-table MyDecision data_sim_mydecision
# 2. Populate table with test data (manual SQL or script)
# 3. Run simulation
python factory.core/ObjDecisionSwitch.py simulate MyDecision
# 4. View results
python factory.core/ObjDecisionSwitch.py distribution MyDecision
# 5. Generate documentation
python factory.core/ObjDecisionSwitch.py diagram MyDecision > docs/mydecision.mmd
# 1. Check current state
python factory.core/ObjDecisionSwitch.py info ProductionTree
# 2. Validate correctness
python factory.core/ObjDecisionSwitch.py compare ProductionTree data_validation_set
# 3. Store SQL for database execution
python factory.core/ObjDecisionSwitch.py store-sql ProductionTree
# 4. Create backup
python factory.core/ObjDecisionSwitch.py export-pmml ProductionTree backups/prod_v3.pmml
# 5. Run simulation
python factory.core/ObjDecisionSwitch.py simulate ProductionTree
Example shell script for automated testing:
#!/bin/bash
DECISION="CreditScoring"
TEST_GUID="AUTO_$(date +%Y%m%d_%H%M%S)"
echo "Testing decision tree: $DECISION"
# Run simulation
python factory.core/ObjDecisionSwitch.py simulate $DECISION --input-guid "$TEST_GUID"
# Check distribution
python factory.core/ObjDecisionSwitch.py distribution $DECISION --guid "$TEST_GUID"
# Validate against SQL
python factory.core/ObjDecisionSwitch.py compare $DECISION data_test_cases
echo "Test complete"
| Command | Purpose | Required Args |
|---|---|---|
list-trees |
Show all decision trees | None |
info |
Display tree metadata | decision_name |
simulate |
Run simulation | decision_name |
distribution |
Show outcome stats | decision_name |
diagram |
Generate flowchart | decision_name |
generate-sql |
Create SQL statement | decision_name |
store-sql |
Save SQL to database | decision_name |
compare |
Validate Python vs SQL | decision_name, input_table |
create-input-table |
Create test table | decision_name, table_name |
export-pmml |
Export to PMML | decision_name, output_file |
import-pmml |
Import from PMML | input_file |
--input-guid to process specific test batchesresource.notes/howto/multiprocessing_guide.md for parallel processingExpected_Outcome in test dataTEST_REGRESSION_20260221)If decision tree not found:
python factory.core/ObjDecisionSwitch.py list-trees # Check available trees
If database connection fails:
python factory.core/ObjData.py preflight # Verify connectivity
resource.notes/howto/multiprocessing_guide.mdfactory.core/ObjDecisionSwitch.pyresource.schema/def_decision_tree.sql