Initial commit
Dieser Commit ist enthalten in:
13
domain/services/__init__.py
Normale Datei
13
domain/services/__init__.py
Normale Datei
@ -0,0 +1,13 @@
|
||||
"""
|
||||
Domain Services - Geschäftslogik-Interfaces die nicht in Entities gehören
|
||||
"""
|
||||
|
||||
from .rate_limit_service import IRateLimitService
|
||||
from .fingerprint_service import IFingerprintService
|
||||
from .analytics_service import IAnalyticsService
|
||||
|
||||
__all__ = [
|
||||
'IRateLimitService',
|
||||
'IFingerprintService',
|
||||
'IAnalyticsService'
|
||||
]
|
||||
181
domain/services/analytics_service.py
Normale Datei
181
domain/services/analytics_service.py
Normale Datei
@ -0,0 +1,181 @@
|
||||
"""
|
||||
Analytics Service Interface - Domain Service für Analytics und Reporting
|
||||
"""
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import List, Optional, Dict, Any, Union
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from domain.entities.account_creation_event import AccountCreationEvent
|
||||
from domain.entities.error_event import ErrorEvent
|
||||
from domain.value_objects.error_summary import ErrorSummary
|
||||
from domain.value_objects.report import Report, ReportType
|
||||
|
||||
|
||||
class IAnalyticsService(ABC):
|
||||
"""
|
||||
Interface für Analytics Service.
|
||||
Definiert die Geschäftslogik für Event-Tracking und Reporting.
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def log_event(self, event: Union[AccountCreationEvent, ErrorEvent, Any]) -> None:
|
||||
"""
|
||||
Loggt ein Event für spätere Analyse.
|
||||
|
||||
Args:
|
||||
event: Zu loggendes Event
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_success_rate(self,
|
||||
timeframe: Optional[timedelta] = None,
|
||||
platform: Optional[str] = None) -> float:
|
||||
"""
|
||||
Berechnet die Erfolgsrate für Account-Erstellung.
|
||||
|
||||
Args:
|
||||
timeframe: Optional - Zeitrahmen für Berechnung
|
||||
platform: Optional - Spezifische Plattform
|
||||
|
||||
Returns:
|
||||
Erfolgsrate zwischen 0.0 und 1.0
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_common_errors(self,
|
||||
limit: int = 10,
|
||||
timeframe: Optional[timedelta] = None) -> List[ErrorSummary]:
|
||||
"""
|
||||
Holt die häufigsten Fehler.
|
||||
|
||||
Args:
|
||||
limit: Maximale Anzahl von Fehlern
|
||||
timeframe: Optional - Zeitrahmen für Analyse
|
||||
|
||||
Returns:
|
||||
Liste von Fehler-Zusammenfassungen
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def generate_report(self,
|
||||
report_type: ReportType,
|
||||
start: datetime,
|
||||
end: datetime,
|
||||
platforms: Optional[List[str]] = None) -> Report:
|
||||
"""
|
||||
Generiert einen detaillierten Report.
|
||||
|
||||
Args:
|
||||
report_type: Typ des Reports
|
||||
start: Startdatum
|
||||
end: Enddatum
|
||||
platforms: Optional - Filter für spezifische Plattformen
|
||||
|
||||
Returns:
|
||||
Generierter Report
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_real_time_metrics(self) -> Dict[str, Any]:
|
||||
"""
|
||||
Holt Echtzeit-Metriken für Dashboard.
|
||||
|
||||
Returns:
|
||||
Dictionary mit aktuellen Metriken
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def track_performance(self,
|
||||
metric_name: str,
|
||||
value: float,
|
||||
tags: Optional[Dict[str, str]] = None) -> None:
|
||||
"""
|
||||
Trackt eine Performance-Metrik.
|
||||
|
||||
Args:
|
||||
metric_name: Name der Metrik
|
||||
value: Wert der Metrik
|
||||
tags: Optional - Zusätzliche Tags
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_account_creation_timeline(self,
|
||||
hours: int = 24,
|
||||
platform: Optional[str] = None) -> Dict[str, Any]:
|
||||
"""
|
||||
Holt Timeline der Account-Erstellungen.
|
||||
|
||||
Args:
|
||||
hours: Anzahl Stunden zurück
|
||||
platform: Optional - Spezifische Plattform
|
||||
|
||||
Returns:
|
||||
Timeline-Daten für Visualisierung
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def analyze_failure_patterns(self,
|
||||
timeframe: Optional[timedelta] = None) -> Dict[str, Any]:
|
||||
"""
|
||||
Analysiert Muster in Fehlern.
|
||||
|
||||
Args:
|
||||
timeframe: Optional - Zeitrahmen für Analyse
|
||||
|
||||
Returns:
|
||||
Dictionary mit Fehler-Mustern und Insights
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_platform_comparison(self,
|
||||
timeframe: Optional[timedelta] = None) -> Dict[str, Any]:
|
||||
"""
|
||||
Vergleicht Performance zwischen Plattformen.
|
||||
|
||||
Args:
|
||||
timeframe: Optional - Zeitrahmen für Vergleich
|
||||
|
||||
Returns:
|
||||
Dictionary mit Plattform-Vergleichsdaten
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def export_data(self,
|
||||
format: str = "json",
|
||||
start: Optional[datetime] = None,
|
||||
end: Optional[datetime] = None) -> bytes:
|
||||
"""
|
||||
Exportiert Analytics-Daten.
|
||||
|
||||
Args:
|
||||
format: Export-Format ("json", "csv", "excel")
|
||||
start: Optional - Startdatum
|
||||
end: Optional - Enddatum
|
||||
|
||||
Returns:
|
||||
Exportierte Daten als Bytes
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def cleanup_old_events(self, older_than: datetime) -> int:
|
||||
"""
|
||||
Bereinigt alte Events.
|
||||
|
||||
Args:
|
||||
older_than: Lösche Events älter als dieses Datum
|
||||
|
||||
Returns:
|
||||
Anzahl gelöschter Events
|
||||
"""
|
||||
pass
|
||||
152
domain/services/fingerprint_service.py
Normale Datei
152
domain/services/fingerprint_service.py
Normale Datei
@ -0,0 +1,152 @@
|
||||
"""
|
||||
Fingerprint Service Interface - Domain Service für Browser Fingerprinting
|
||||
"""
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import List, Optional, Dict, Any
|
||||
from datetime import datetime
|
||||
|
||||
from domain.entities.browser_fingerprint import BrowserFingerprint
|
||||
|
||||
|
||||
class IFingerprintService(ABC):
|
||||
"""
|
||||
Interface für Fingerprint Service.
|
||||
Definiert die Geschäftslogik für Browser Fingerprint Management.
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def generate_fingerprint(self,
|
||||
profile_type: Optional[str] = None,
|
||||
platform: Optional[str] = None) -> BrowserFingerprint:
|
||||
"""
|
||||
Generiert einen neuen, realistischen Browser-Fingerprint.
|
||||
|
||||
Args:
|
||||
profile_type: Optional - Typ des Profils (z.B. "mobile", "desktop")
|
||||
platform: Optional - Zielplattform (z.B. "instagram", "tiktok")
|
||||
|
||||
Returns:
|
||||
Neuer Browser-Fingerprint
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def rotate_fingerprint(self,
|
||||
current: BrowserFingerprint,
|
||||
rotation_strategy: str = "gradual") -> BrowserFingerprint:
|
||||
"""
|
||||
Rotiert einen bestehenden Fingerprint für mehr Anonymität.
|
||||
|
||||
Args:
|
||||
current: Aktueller Fingerprint
|
||||
rotation_strategy: Strategie für Rotation ("gradual", "complete", "minimal")
|
||||
|
||||
Returns:
|
||||
Neuer rotierter Fingerprint
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def validate_fingerprint(self, fingerprint: BrowserFingerprint) -> tuple[bool, List[str]]:
|
||||
"""
|
||||
Validiert einen Fingerprint auf Konsistenz und Realismus.
|
||||
|
||||
Args:
|
||||
fingerprint: Zu validierender Fingerprint
|
||||
|
||||
Returns:
|
||||
Tuple aus (ist_valide, liste_von_problemen)
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def save_fingerprint(self, fingerprint: BrowserFingerprint) -> None:
|
||||
"""
|
||||
Speichert einen Fingerprint für spätere Verwendung.
|
||||
|
||||
Args:
|
||||
fingerprint: Zu speichernder Fingerprint
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def load_fingerprint(self, fingerprint_id: str) -> Optional[BrowserFingerprint]:
|
||||
"""
|
||||
Lädt einen gespeicherten Fingerprint.
|
||||
|
||||
Args:
|
||||
fingerprint_id: ID des Fingerprints
|
||||
|
||||
Returns:
|
||||
Fingerprint oder None wenn nicht gefunden
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_fingerprint_pool(self,
|
||||
count: int = 10,
|
||||
platform: Optional[str] = None) -> List[BrowserFingerprint]:
|
||||
"""
|
||||
Holt einen Pool von Fingerprints für Rotation.
|
||||
|
||||
Args:
|
||||
count: Anzahl der gewünschten Fingerprints
|
||||
platform: Optional - Filter für spezifische Plattform
|
||||
|
||||
Returns:
|
||||
Liste von Fingerprints
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def apply_fingerprint(self,
|
||||
browser_context: Any,
|
||||
fingerprint: BrowserFingerprint) -> None:
|
||||
"""
|
||||
Wendet einen Fingerprint auf einen Browser-Kontext an.
|
||||
|
||||
Args:
|
||||
browser_context: Playwright Browser Context
|
||||
fingerprint: Anzuwendender Fingerprint
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def detect_fingerprinting(self, page_content: str) -> Dict[str, Any]:
|
||||
"""
|
||||
Erkennt Fingerprinting-Versuche auf einer Webseite.
|
||||
|
||||
Args:
|
||||
page_content: HTML oder JavaScript Content der Seite
|
||||
|
||||
Returns:
|
||||
Dictionary mit erkannten Fingerprinting-Techniken
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_fingerprint_score(self, fingerprint: BrowserFingerprint) -> float:
|
||||
"""
|
||||
Bewertet die Qualität/Einzigartigkeit eines Fingerprints.
|
||||
|
||||
Args:
|
||||
fingerprint: Zu bewertender Fingerprint
|
||||
|
||||
Returns:
|
||||
Score zwischen 0.0 (schlecht) und 1.0 (gut)
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def cleanup_old_fingerprints(self, older_than: datetime) -> int:
|
||||
"""
|
||||
Bereinigt alte, nicht mehr verwendete Fingerprints.
|
||||
|
||||
Args:
|
||||
older_than: Lösche Fingerprints älter als dieses Datum
|
||||
|
||||
Returns:
|
||||
Anzahl gelöschter Fingerprints
|
||||
"""
|
||||
pass
|
||||
125
domain/services/rate_limit_service.py
Normale Datei
125
domain/services/rate_limit_service.py
Normale Datei
@ -0,0 +1,125 @@
|
||||
"""
|
||||
Rate Limit Service Interface - Domain Service für Rate Limiting
|
||||
"""
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional, List, Dict, Any
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from domain.value_objects.action_timing import ActionTiming, ActionType
|
||||
from domain.entities.rate_limit_policy import RateLimitPolicy
|
||||
|
||||
|
||||
class IRateLimitService(ABC):
|
||||
"""
|
||||
Interface für Rate Limit Service.
|
||||
Definiert die Geschäftslogik für adaptives Rate Limiting.
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def calculate_delay(self, action_type: ActionType, context: Optional[Dict[str, Any]] = None) -> float:
|
||||
"""
|
||||
Berechnet die optimale Verzögerung für eine Aktion.
|
||||
|
||||
Args:
|
||||
action_type: Typ der auszuführenden Aktion
|
||||
context: Optionaler Kontext (z.B. Platform, Session-ID)
|
||||
|
||||
Returns:
|
||||
Verzögerung in Sekunden
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def record_action(self, timing: ActionTiming) -> None:
|
||||
"""
|
||||
Zeichnet eine ausgeführte Aktion für Analyse auf.
|
||||
|
||||
Args:
|
||||
timing: Timing-Informationen der Aktion
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def detect_rate_limit(self, response: Any) -> bool:
|
||||
"""
|
||||
Erkennt ob eine Response auf Rate Limiting hindeutet.
|
||||
|
||||
Args:
|
||||
response: HTTP Response oder Browser-Seite
|
||||
|
||||
Returns:
|
||||
True wenn Rate Limit erkannt wurde
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_policy(self, action_type: ActionType) -> RateLimitPolicy:
|
||||
"""
|
||||
Holt die aktuelle Rate Limit Policy für einen Action Type.
|
||||
|
||||
Args:
|
||||
action_type: Typ der Aktion
|
||||
|
||||
Returns:
|
||||
Rate Limit Policy
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_policy(self, action_type: ActionType, policy: RateLimitPolicy) -> None:
|
||||
"""
|
||||
Aktualisiert die Rate Limit Policy für einen Action Type.
|
||||
|
||||
Args:
|
||||
action_type: Typ der Aktion
|
||||
policy: Neue Policy
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_statistics(self,
|
||||
action_type: Optional[ActionType] = None,
|
||||
timeframe: Optional[timedelta] = None) -> Dict[str, Any]:
|
||||
"""
|
||||
Holt Statistiken über Rate Limiting.
|
||||
|
||||
Args:
|
||||
action_type: Optional - nur für spezifischen Action Type
|
||||
timeframe: Optional - nur für bestimmten Zeitraum
|
||||
|
||||
Returns:
|
||||
Dictionary mit Statistiken
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def reset_statistics(self) -> None:
|
||||
"""Setzt alle gesammelten Statistiken zurück."""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def is_action_allowed(self, action_type: ActionType) -> bool:
|
||||
"""
|
||||
Prüft ob eine Aktion basierend auf Rate Limits erlaubt ist.
|
||||
|
||||
Args:
|
||||
action_type: Typ der Aktion
|
||||
|
||||
Returns:
|
||||
True wenn Aktion erlaubt ist
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def wait_if_needed(self, action_type: ActionType) -> float:
|
||||
"""
|
||||
Wartet die notwendige Zeit bevor eine Aktion ausgeführt werden kann.
|
||||
|
||||
Args:
|
||||
action_type: Typ der Aktion
|
||||
|
||||
Returns:
|
||||
Tatsächlich gewartete Zeit in Sekunden
|
||||
"""
|
||||
pass
|
||||
In neuem Issue referenzieren
Einen Benutzer sperren