kcg-ai-monitoring/prediction/pipeline/behavior.py
htlee e2fc355b2c feat: S2 prediction 분석 엔진 모노레포 이식
iran prediction 47개 Python 파일을 prediction/ 디렉토리로 복제:
- algorithms/ 14개 분석 알고리즘 (어구추론, 다크베셀, 스푸핑, 환적, 위험도 등)
- pipeline/ 7단계 분류 파이프라인
- cache/vessel_store (24h 슬라이딩 윈도우)
- db/ 어댑터 (snpdb 원본조회, kcgdb 결과저장)
- chat/ AI 채팅 (Ollama, 후순위)
- data/ 정적 데이터 (기선, 특정어업수역 GeoJSON)

config.py를 kcgaidb로 재구성 (DB명, 사용자, 비밀번호)
DB 연결 검증 완료 (kcgaidb 37개 테이블 접근 확인)
Makefile에 dev-prediction / dev-all 타겟 추가
CLAUDE.md에 prediction 섹션 추가

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 12:56:51 +09:00

32 lines
929 B
Python

import pandas as pd
from pipeline.constants import SOG_STATIONARY_MAX, SOG_FISHING_MAX
class BehaviorDetector:
"""
속도 기반 3단계 행동 분류 (Yan et al. 2022, Natale et al. 2015)
정박(STATIONARY) / 조업(FISHING) / 항행(SAILING)
"""
@staticmethod
def classify_point(sog: float) -> str:
if sog < SOG_STATIONARY_MAX:
return 'STATIONARY'
elif sog <= SOG_FISHING_MAX:
return 'FISHING'
else:
return 'SAILING'
def detect(self, df: pd.DataFrame) -> pd.DataFrame:
df = df.copy()
df['state'] = df['sog'].apply(self.classify_point)
return df
@staticmethod
def compute_fishing_ratio(df_vessel: pd.DataFrame) -> float:
total = len(df_vessel)
if total == 0:
return 0.0
fishing = (df_vessel['state'] == 'FISHING').sum()
return round(fishing / total * 100, 2)