fix: 1h 활성 판정 parent_name 전체 합산 기준 #220

병합
htlee bugfix/1h-active-parent-sum 에서 develop 로 2 commits 를 머지했습니다 2026-04-01 16:48:09 +09:00
Showing only changes of commit b04e96c457 - Show all commits

파일 보기

@ -414,6 +414,16 @@ def build_all_group_snapshots(
# ── GEAR 타입: detect_gear_groups 결과 → 1h/6h 듀얼 스냅샷 ────
gear_groups = detect_gear_groups(vessel_store, now=now)
# parent_name 기준 전체 1h 활성 멤버 합산 (서브클러스터 분리 전)
parent_active_1h: dict[str, int] = {}
for group in gear_groups:
pn = group['parent_name']
cnt = sum(
1 for gm in group['members']
if _get_time_bucket_age(gm.get('mmsi'), all_positions, now) <= DISPLAY_STALE_SEC
)
parent_active_1h[pn] = parent_active_1h.get(pn, 0) + cnt
for group in gear_groups:
parent_name: str = group['parent_name']
parent_mmsi: Optional[str] = group['parent_mmsi']
@ -422,17 +432,15 @@ def build_all_group_snapshots(
if not gear_members:
continue
# ── 1h 활성 멤버 필터 ──
# ── 1h 활성 멤버 필터 (이 서브클러스터 내) ──
active_members_1h = [
gm for gm in gear_members
if _get_time_bucket_age(gm.get('mmsi'), all_positions, now) <= DISPLAY_STALE_SEC
]
active_count_1h = len(active_members_1h)
# fallback: 1h < 2이면 time_bucket 최신 2개 유지 (리플레이/일치율 추적용)
# 라이브 현황에서는 active_count_1h로 필터 (fallback 그룹 제외)
# fallback: 서브클러스터 내 1h < 2이면 time_bucket 최신 2개 유지
display_members_1h = active_members_1h
if active_count_1h < 2 and len(gear_members) >= 2:
if len(active_members_1h) < 2 and len(gear_members) >= 2:
sorted_by_age = sorted(
gear_members,
key=lambda gm: _get_time_bucket_age(gm.get('mmsi'), all_positions, now),
@ -447,8 +455,9 @@ def build_all_group_snapshots(
display_members_6h = gear_members
# ── resolution별 스냅샷 생성 ──
# 1h-fb: fallback (실제 1h 활성 < 2) — 리플레이/일치율 추적용, 라이브 현황에서 제외
res_1h = '1h' if active_count_1h >= 2 else '1h-fb'
# 1h-fb: parent_name 전체 1h 활성 < 2 → 리플레이/일치율 추적용, 라이브 현황에서 제외
# parent_name 전체 기준으로 판단 (서브클러스터 분리로 개별 멤버가 적어져도 그룹 전체가 활성이면 1h)
res_1h = '1h' if parent_active_1h.get(parent_name, 0) >= 2 else '1h-fb'
for resolution, members_for_snap in [(res_1h, display_members_1h), ('6h', display_members_6h)]:
if len(members_for_snap) < 2:
continue