Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """Test the DiabetesSignificanceModel""" | |
| from collections import deque | |
| from dataclasses import dataclass | |
| from typing import Dict, Any, List, Tuple | |
| # Mock ProcessingContext if not available | |
| class ProcessingContext: | |
| timestamp: float | |
| sequence_id: int | |
| features: Dict[str, Any] | |
| history: List[Dict[str, Any]] | |
| metadata: Dict[str, Any] | |
| class DiabetesSignificanceModel: | |
| """Test version of the model""" | |
| def __init__(self, config: Dict[str, Any]): | |
| self.hypo_threshold = config.get("hypo_threshold", 70.0) | |
| self.hyper_threshold = config.get("hyper_threshold", 180.0) | |
| self.target_glucose = config.get("target_glucose", 100.0) | |
| self.weights = { | |
| "glycemic_deviation": 0.35, | |
| "velocity_risk": 0.25, | |
| "iob_risk": 0.15, | |
| "cob_risk": 0.10, | |
| "variability": 0.10, | |
| "activity_risk": 0.05, | |
| } | |
| self.glucose_history: deque = deque(maxlen=12) | |
| self.significance_ema = 0.5 | |
| self.ema_alpha = 0.15 | |
| def compute_significance(self, context: ProcessingContext) -> Tuple[float, Dict[str, Any]]: | |
| # THIS IS THE FIXED VERSION | |
| features = context.features if hasattr(context, 'features') else {} | |
| # Extract features safely with proper dict access | |
| glucose = float(features.get("glucose_mgdl", 120.0)) if isinstance(features, dict) else 120.0 | |
| print(f"✅ Successfully accessed features!") | |
| print(f" Glucose: {glucose}") | |
| print(f" Features type: {type(features)}") | |
| print(f" Features is dict: {isinstance(features, dict)}") | |
| return 0.5, {"components": {"test": 0.5}} | |
| # Test it | |
| if __name__ == "__main__": | |
| print("Testing DiabetesSignificanceModel...") | |
| context = ProcessingContext( | |
| timestamp=1234567890.0, | |
| sequence_id=0, | |
| features={ | |
| 'glucose_mgdl': 150.0, | |
| 'roc_mgdl_min': 2.0, | |
| }, | |
| history=[], | |
| metadata={}, | |
| ) | |
| config = { | |
| 'hypo_threshold': 70.0, | |
| 'hyper_threshold': 180.0, | |
| 'target_glucose': 100.0, | |
| } | |
| model = DiabetesSignificanceModel(config) | |
| sig, explanation = model.compute_significance(context) | |
| print(f"\nSignificance: {sig:.3f}") | |
| print(f"✅ Model works correctly!") | |