kcg-ai-monitoring/prediction/output
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
..
__init__.py feat: S3 prediction 신규 출력 모듈 5종 + scheduler 통합 2026-04-07 13:00:50 +09:00
alert_dispatcher.py feat: S3 prediction 신규 출력 모듈 5종 + scheduler 통합 2026-04-07 13:00:50 +09:00
event_generator.py feat(detection): GEAR_IDENTITY_COLLISION 탐지 패턴 추가 2026-04-17 06:53:12 +09:00
kpi_writer.py fix: prediction 5가지 이슈 수정 — 모든 파이프라인 정상 동작 2026-04-08 06:47:53 +09:00
stats_aggregator.py fix(prediction): stats_aggregator hour 경계 silent 누락 복구 2026-04-20 13:32:44 +09:00
violation_classifier.py feat(prediction): G-02 금어기 + G-03 미등록 어구 탐지 추가 (A-4) 2026-04-16 09:12:07 +09:00