v1.0 - Version stable: multi-PC, détection UI-DETR-1, 3 modes exécution
- Frontend v4 accessible sur réseau local (192.168.1.40) - Ports ouverts: 3002 (frontend), 5001 (backend), 5004 (dashboard) - Ollama GPU fonctionnel - Self-healing interactif - Dashboard confiance Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
23
core/precision/models/__init__.py
Normal file
23
core/precision/models/__init__.py
Normal file
@@ -0,0 +1,23 @@
|
||||
"""
|
||||
Modèles de données pour métriques - Fiche #10
|
||||
"""
|
||||
|
||||
from .metric_models import (
|
||||
MetricType,
|
||||
ResolutionMetric,
|
||||
PerformanceMetric,
|
||||
ErrorMetric,
|
||||
generate_target_spec_hash,
|
||||
generate_screen_state_hash,
|
||||
generate_environment_hash
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
'MetricType',
|
||||
'ResolutionMetric',
|
||||
'PerformanceMetric',
|
||||
'ErrorMetric',
|
||||
'generate_target_spec_hash',
|
||||
'generate_screen_state_hash',
|
||||
'generate_environment_hash'
|
||||
]
|
||||
142
core/precision/models/metric_models.py
Normal file
142
core/precision/models/metric_models.py
Normal file
@@ -0,0 +1,142 @@
|
||||
"""
|
||||
Modèles de Données Métriques - Fiche #10 Patch A
|
||||
|
||||
Définit les structures de données pour la collecte métriques
|
||||
temps réel avec sérialisation optimisée.
|
||||
|
||||
Auteur: Dom, Alice Kiro - 15 décembre 2024
|
||||
"""
|
||||
|
||||
import time
|
||||
import hashlib
|
||||
from dataclasses import dataclass, asdict
|
||||
from typing import Optional, Dict, Any, List
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class MetricType(str, Enum):
|
||||
"""Types de métriques collectées"""
|
||||
RESOLUTION = "resolution"
|
||||
PERFORMANCE = "performance"
|
||||
ERROR = "error"
|
||||
|
||||
|
||||
@dataclass
|
||||
class ResolutionMetric:
|
||||
"""
|
||||
Métrique de résolution de cible UI
|
||||
|
||||
Collecte les données de performance et succès
|
||||
pour chaque tentative de résolution de cible.
|
||||
"""
|
||||
timestamp: float
|
||||
target_spec_hash: str
|
||||
resolution_strategy: str # "by_text", "by_role", "composite", "sniper"
|
||||
success: bool
|
||||
duration_ms: float
|
||||
confidence_score: float
|
||||
environment_hash: str
|
||||
screen_state_hash: str
|
||||
|
||||
# Détails optionnels
|
||||
error_type: Optional[str] = None
|
||||
error_message: Optional[str] = None
|
||||
candidates_count: int = 0
|
||||
cache_hit: bool = False
|
||||
|
||||
# Contexte résolution
|
||||
sniper_score: Optional[float] = None
|
||||
anchor_element_id: Optional[str] = None
|
||||
context_hints_used: Optional[List[str]] = None
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
"""Sérialisation optimisée pour stockage"""
|
||||
return asdict(self)
|
||||
|
||||
|
||||
@dataclass
|
||||
class PerformanceMetric:
|
||||
"""
|
||||
Métrique de performance système
|
||||
|
||||
Collecte les métriques de performance globales
|
||||
du système (CPU, mémoire, latence).
|
||||
"""
|
||||
timestamp: float
|
||||
operation_type: str # "resolve", "execute", "cache_lookup", "embedding"
|
||||
duration_ms: float
|
||||
memory_usage_mb: float
|
||||
cpu_usage_percent: float
|
||||
|
||||
# Métriques cache
|
||||
cache_hit: bool = False
|
||||
cache_size_mb: Optional[float] = None
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
"""Sérialisation optimisée"""
|
||||
return asdict(self)
|
||||
|
||||
|
||||
@dataclass
|
||||
class ErrorMetric:
|
||||
"""
|
||||
Métrique d'erreur système
|
||||
|
||||
Collecte les erreurs et exceptions pour
|
||||
analyse et amélioration continue.
|
||||
"""
|
||||
timestamp: float
|
||||
error_type: str
|
||||
error_message: str
|
||||
component: str # "target_resolver", "action_executor", "cache", etc.
|
||||
severity: str # "low", "medium", "high", "critical"
|
||||
|
||||
# Contexte erreur
|
||||
stack_trace: Optional[str] = None
|
||||
context: Optional[Dict[str, Any]] = None
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
"""Sérialisation optimisée"""
|
||||
return asdict(self)
|
||||
|
||||
|
||||
# Utilitaires pour génération hash
|
||||
def generate_target_spec_hash(target_spec) -> str:
|
||||
"""Génère hash stable pour TargetSpec"""
|
||||
try:
|
||||
# Sérialisation déterministe
|
||||
spec_str = f"{target_spec.by_role}|{target_spec.by_text}|{target_spec.by_position}"
|
||||
if hasattr(target_spec, 'context_hints') and target_spec.context_hints:
|
||||
hints_str = "|".join(sorted(f"{k}:{v}" for k, v in target_spec.context_hints.items()))
|
||||
spec_str += f"|{hints_str}"
|
||||
|
||||
return hashlib.md5(spec_str.encode()).hexdigest()[:16]
|
||||
except Exception:
|
||||
return "unknown"
|
||||
|
||||
|
||||
def generate_screen_state_hash(screen_state) -> str:
|
||||
"""Génère hash stable pour ScreenState"""
|
||||
try:
|
||||
# Hash basé sur éléments UI principaux
|
||||
elements_str = ""
|
||||
if hasattr(screen_state, 'ui_elements') and screen_state.ui_elements:
|
||||
for elem in screen_state.ui_elements[:10]: # Limite pour performance
|
||||
elements_str += f"{elem.element_type}|{elem.text}|{elem.bbox}|"
|
||||
|
||||
return hashlib.md5(elements_str.encode()).hexdigest()[:16]
|
||||
except Exception:
|
||||
return "unknown"
|
||||
|
||||
|
||||
def generate_environment_hash() -> str:
|
||||
"""Génère hash stable pour environnement actuel"""
|
||||
try:
|
||||
import platform
|
||||
|
||||
# Informations système
|
||||
os_info = f"{platform.system()}|{platform.release()}"
|
||||
env_str = f"{os_info}"
|
||||
return hashlib.md5(env_str.encode()).hexdigest()[:16]
|
||||
except Exception:
|
||||
return "unknown"
|
||||
Reference in New Issue
Block a user