Download src/services/performance.py from anaselamr/yaz: direct link, hf CLI and curl.
- Browser
- Download file 1.2 kB
-
https://huggingface.co/spaces/anaselamr/yaz/resolve/main/src/services/performance.py
- Command line
-
hf download hf://spaces/anaselamr/yaz/src/services/performance.py
-
curl -L -o performance.py https://huggingface.co/spaces/anaselamr/yaz/resolve/main/src/services/performance.py
1.2 kB
| """YAZ Care Platform - Performance Service Fallback""" | |
| import time | |
| from datetime import datetime | |
| from typing import Any, Dict | |
| import structlog | |
| logger = structlog.get_logger(__name__) | |
| class PerformanceService: | |
| """Simple performance service fallback""" | |
| def __init__(self): | |
| self.start_time = time.time() | |
| self.request_count = 0 | |
| self.total_time = 0.0 | |
| def record_request(self, duration: float, endpoint: str = "/"): | |
| """Record request performance""" | |
| try: | |
| self.request_count += 1 | |
| self.total_time += duration | |
| except Exception as e: | |
| logger.warning(f"Failed to record request: {e}") | |
| def get_metrics(self) -> dict[str, Any]: | |
| """Get performance metrics""" | |
| uptime = time.time() - self.start_time | |
| avg_time = self.total_time / max(self.request_count, 1) | |
| return { | |
| "uptime_seconds": uptime, | |
| "request_count": self.request_count, | |
| "avg_response_time": avg_time, | |
| "requests_per_minute": self.request_count / max(uptime / 60, 1), | |
| "status": "healthy", | |
| } | |
| # Global instance | |
| performance_service = PerformanceService() | |