From 746ddb7111bbc85511b2ac76c799a4a2a2ff6869 Mon Sep 17 00:00:00 2001 From: htlee Date: Fri, 20 Mar 2026 13:40:16 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20numpy=20float=20=E2=86=92=20Python=20nat?= =?UTF-8?q?ive=20=EB=B3=80=ED=99=98=20=E2=80=94=20DB=20INSERT=20=EC=8B=9C?= =?UTF-8?q?=20np.float64=20=EC=A7=81=EB=A0=AC=ED=99=94=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 (1M context) --- prediction/models/result.py | 56 ++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/prediction/models/result.py b/prediction/models/result.py index 9792351..e1680a5 100644 --- a/prediction/models/result.py +++ b/prediction/models/result.py @@ -56,29 +56,41 @@ class AnalysisResult: def to_db_tuple(self) -> tuple: import json + + def _f(v: object) -> float: + """numpy float → Python float 변환.""" + return float(v) if v is not None else 0.0 + + def _i(v: object) -> int: + """numpy int → Python int 변환.""" + return int(v) if v is not None else 0 + + # features dict 내부 numpy 값도 변환 + safe_features = {k: float(v) for k, v in self.features.items()} if self.features else {} + return ( - self.mmsi, + str(self.mmsi), self.timestamp, - self.vessel_type, - self.confidence, - self.fishing_pct, - self.cluster_id, - self.season, - self.zone, - self.dist_to_baseline_nm, - self.activity_state, - self.ucaf_score, - self.ucft_score, - self.is_dark, - self.gap_duration_min, - self.spoofing_score, - self.bd09_offset_m, - self.speed_jump_count, - self.cluster_size, - self.is_leader, - self.fleet_role, - self.risk_score, - self.risk_level, - json.dumps(self.features), + str(self.vessel_type), + _f(self.confidence), + _f(self.fishing_pct), + _i(self.cluster_id), + str(self.season), + str(self.zone), + _f(self.dist_to_baseline_nm), + str(self.activity_state), + _f(self.ucaf_score), + _f(self.ucft_score), + bool(self.is_dark), + _i(self.gap_duration_min), + _f(self.spoofing_score), + _f(self.bd09_offset_m), + _i(self.speed_jump_count), + _i(self.cluster_size), + bool(self.is_leader), + str(self.fleet_role), + _i(self.risk_score), + str(self.risk_level), + json.dumps(safe_features), self.analyzed_at, ) -- 2.45.2