
NOTICE: All information contained herein is, and remains
the property of TechnoCore.
The intellectual and technical concepts contained
herein are proprietary to TechnoCore and dissemination of this information or reproduction of this material
is strictly forbidden unless prior written permission is obtained
from TechnoCore.
The ObjServiceDecisionSwitch is a service class responsible for managing and executing decision tree logic. It allows for the creation, evaluation, validation, and visualization of complex decision-making processes based on contextual data.
The service can read decision tree structures from a database, compute outcomes based on input context, validate results against expected outcomes, and generate comprehensive reports. It supports both single-tree operations and batch processing of multiple decision trees.
def_decision_tree, def_decision_treenodes).The service uses typer to provide a comprehensive set of CLI commands for interaction.
sim <decision_name>Runs a simulation for a given decision tree. This command processes a dataset against the tree logic and stores the results with validation.
python factory.service/package.core/ObjServiceDecisionSwitch.py sim hc_collections_abovetheline
Options:
--workers N: Number of parallel workers (default: 4)What it does:
bloom_sim_{decision_name} tablerun-decision <decision_name>Alternative command name for running simulations (alias for sim).
python factory.service/package.core/ObjServiceDecisionSwitch.py run-decision hc_collections_abovetheline
validation-report <decision_name>Generate comprehensive validation report comparing expected vs actual outcomes.
# Basic text report
python factory.service/package.core/ObjServiceDecisionSwitch.py validation-report hc_collections_abovetheline
# Show detailed failures
python factory.service/package.core/ObjServiceDecisionSwitch.py validation-report hc_collections_abovetheline --show-failures
# Export to JSON
python factory.service/package.core/ObjServiceDecisionSwitch.py validation-report hc_collections_abovetheline --output-format json
# Export to CSV
python factory.service/package.core/ObjServiceDecisionSwitch.py validation-report hc_collections_abovetheline --output-format csv > report.csv
Options:
--output-format [text|json|csv]: Output format (default: text)--show-failures: Include detailed failure records--limit N: Maximum failures to show (default: 20)Output includes:
performance-report <decision_name>Generate performance metrics for simulation runs.
# Show stats from existing simulation
python factory.service/package.core/ObjServiceDecisionSwitch.py performance-report hc_collections_abovetheline
# Run new simulation with timing
python factory.service/package.core/ObjServiceDecisionSwitch.py performance-report hc_collections_abovetheline --run-simulation
Options:
--run-simulation: Execute new simulation with performance trackingMetrics shown:
compare-simulations <decision_name>Compare two simulation runs to identify differences in outcomes.
# Compare two runs
python factory.service/package.core/ObjServiceDecisionSwitch.py compare-simulations hc_collections_abovetheline \
--run1 RUN001 --run2 RUN002
# Export comparison to JSON
python factory.service/package.core/ObjServiceDecisionSwitch.py compare-simulations hc_collections_abovetheline \
--run1 RUN001 --run2 RUN002 --output-format json
# Export to CSV
python factory.service/package.core/ObjServiceDecisionSwitch.py compare-simulations hc_collections_abovetheline \
--run1 RUN001 --run2 RUN002 --output-format csv > comparison.csv
Required Options:
--run1 SETGUID: First SetGuid to compare--run2 SETGUID: Second SetGuid to compareOptional:
--output-format [text|json|csv]: Output format (default: text)Use cases:
tree-diffCompare decision tree structures to identify structural differences.
# Compare two trees
python factory.service/package.core/ObjServiceDecisionSwitch.py tree-diff \
--tree1 hc_collections_v1 --tree2 hc_collections_v2
# Export to JSON
python factory.service/package.core/ObjServiceDecisionSwitch.py tree-diff \
--tree1 hc_collections_v1 --tree2 hc_collections_v2 --output-format json
# Export to CSV
python factory.service/package.core/ObjServiceDecisionSwitch.py tree-diff \
--tree1 hc_collections_v1 --tree2 hc_collections_v2 --output-format csv
Required Options:
--tree1 NAME: First decision tree name--tree2 NAME: Second decision tree nameOptional:
--output-format [text|json|csv]: Output format (default: text)Output includes:
Example Output:
DECISION TREE STRUCTURE COMPARISON
Tree 1: hc_collections_v1 (275 nodes)
Tree 2: hc_collections_v2 (278 nodes)
SUMMARY
Added Nodes: 5
Removed Nodes: 2
Modified Nodes: 3
Unchanged Nodes: 70
ADDED NODES (5)
Node: N27 (2 rules)
• CollectionsScore < 620 → O51
• CollectionsScore >= 620 → O52
MODIFIED NODES (3)
Node: N10
Added Rules (1):
+ Dispatch Defaulter = '1' → O26
Removed Rules (1):
- Dispatch Defaulter = '0' → N11
CHANGE MAGNITUDE: 3.6% of nodes affected
Assessment: Minor changes - likely safe to deploy
Use cases:
Best practices:
validate-tree <decision_name>Validate decision tree structure and data integrity.
python factory.service/package.core/ObjServiceDecisionSwitch.py validate-tree hc_collections_abovetheline
Checks performed:
Run this before:
validate-input-data <decision_name>Validate input data quality and completeness.
# Basic validation
python factory.service/package.core/ObjServiceDecisionSwitch.py validate-input-data hc_collections_abovetheline
# Show sample invalid records
python factory.service/package.core/ObjServiceDecisionSwitch.py validate-input-data hc_collections_abovetheline \
--show-samples --limit 20
Options:
--show-samples: Display sample invalid records--limit N: Number of samples to show (default: 10)Checks performed:
Use cases:
cleanup-simulations <decision_name>Clean up old simulation results.
# Delete specific run (with confirmation)
python factory.service/package.core/ObjServiceDecisionSwitch.py cleanup-simulations hc_collections_abovetheline \
--set-guid RUN001
# Delete all runs (with confirmation)
python factory.service/package.core/ObjServiceDecisionSwitch.py cleanup-simulations hc_collections_abovetheline \
--all-runs
# Skip confirmation prompt
python factory.service/package.core/ObjServiceDecisionSwitch.py cleanup-simulations hc_collections_abovetheline \
--set-guid RUN001 --confirm
Options:
--set-guid GUID: Specific SetGuid to delete--all-runs: Delete all simulation results--confirm: Skip confirmation promptSafety features:
export-validation-failures <decision_name>Export failed validation records to CSV for detailed analysis.
# Export failures
python factory.service/package.core/ObjServiceDecisionSwitch.py export-validation-failures hc_collections_abovetheline
# Custom output file and limit
python factory.service/package.core/ObjServiceDecisionSwitch.py export-validation-failures hc_collections_abovetheline \
--output-file failures_analysis.csv --limit 500
Options:
--output-file FILE: Output CSV filename (default: validation_failures.csv)--limit N: Maximum records to export (default: 1000)CSV columns:
Use cases:
visualize-tree <decision_name>Generate Mermaid flowchart diagram of decision tree structure.
# Generate diagram
python factory.service/package.core/ObjServiceDecisionSwitch.py visualize-tree hc_collections_abovetheline
# Custom output file
python factory.service/package.core/ObjServiceDecisionSwitch.py visualize-tree hc_collections_abovetheline \
--output-file my_tree.png
Options:
--output-file FILE: Output filename (default: decision_tree.png)Output formats:
Diagram features:
Use cases:
diagram <decision_name>Generates a Mermaid flowchart diagram and stores it in the database.
python factory.service/package.core/ObjServiceDecisionSwitch.py diagram hc_collections_abovetheline
diagram-sankey <decision_name>Generates a Mermaid Sankey diagram from simulation results showing data flow.
python factory.service/package.core/ObjServiceDecisionSwitch.py diagram-sankey hc_collections_abovetheline
batch-simulateRun simulations for multiple decision trees in batch mode.
# Run all trees in package
python factory.service/package.core/ObjServiceDecisionSwitch.py batch-simulate --package HOMECHOICE
# Run specific trees
python factory.service/package.core/ObjServiceDecisionSwitch.py batch-simulate \
--package HOMECHOICE \
--decision-names "tree1,tree2,tree3"
# Adjust parallelism and output
python factory.service/package.core/ObjServiceDecisionSwitch.py batch-simulate \
--package HOMECHOICE \
--workers 8 \
--output-file batch_results.json
Options:
--package NAME: Package name (default: HOMECHOICE)--decision-names LIST: Comma-separated tree names (or all if omitted)--workers N: Number of parallel workers (default: 4)--output-file FILE: JSON output file (default: batch_results.json)Output includes:
Use cases:
selftest <decision_name>Runs predefined test cases against the decision tree.
python factory.service/package.core/ObjServiceDecisionSwitch.py selftest TestTree
test-pmml-cycle [decision_name]Performs full PMML save/load test cycle.
python factory.service/package.core/ObjServiceDecisionSwitch.py test-pmml-cycle TestTree
save-pmml <decision_name> <file_path>Export decision tree to PMML format.
python factory.service/package.core/ObjServiceDecisionSwitch.py save-pmml hc_collections_abovetheline tree.pmml
load-pmml <file_path>Import decision tree from PMML file.
python factory.service/package.core/ObjServiceDecisionSwitch.py load-pmml tree.pmml
setup-tablesCreates necessary database tables.
python factory.service/package.core/ObjServiceDecisionSwitch.py setup-tables
Step 1: Validate Structure
# Check tree structure for errors
python factory.service/package.core/ObjServiceDecisionSwitch.py validate-tree my_new_tree
Step 2: Validate Input Data
# Check data quality
python factory.service/package.core/ObjServiceDecisionSwitch.py validate-input-data my_new_tree --show-samples
Step 3: Run Simulation
# Execute simulation
python factory.service/package.core/ObjServiceDecisionSwitch.py sim my_new_tree --workers 8
Step 4: Check Results
# Generate validation report
python factory.service/package.core/ObjServiceDecisionSwitch.py validation-report my_new_tree --show-failures
# Check performance
python factory.service/package.core/ObjServiceDecisionSwitch.py performance-report my_new_tree
Step 5: Visualize
# Generate diagram for documentation
python factory.service/package.core/ObjServiceDecisionSwitch.py visualize-tree my_new_tree
When updating a decision tree:
# Run simulation with old version (save as RUN_OLD)
python factory.service/package.core/ObjServiceDecisionSwitch.py sim my_tree
# Update decision tree logic in database
# ...
# Run simulation with new version (save as RUN_NEW)
python factory.service/package.core/ObjServiceDecisionSwitch.py sim my_tree
# Compare results
python factory.service/package.core/ObjServiceDecisionSwitch.py compare-simulations my_tree \
--run1 RUN_OLD --run2 RUN_NEW --output-format json > changes.json
# 1. Get overview
python factory.service/package.core/ObjServiceDecisionSwitch.py validation-report my_tree
# 2. Export failures for analysis
python factory.service/package.core/ObjServiceDecisionSwitch.py export-validation-failures my_tree \
--output-file failures.csv --limit 100
# 3. Check input data quality
python factory.service/package.core/ObjServiceDecisionSwitch.py validate-input-data my_tree --show-samples
# 4. Validate tree structure
python factory.service/package.core/ObjServiceDecisionSwitch.py validate-tree my_tree
# Weekly: Clean up old test runs
python factory.service/package.core/ObjServiceDecisionSwitch.py cleanup-simulations my_tree \
--set-guid OLD_TEST_RUN --confirm
# Monthly: Full regression test
python factory.service/package.core/ObjServiceDecisionSwitch.py batch-simulate \
--package HOMECHOICE --output-file monthly_regression.json
Symptoms: Error before any records are processed
Possible causes:
Solution:
# Check tree exists and is valid
python factory.service/package.core/ObjServiceDecisionSwitch.py validate-tree my_tree
# Verify input data
python factory.service/package.core/ObjServiceDecisionSwitch.py validate-input-data my_tree
Symptoms: validation-report shows failed validations
Possible causes:
Solution:
# Export failures for analysis
python factory.service/package.core/ObjServiceDecisionSwitch.py export-validation-failures my_tree
# Check specific failed records in CSV
# Trace through decision tree logic manually
# Check for data quality issues
python factory.service/package.core/ObjServiceDecisionSwitch.py validate-input-data my_tree --show-samples
Symptoms: Simulation takes longer than expected
Possible causes:
Solution:
# Run with more workers
python factory.service/package.core/ObjServiceDecisionSwitch.py sim my_tree --workers 16
# Check performance metrics
python factory.service/package.core/ObjServiceDecisionSwitch.py performance-report my_tree --run-simulation
# Expected: 100-1000 records/second depending on complexity
Symptoms: Outcomes changed after tree update
Possible causes:
Solution:
# Compare before/after runs
python factory.service/package.core/ObjServiceDecisionSwitch.py compare-simulations my_tree \
--run1 BEFORE --run2 AFTER --show-differences
# Analyze which records changed and why
# Review decision tree changes
# Validate tree structure
python factory.service/package.core/ObjServiceDecisionSwitch.py validate-tree my_tree
Symptoms: Process runs out of memory
Possible causes:
Solution:
# Reduce worker count
python factory.service/package.core/ObjServiceDecisionSwitch.py sim my_tree --workers 2
# Process in batches (modify input query to use LIMIT/OFFSET)
# Monitor memory usage during simulation
Always validate before deploying
validate-tree to check structurevalidate-input-data to verify data qualityUse version control for decision trees
Document expected outcomes
Test incrementally
Achieve 100% pass rate before production
Maintain comprehensive test coverage
Use batch-simulate for regression testing
Optimize for your workload
Track performance metrics
Validate input data regularly
Clean data before simulation
Clean up old simulation results
Keep documentation current
Decision trees are configured in the database:
Tables:
def_decision_tree: Tree metadata (name, package, version)def_decision_treenodes: Tree nodes (conditions, outcomes)Required attributes per ObjServiceDecisionSwitch instance:
_Datatable: Input data table name_Simdatatable: Simulation data table name (optional)_Simoutputtable: Output table name (auto-generated if not set)SQL Queries:
All SQL queries are stored in ObjServiceDecisionSwitch.yaml under the queries section.
from ObjServiceDecisionSwitch import ObjServiceApi
# Load decision tree
service = ObjServiceApi()
service.read('hc_collections_abovetheline')
# Run simulation
service.simulate('hc_collections_abovetheline', workers=4)
# Evaluate single record
context = {
'Bureau Status': '',
'Payment': '0',
'Now Due': 100,
# ... other fields
}
result = service.process(context)
print(result) # Returns dict with calculated outcomes