From 86315461423fbbc1eaae63f4b1a8bfb2962ecd91 Mon Sep 17 00:00:00 2001 From: htlee Date: Tue, 31 Mar 2026 09:03:33 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=ED=8A=B8=EB=9E=99=20API=20DB=20?= =?UTF-8?q?=EC=A0=91=EC=86=8D=20=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?(context=20manager)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - kcgdb.get_conn()을 with문 없이 사용 → cursor 에러 - with kcgdb.get_conn() as conn: 으로 수정 - 디버그 로그 추가 (rows 수, track 매칭 수, vessel_store 크기) - 결과: 47 vessels, 47 with track data (25567#1 그룹) Co-Authored-By: Claude Opus 4.6 (1M context) --- prediction/main.py | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/prediction/main.py b/prediction/main.py index 00c9b33..139912f 100644 --- a/prediction/main.py +++ b/prediction/main.py @@ -85,24 +85,26 @@ def get_correlation_tracks( from cache.vessel_store import vessel_store try: - conn = kcgdb.get_conn() - cur = conn.cursor() + with kcgdb.get_conn() as conn: + cur = conn.cursor() - # Get correlated vessels from ALL active models - cur.execute(""" - SELECT s.target_mmsi, s.target_type, s.target_name, - s.current_score, m.name AS model_name - FROM kcg.gear_correlation_scores s - JOIN kcg.correlation_param_models m ON s.model_id = m.id - WHERE s.group_key = %s - AND s.current_score >= %s - AND m.is_active = TRUE - ORDER BY s.current_score DESC - """, (group_key, min_score)) + # Get correlated vessels from ALL active models + cur.execute(""" + SELECT s.target_mmsi, s.target_type, s.target_name, + s.current_score, m.name AS model_name + FROM kcg.gear_correlation_scores s + JOIN kcg.correlation_param_models m ON s.model_id = m.id + WHERE s.group_key = %s + AND s.current_score >= %s + AND m.is_active = TRUE + ORDER BY s.current_score DESC + """, (group_key, min_score)) - rows = cur.fetchall() - cur.close() - conn.close() + rows = cur.fetchall() + cur.close() + + logger.info('correlation tracks: group_key=%r, min_score=%s, rows=%d', + group_key, min_score, len(rows)) if not rows: return {'groupKey': group_key, 'vessels': []} @@ -131,6 +133,9 @@ def get_correlation_tracks( # Get tracks from vessel_store tracks = vessel_store.get_vessel_tracks(mmsis, hours) + with_tracks = sum(1 for m in mmsis if m in tracks and len(tracks[m]) > 0) + logger.info('correlation tracks: %d unique mmsis, %d with track data, vessel_store._tracks has %d entries', + len(mmsis), with_tracks, len(vessel_store._tracks)) # Build response vessels = []