Function Signature
Input Parameters
The function receives dictionaries from the previous three steps:- m (metricas): Dexterity metrics from Step 2
- b (benchmarking): Precision data from Step 3
- r (riesgo): Risk analysis from Step 4
Scoring Algorithm
The score starts at 100 and penalties are subtracted:analysis_pipeline.py
Penalty Breakdown
Hemorrhages: -15 points each
Hemorrhages: -15 points each
Hemorrhages are the most critical errors. Each bleeding event costs 15 points.Rationale: In real surgery, vascular damage is life-threatening and must be avoided at all costs.
Tumor Touches: -8 points each
Tumor Touches: -8 points each
Contact with tumor tissue is a moderate error. Each touch costs 8 points.Rationale: Tumor contact can spread cancer cells, but is less immediately dangerous than hemorrhage.
Poor Economy: -10 points
Poor Economy: -10 points
If economy of movement exceeds 1.5x (path is 50% longer than necessary), a 10-point penalty applies.Rationale: Inefficient movements indicate poor planning and increase procedure time and tissue trauma.
The final score is clamped between 0 and 100:
score = max(0, min(100, score))Performance Tiers
Based on the final score, performance is classified into one of four tiers:- 🌟 EXCELENTE (90-100)
- ✅ BUENO (75-89)
- ⚠️ MEJORABLE (60-74)
- ❌ DEFICIENTE (<60)
Characteristics:
- Zero or one minor error
- Excellent economy of movement
- High precision
- Smooth, controlled technique
Feedback Structure
The feedback is formatted as Markdown with four main sections:1. Critical Alerts (🚨)
Highlights the most severe issues that need immediate attention:- Hemorrhages: Number of bleeding events with urgent flag if > 0
- Tumor Touches: Count of cancerous tissue contacts
- Risk Quadrants: Spatial zones where errors occurred
2. Dexterity Metrics (📊)
Key performance indicators from the physics analysis:- Economy of Movement: Path efficiency ratio (ideal < 1.2x)
- Fluidity (Average Jerk): Smoothness indicator
- Precision vs Gold Standard: Percentage score for path accuracy
3. Statistics (📈)
Raw data about the procedure:- Total Duration: Time from start to finish
- Distance Traveled: Total path length
- Average Velocity: Mean movement speed
4. Recommendations (💡)
Conditional, personalized advice based on specific issues:Recommendations are only added if specific conditions are met, making feedback highly personalized.
Complete Example Output
Input Metrics
Generated Output
Recommendation Logic
Hemorrhages > 0
“Priorizar control vascular en cuadrantes críticos.”
Economy > 1.8
“Planificar trayectorias más directas para reducir fatiga.”
Precision < 70%
“Mantener mayor estabilidad en la ejecución del path ideal.”
Score < 80
“Incrementar práctica en simulador para mejorar coordinación motora.”
Clinical Value
The feedback system provides:- Objective Scoring: Removes subjective bias from performance evaluation
- Actionable Insights: Specific recommendations tied to measurable metrics
- Progress Tracking: Consistent scoring enables longitudinal performance monitoring
- Focused Training: Pinpoints exact areas needing improvement
Performance
Feedback generation is extremely fast:- String formatting: Simple concatenation and f-strings
- Conditional logic: Basic if statements
- No heavy computation: Just assembling pre-calculated metrics
Next Steps
Setup AI Environment
Install dependencies and configure the AI service
Use the AI Client
Learn how to integrate with the backend API