refactor(scoring): persist weights in DB table, replace mutable Settings with scoring_config_service
This commit is contained in:
@@ -19,6 +19,7 @@ from app.models.coverage_snapshot import CoverageSnapshot, SnapshotTechniqueStat
|
||||
from app.models.jira_link import JiraLink, JiraLinkEntityType, JiraSyncDirection
|
||||
from app.models.worklog import Worklog
|
||||
from app.models.osint_item import OsintItem
|
||||
from app.models.scoring_config import ScoringConfig
|
||||
from app.models.enums import TechniqueStatus, TestState, TestResult, TeamSide
|
||||
|
||||
__all__ = [
|
||||
@@ -31,6 +32,6 @@ __all__ = [
|
||||
"ComplianceFramework", "ComplianceControl", "ComplianceControlMapping",
|
||||
"CoverageSnapshot", "SnapshotTechniqueState",
|
||||
"JiraLink", "JiraLinkEntityType", "JiraSyncDirection",
|
||||
"Worklog", "OsintItem",
|
||||
"Worklog", "OsintItem", "ScoringConfig",
|
||||
"TechniqueStatus", "TestState", "TestResult", "TeamSide",
|
||||
]
|
||||
|
||||
24
backend/app/models/scoring_config.py
Normal file
24
backend/app/models/scoring_config.py
Normal file
@@ -0,0 +1,24 @@
|
||||
"""ScoringConfig — single-row table for persisted scoring weights.
|
||||
|
||||
Replaces the mutable-settings approach where PATCH /scores/config
|
||||
mutated the in-process ``Settings`` object (lost on restart).
|
||||
"""
|
||||
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import Column, Float, DateTime, func
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class ScoringConfig(Base):
|
||||
__tablename__ = "scoring_config"
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
weight_tests = Column(Float, nullable=False, default=40.0)
|
||||
weight_detection_rules = Column(Float, nullable=False, default=20.0)
|
||||
weight_d3fend = Column(Float, nullable=False, default=15.0)
|
||||
weight_freshness = Column(Float, nullable=False, default=15.0)
|
||||
weight_platform_diversity = Column(Float, nullable=False, default=10.0)
|
||||
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
Reference in New Issue
Block a user