런타임 override 완성 (params 인자 + 내부 상수 교체): - gear_violation_g01_g06 (GEAR, tier 4) · G01~G06 점수 + signal_cycling(gap_min/min_count) · gear_drift_threshold_nm + fixed_gear_types + fishery_code_allowed_gear · _detect_signal_cycling_count 도입 (기존 _detect_signal_cycling 보존) 카탈로그 + 관찰 (DEFAULT_PARAMS 노출 + Adapter 집계, 런타임 교체는 후속 PR): - transshipment_5stage (TRANSSHIP, tier 4) — 5단계 필터 임계 - risk_composite (META, tier 3) — 경량+파이프라인 가중치 - pair_trawl_tier (GEAR, tier 4) — STRONG/PROBABLE/SUSPECT 임계 각 모델 공통: - prediction/algorithms/*.py: DEFAULT_PARAMS 상수 추가 - models_core/registered/*_model.py: BaseDetectionModel Adapter - models_core/seeds/v1_<model>.sql: DRAFT seed (호출자 트랜잭션 제어) - tests/test_<model>_params.py: Python ↔ 모듈 상수 ↔ seed SQL 정적 일치 검증 통합 seed: models_core/seeds/v1_phase2_all.sql (\i 로 5 모델 일괄 시드) 검증: - 30/30 테스트 통과 (Phase 1-2 15 + dark 5 + Phase 2 신규 10) - 운영 DB 5 모델 개별 + 일괄 seed dry-run 통과 (BEGIN/ROLLBACK 격리) - 5 모델 모두 tier/category 정렬 확인: dark_suspicion(3) / risk_composite(3) / gear_violation_g01_g06(4) / pair_trawl_tier(4) / transshipment_5stage(4) 후속: - transshipment/risk/pair_trawl 런타임 override 활성화 (헬퍼 params 전파) - Phase 3 백엔드 API (DetectionModelController + 승격 엔드포인트) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
67 lines
2.5 KiB
Python
67 lines
2.5 KiB
Python
"""Phase 2 PoC #5 — pair_trawl_tier DEFAULT_PARAMS ↔ seed SQL 정적 일치."""
|
|
from __future__ import annotations
|
|
|
|
import importlib
|
|
import json
|
|
import os
|
|
import sys
|
|
import types
|
|
import unittest
|
|
|
|
if 'pandas' not in sys.modules:
|
|
pd_stub = types.ModuleType('pandas')
|
|
pd_stub.DataFrame = type('DataFrame', (), {})
|
|
pd_stub.Timestamp = type('Timestamp', (), {})
|
|
sys.modules['pandas'] = pd_stub
|
|
|
|
if 'pydantic_settings' not in sys.modules:
|
|
stub = types.ModuleType('pydantic_settings')
|
|
|
|
class _S:
|
|
def __init__(self, **kw):
|
|
for name, value in self.__class__.__dict__.items():
|
|
if name.isupper():
|
|
setattr(self, name, kw.get(name, value))
|
|
|
|
stub.BaseSettings = _S
|
|
sys.modules['pydantic_settings'] = stub
|
|
|
|
if 'algorithms' not in sys.modules:
|
|
pkg = types.ModuleType('algorithms')
|
|
pkg.__path__ = [os.path.join(os.path.dirname(__file__), '..', 'algorithms')]
|
|
sys.modules['algorithms'] = pkg
|
|
|
|
|
|
class PairTrawlParamsTest(unittest.TestCase):
|
|
|
|
def test_seed_matches_default(self):
|
|
pt = importlib.import_module('algorithms.pair_trawl')
|
|
seed_path = os.path.join(
|
|
os.path.dirname(__file__), '..',
|
|
'models_core', 'seeds', 'v1_pair_trawl.sql',
|
|
)
|
|
with open(seed_path, 'r', encoding='utf-8') as f:
|
|
sql = f.read()
|
|
start = sql.index('$json$') + len('$json$')
|
|
end = sql.index('$json$', start)
|
|
params = json.loads(sql[start:end].strip())
|
|
self.assertEqual(params, pt.PAIR_TRAWL_DEFAULT_PARAMS)
|
|
|
|
def test_default_values_match_module_constants(self):
|
|
pt = importlib.import_module('algorithms.pair_trawl')
|
|
d = pt.PAIR_TRAWL_DEFAULT_PARAMS
|
|
self.assertEqual(d['strong']['proximity_nm'], pt.PROXIMITY_NM)
|
|
self.assertEqual(d['strong']['sog_delta_max'], pt.SOG_DELTA_MAX)
|
|
self.assertEqual(d['strong']['cog_delta_max'], pt.COG_DELTA_MAX)
|
|
self.assertEqual(d['strong']['min_sync_cycles'], pt.MIN_SYNC_CYCLES)
|
|
self.assertEqual(d['strong']['simultaneous_gap_min'], pt.SIMULTANEOUS_GAP_MIN)
|
|
self.assertEqual(d['probable']['min_block_cycles'], pt.PROBABLE_MIN_BLOCK_CYCLES)
|
|
self.assertEqual(d['probable']['min_sync_ratio'], pt.PROBABLE_MIN_SYNC_RATIO)
|
|
self.assertEqual(d['suspect']['min_block_cycles'], pt.SUSPECT_MIN_BLOCK_CYCLES)
|
|
self.assertEqual(d['suspect']['min_sync_ratio'], pt.SUSPECT_MIN_SYNC_RATIO)
|
|
self.assertEqual(d['candidate_scan']['cell_size_deg'], pt.CELL_SIZE)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|