diff --git a/src/Model/BoundaryCondition/BoundaryCondition.py b/src/Model/BoundaryCondition/BoundaryCondition.py index 93c6bada..25d0fd86 100644 --- a/src/Model/BoundaryCondition/BoundaryCondition.py +++ b/src/Model/BoundaryCondition/BoundaryCondition.py @@ -314,7 +314,6 @@ class BoundaryCondition(SQLSubModel): ind = 0 for d in self._data: - print(d) data["ind"] = ind d._db_save(execute, data) diff --git a/src/Model/Geometry/PointXYZ.py b/src/Model/Geometry/PointXYZ.py index 14243d7f..9c62e0ca 100644 --- a/src/Model/Geometry/PointXYZ.py +++ b/src/Model/Geometry/PointXYZ.py @@ -16,6 +16,8 @@ # -*- coding: utf-8 -*- +import logging + from math import dist import numpy as np @@ -23,6 +25,8 @@ from Model.Tools.PamhyrDB import SQLSubModel from Model.Scenario import Scenario from Model.Geometry.Point import Point +logger = logging.getLogger() + class PointXYZ(Point, SQLSubModel): _sub_classes = [] @@ -116,6 +120,12 @@ class PointXYZ(Point, SQLSubModel): pid = next(it) profile_id = next(it) + if profile_id not in profiles: + logger.warning( + f"This point as no associated profile ({profile_id})" + ) + continue + execute( f"UPDATE {table} " + f"SET profile = {profiles[profile_id]} " + diff --git a/src/Model/Geometry/ProfileXYZ.py b/src/Model/Geometry/ProfileXYZ.py index ef4d80c9..3469b4ac 100644 --- a/src/Model/Geometry/ProfileXYZ.py +++ b/src/Model/Geometry/ProfileXYZ.py @@ -21,7 +21,7 @@ import numpy as np from typing import List from functools import reduce -from tools import timer +from tools import timer, flatten from shapely import geometry from Model.Tools.PamhyrDB import SQLSubModel @@ -129,6 +129,8 @@ class ProfileXYZ(Profile, SQLSubModel): id2pid = data['id2pid'] reachs = id2pid['river_reach'] + cls._db_update_cleanup_points(execute) + cls.update_db_add_pamhyr_id(execute, table, data) Scenario.update_db_add_scenario(execute, table) @@ -152,6 +154,24 @@ class ProfileXYZ(Profile, SQLSubModel): sl = id2pid['sedimentary_layer'] cls._db_update_to_0_1_0_set_sl_pid(execute, table, sl) + @classmethod + def _db_update_cleanup_points(cls, execute): + profiles = set( + map( + str, + flatten( + execute( + "SELECT id FROM geometry_profileXYZ" + ) + ) + ) + ) + + execute( + "DELETE FROM geometry_pointXYZ " + + f"WHERE profile NOT IN ({', '.join(profiles)})" + ) + @classmethod def _db_update_to_0_1_0_set_sl_pid(cls, execute, table, sl): els = execute(