kcg-ai-monitoring/prediction
htlee 7ab6baeed2 fix(prediction): stats_aggregator hour 경계 silent 누락 복구
배경: prediction 5분 interval 이지만 한 사이클 평균 13분 소요라
사이클이 hour 경계를 넘나드는 경우(12:55 시작 → 13:08 완료)가 흔하다.
이 때 사이클 내 생성된 이벤트(occurred_at=12:57)가 aggregate_hourly
호출 시점(now_kst=13:08) 기준 현재 hour=13:00 만 UPSERT 되어
12:00 hour 는 이전 사이클 snapshot 으로 stale 유지되는 silent drop.

실제 포착: 2026-04-20 12:50 CRITICAL GEAR_IDENTITY_COLLISION 이벤트가
prediction_stats_hourly.by_category 12:00 slot 에서 누락. Phase 1-2
snapshot 의 C1 drift 섹션이 only_in_events=GEAR_IDENTITY_COLLISION 으로 탐지.

수정:
- _aggregate_one_hour(conn, hour_start, updated_at): 단일 hour UPSERT 추출
- aggregate_hourly(): 호출 시마다 previous→current 순서로 2번 집계
  · UPSERT 라 idempotent
  · 반환값은 현재 hour (하위 호환)
  · target_hour 지정 케이스도 ±1h 재집계

검증:
- 3 유닛테스트 (경계 호출 2건 / 반환값 / 일 경계) 전수 통과
- 운영 수동 재집계로 12:00 slot GEAR_IDENTITY_COLLISION: 1 복구
- snapshot 재실행 시 C1 drift 0 확인

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-20 13:32:44 +09:00
..
algorithms feat(prediction): Phase 2 PoC 2~5 — gear_violation/transshipment/risk/pair_trawl 2026-04-20 10:11:16 +09:00
cache feat: prediction 알고리즘 재설계 + 프론트 CRUD 권한 가드 보완 (#29) 2026-04-13 11:08:11 +09:00
chat feat: S2 prediction 분석 엔진 모노레포 이식 2026-04-07 12:56:51 +09:00
data feat: prediction 알고리즘 재설계 + 프론트 CRUD 권한 가드 보완 (#29) 2026-04-13 11:08:11 +09:00
db feat(prediction): Phase 1-2 detection model registry + snapshot 관찰 보강 2026-04-20 08:07:29 +09:00
models feat(prediction): vessel_analysis_results 에 분석 시점 lat/lon 저장 2026-04-16 14:30:49 +09:00
models_core feat(prediction): Phase 2 PoC 2~5 — gear_violation/transshipment/risk/pair_trawl 2026-04-20 10:11:16 +09:00
output fix(prediction): stats_aggregator hour 경계 silent 누락 복구 2026-04-20 13:32:44 +09:00
pipeline refactor(prediction): 사이클 스테이지 에러 경계 도입 (Phase 0-1) 2026-04-17 11:28:30 +09:00
scripts feat(prediction): Phase 1-2 detection model registry + snapshot 관찰 보강 2026-04-20 08:07:29 +09:00
tests fix(prediction): stats_aggregator hour 경계 silent 누락 복구 2026-04-20 13:32:44 +09:00
config.py feat: prediction 알고리즘 재설계 + 프론트 CRUD 권한 가드 보완 (#29) 2026-04-13 11:08:11 +09:00
env.example feat: S2 prediction 분석 엔진 모노레포 이식 2026-04-07 12:56:51 +09:00
fleet_tracker.py feat(detection): GEAR_IDENTITY_COLLISION 탐지 패턴 추가 2026-04-17 06:53:12 +09:00
main.py feat(detection): DAR-03 어구 탐지 워크플로우 + 모선 검토 UI + 24h 리플레이 통합 2026-04-15 13:26:15 +09:00
requirements.txt feat: S2 prediction 분석 엔진 모노레포 이식 2026-04-07 12:56:51 +09:00
scheduler.py feat(prediction): Phase 1-2 detection model registry + snapshot 관찰 보강 2026-04-20 08:07:29 +09:00
time_bucket.py feat: S2 prediction 분석 엔진 모노레포 이식 2026-04-07 12:56:51 +09:00