From 263069a5c5addcb8309ca474fd8b2f751519503e Mon Sep 17 00:00:00 2001 From: schroedtert Date: Thu, 14 Mar 2024 16:04:05 +0100 Subject: [PATCH] Insert current geometry in DB version --- .../jupedsim/jupedsim/sqlite_serialization.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/python_modules/jupedsim/jupedsim/sqlite_serialization.py b/python_modules/jupedsim/jupedsim/sqlite_serialization.py index e37d97d4f..5b642b64e 100644 --- a/python_modules/jupedsim/jupedsim/sqlite_serialization.py +++ b/python_modules/jupedsim/jupedsim/sqlite_serialization.py @@ -85,6 +85,7 @@ def begin_writing(self, simulation: Simulation) -> None: " hash INTEGER NOT NULL, " " wkt TEXT NOT NULL)" ) + cur.execute("CREATE UNIQUE INDEX geometry_hash on geometry( hash)") cur.execute( "INSERT INTO geometry VALUES(?, ?)", (hash(geo), geo), @@ -154,9 +155,16 @@ def write_iteration_state(self, simulation: Simulation) -> None: ("ymax", str(max(ymax, float(old_ymax)))), ], ) + + geo_wkt = simulation.get_geometry().as_wkt() + geo_hash = hash(geo_wkt) + cur.execute( + "INSERT OR IGNORE INTO geometry(hash, wkt) VALUES(?,?)", + (geo_hash, geo_wkt), + ) cur.execute( "INSERT INTO frame_data VALUES(?, ?)", - (frame, hash(simulation.get_geometry().as_wkt())), + (frame, geo_hash), ) cur.execute("COMMIT") except sqlite3.Error as e: