102 Zeilen
2.9 KiB
Python
102 Zeilen
2.9 KiB
Python
"""
|
|
Action Timing Value Object - Repräsentiert Timing-Informationen einer Aktion
|
|
"""
|
|
|
|
from dataclasses import dataclass
|
|
from datetime import datetime
|
|
from enum import Enum
|
|
from typing import Optional, Dict, Any
|
|
|
|
|
|
class ActionType(Enum):
|
|
"""Typen von Aktionen die getimed werden"""
|
|
# Navigation
|
|
PAGE_LOAD = "page_load"
|
|
PAGE_NAVIGATION = "page_navigation"
|
|
|
|
# Form-Interaktionen
|
|
FORM_FILL = "form_fill"
|
|
BUTTON_CLICK = "button_click"
|
|
INPUT_TYPE = "input_type"
|
|
DROPDOWN_SELECT = "dropdown_select"
|
|
CHECKBOX_TOGGLE = "checkbox_toggle"
|
|
|
|
# Verifizierung
|
|
EMAIL_CHECK = "email_check"
|
|
SMS_CHECK = "sms_check"
|
|
CAPTCHA_SOLVE = "captcha_solve"
|
|
|
|
# Account-Aktionen
|
|
REGISTRATION_START = "registration_start"
|
|
REGISTRATION_COMPLETE = "registration_complete"
|
|
LOGIN_ATTEMPT = "login_attempt"
|
|
LOGOUT = "logout"
|
|
|
|
# Daten-Operationen
|
|
SCREENSHOT = "screenshot"
|
|
DATA_SAVE = "data_save"
|
|
SESSION_SAVE = "session_save"
|
|
|
|
# Netzwerk
|
|
API_REQUEST = "api_request"
|
|
FILE_UPLOAD = "file_upload"
|
|
FILE_DOWNLOAD = "file_download"
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class ActionTiming:
|
|
"""
|
|
Repräsentiert Timing-Informationen einer Aktion.
|
|
Frozen dataclass macht es unveränderlich (Value Object).
|
|
"""
|
|
|
|
action_type: ActionType
|
|
timestamp: datetime
|
|
duration: float # in Sekunden
|
|
success: bool
|
|
|
|
# Optionale Metadaten
|
|
url: Optional[str] = None
|
|
element_selector: Optional[str] = None
|
|
error_message: Optional[str] = None
|
|
retry_count: int = 0
|
|
metadata: Optional[Dict[str, Any]] = None
|
|
|
|
def __post_init__(self):
|
|
"""Validierung der Timing-Daten"""
|
|
if self.duration < 0:
|
|
raise ValueError("Duration kann nicht negativ sein")
|
|
if self.retry_count < 0:
|
|
raise ValueError("Retry count kann nicht negativ sein")
|
|
|
|
@property
|
|
def duration_ms(self) -> float:
|
|
"""Gibt die Dauer in Millisekunden zurück"""
|
|
return self.duration * 1000
|
|
|
|
@property
|
|
def is_slow(self) -> bool:
|
|
"""Prüft ob die Aktion langsam war (> 3 Sekunden)"""
|
|
return self.duration > 3.0
|
|
|
|
@property
|
|
def is_very_slow(self) -> bool:
|
|
"""Prüft ob die Aktion sehr langsam war (> 10 Sekunden)"""
|
|
return self.duration > 10.0
|
|
|
|
def to_dict(self) -> Dict[str, Any]:
|
|
"""Konvertiert zu Dictionary für Serialisierung"""
|
|
return {
|
|
'action_type': self.action_type.value,
|
|
'timestamp': self.timestamp.isoformat(),
|
|
'duration': self.duration,
|
|
'duration_ms': self.duration_ms,
|
|
'success': self.success,
|
|
'url': self.url,
|
|
'element_selector': self.element_selector,
|
|
'error_message': self.error_message,
|
|
'retry_count': self.retry_count,
|
|
'metadata': self.metadata or {},
|
|
'is_slow': self.is_slow,
|
|
'is_very_slow': self.is_very_slow
|
|
} |