uploader-bot/app/core/models/validation/validation_models.py

75 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from __future__ import annotations
import json
from dataclasses import dataclass, asdict, field
from datetime import datetime
from typing import Any, Dict, Optional
def _iso_now() -> str:
return datetime.utcnow().isoformat()
@dataclass
class ValidationResult:
"""
Результат валидации контента/чанков.
"""
ok: bool
reason: Optional[str] = None
details: Dict[str, Any] = field(default_factory=dict)
timestamp: str = field(default_factory=_iso_now)
def to_dict(self) -> Dict[str, Any]:
return asdict(self)
def to_json(self) -> str:
return json.dumps(self.to_dict(), ensure_ascii=False, sort_keys=True)
@dataclass
class ContentSignature:
"""
Информация о подписи контента/объекта.
"""
signature: Optional[str]
public_key_hex: Optional[str]
algorithm: str = "ed25519"
def to_dict(self) -> Dict[str, Any]:
return asdict(self)
@dataclass
class TrustScore:
"""
Итоговый скор доверия (0.0 - 1.0)
"""
node_id: str
score: float
updated_at: str = field(default_factory=_iso_now)
reason: Optional[str] = None
def to_dict(self) -> Dict[str, Any]:
d = asdict(self)
# Нормализация диапазона
d["score"] = max(0.0, min(1.0, float(d["score"])))
return d
@dataclass
class NodeTrust:
"""
Состояние доверия к ноде.
"""
node_id: str
score: float = 0.5
blacklisted: bool = False
manual_override: bool = False
note: Optional[str] = None
updated_at: str = field(default_factory=_iso_now)
def to_dict(self) -> Dict[str, Any]:
d = asdict(self)
d["score"] = max(0.0, min(1.0, float(d["score"])))
return d