06 developer guide - VforVitorio/F1_Strat_Manager GitHub Wiki
Integration Guide
Relevant source files
- scripts/IS_agent/N06_rule_merging.ipynb
- scripts/IS_agent/utils/N06_rule_merging.py
- scripts/app/app_modules/agent/N01_agent_setup.py
- scripts/app/app_modules/agent/N02_degradation_time_rules.py
- scripts/app/app_modules/agent/N03_lap_time_rules.py
- scripts/app/app_modules/agent/N04_nlp_rules.py
- scripts/app/app_modules/agent/N05_gap_rules.py
- scripts/app/app_modules/agent/N06_rule_merging.py
2. Adding New Data Sources
The first step in extending the system is to add new data sources and create transformation functions to convert the data into facts that the rule engine can process.
2.1 Data Source Requirements
New data sources should provide one or more of the following types of information:
- Telemetry data (lap times, tire age, etc.)
- Gap information between cars
- Degradation predictions
- Radio communications
- Race status information
2.2 Creating Transformation Functions
You need to create a transformation function that converts your data into fact objects. Follow this pattern:
2.3 Implementation Steps
- Create a new loader function for your data source
- Create a transformation function that converts the data into facts
- Add your transformation function to
transform_all_facts()
Example of adding a new transformation function:
Then, update the transform_all_facts()
function to include your new transformation:
3. Creating Custom Fact Classes
If your data doesn't fit into existing fact classes, you'll need to create a new fact class.
4.2 Implementation Steps
- Create a new class that inherits from
F1StrategyEngine
- Define rules using the
@Rule
decorator from Experta - Implement methods that execute when rules are triggered Example of a custom rule system:
5. Integrating with the Complete Strategy Engine
After creating your custom rule system, you need to integrate it with the F1CompleteStrategyEngine
.
5.1 Updating the Complete Strategy Engine
- Modify the class definition to include your rule system
- Update the
record_rule_fired
method to track your rule system - Update the
active_systems
dictionary initialization
5.2 Updating Conflict Resolution
You may need to update the conflict resolution mechanism in _resolve_conflicts
method if your new rules can potentially conflict with existing rules:
6. Testing Integration
Testing is crucial to ensure that your new components integrate properly with the system.
6.1 Testing Transformation Functions
Create test functions to verify that your transformation functions correctly convert data to facts:
6.2 Testing Rule Activation
Test that your rules are correctly activated when conditions are met:
6.3 Integration Testing
Finally, test that your components work within the complete system:
7. Complete Integration Flow
The following diagram provides an end-to-end view of the integration process, from loading data to generating recommendations:
8. Common Integration Issues and Solutions
Issue | Possible Cause | Solution |
---|---|---|
Rules not activating | Missing or incorrectly formatted facts | Verify fact structure with print statements, ensure all required fields are present |
Type errors in facts | Incorrect data types in transformation functions | Add explicit type conversion in transformation functions (e.g., int() , float() ) |
Recommendations not showing up | Conflicts being resolved against your rules | Check conflict resolution, adjust priorities or confidence levels |
Integration exceptions | Import path issues | Make sure your modules are in the Python path, use absolute imports |
Duplicate rules firing | Multiple rule systems handling same condition | Use more specific rule conditions, add mutual exclusion constraints |
9. Best Practices for Integration
- Follow Naming Conventions: Use consistent prefixes for your rule methods (e.g.,
weather_*
for weather rules) - Document Everything: Add detailed docstrings to all new functions, methods, and classes
- Handle Errors Gracefully: Wrap transformation functions in try-except blocks to prevent failure cascades
- Test Incrementally: Test each component separately before full integration
- Be Mindful of Performance: Avoid expensive operations in rule conditions as they evaluate frequently
- Maintain Backward Compatibility: Don't modify existing fact structures, extend them instead
- Use Debug Flags: Add debug parameters to transformation functions for easier troubleshooting
Summary
This integration guide provides the foundation for extending the F1 Strategy Manager with new data sources, models, and rules. By following the outlined steps and patterns, you can add new capabilities while maintaining compatibility with the existing system.