kcg-ai-monitoring/prediction/tests
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
..
test_dark_suspicion_params.py feat(prediction): Phase 2 PoC #1 — dark_suspicion 모델 외부화 2026-04-20 08:19:57 +09:00
test_gear_parent_episode.py feat: S2 prediction 분석 엔진 모노레포 이식 2026-04-07 12:56:51 +09:00
test_gear_parent_inference.py feat: S2 prediction 분석 엔진 모노레포 이식 2026-04-07 12:56:51 +09:00
test_gear_violation_params.py feat(prediction): Phase 2 PoC 2~5 — gear_violation/transshipment/risk/pair_trawl 2026-04-20 10:11:16 +09:00
test_models_core.py feat(prediction): Phase 1-2 detection model registry + snapshot 관찰 보강 2026-04-20 08:07:29 +09:00
test_pair_trawl_params.py feat(prediction): Phase 2 PoC 2~5 — gear_violation/transshipment/risk/pair_trawl 2026-04-20 10:11:16 +09:00
test_risk_composite_params.py feat(prediction): Phase 2 PoC 2~5 — gear_violation/transshipment/risk/pair_trawl 2026-04-20 10:11:16 +09:00
test_stats_aggregator_hour_boundary.py fix(prediction): stats_aggregator hour 경계 silent 누락 복구 2026-04-20 13:32:44 +09:00
test_time_bucket.py feat: S2 prediction 분석 엔진 모노레포 이식 2026-04-07 12:56:51 +09:00
test_transshipment_params.py feat(prediction): Phase 2 PoC 2~5 — gear_violation/transshipment/risk/pair_trawl 2026-04-20 10:11:16 +09:00