From c498ed2d962db7e08c01823f7d5d65990fad32af Mon Sep 17 00:00:00 2001 From: Dylan Jeannin Date: Mon, 13 Apr 2026 13:10:50 +0200 Subject: [PATCH] add d50/sigma in database + load/save data in UI --- .../BoundaryCondition/BoundaryCondition.py | 50 +++++++++++++++++-- src/Model/Study.py | 2 +- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/Model/BoundaryCondition/BoundaryCondition.py b/src/Model/BoundaryCondition/BoundaryCondition.py index 86f2cb6e..d1da739b 100644 --- a/src/Model/BoundaryCondition/BoundaryCondition.py +++ b/src/Model/BoundaryCondition/BoundaryCondition.py @@ -232,6 +232,8 @@ class BoundaryCondition(SQLSubModel): type TEXT NOT NULL, tab TEXT NOT NULL, node INTEGER, + d50 REAL DEFAULT 0.002, + sigma REAL DEFAULT 1, {Scenario.create_db_add_scenario()}, {Scenario.create_db_add_scenario_fk()}, FOREIGN KEY(node) REFERENCES river_node(pamhyr_id), @@ -258,6 +260,17 @@ class BoundaryCondition(SQLSubModel): "ADD COLUMN deleted BOOLEAN NOT NULL DEFAULT FALSE" ) + if major == "0" and int(minor) <= 2: + if int(release) < 4: + execute( + "ALTER TABLE boundary_condition " + + "ADD COLUMN d50 REAL DEFAULT 0.002" + ) + execute( + "ALTER TABLE boundary_condition " + + "ADD COLUMN sigma REAL DEFAULT 1" + ) + return cls._update_submodel(execute, version, data) @classmethod @@ -316,7 +329,7 @@ class BoundaryCondition(SQLSubModel): return new table = execute( - "SELECT pamhyr_id, deleted, name, type, node, scenario " + + "SELECT pamhyr_id, deleted, name, type, node, d50, sigma, scenario " + "FROM boundary_condition " + f"WHERE tab = '{tab}' " + f"AND scenario = {scenario.id} " + @@ -331,6 +344,8 @@ class BoundaryCondition(SQLSubModel): name = next(it) t = next(it) node = next(it) + d50 = next(it) + sigma = next(it) owner_scenario = next(it) ctor = cls._get_ctor_from_type(t) @@ -342,7 +357,9 @@ class BoundaryCondition(SQLSubModel): ) if deleted: bc.set_as_deleted() - + if t=="SL": + bc.d50 = d50 + bc.sigma = sigma bc.node = None if node != -1: bc.node = next(filter(lambda n: n.id == node, nodes), None) @@ -374,16 +391,23 @@ class BoundaryCondition(SQLSubModel): node = -1 if self._node is not None: node = self._node.id - + + d50 = 0.002 + sigma = 1 + if self._type == "SL": + d50 = self._d50 + sigma = self._sigma + execute( "INSERT INTO " + "boundary_condition(" + - "pamhyr_id, deleted, name, type, tab, node, scenario" + + "pamhyr_id, deleted, name, type, tab, node, d50, sigma, scenario" + ") " + "VALUES (" + f"{self._pamhyr_id}, {self._db_format(self.is_deleted())}, " + f"'{self._db_format(self._name)}', " + f"'{self._db_format(self._type)}', '{tab}', {node}, " + + f"{d50}, {sigma}, " + f"{self._status.scenario_id}" + ")" ) @@ -467,6 +491,24 @@ class BoundaryCondition(SQLSubModel): def has_node(self): return self._node is not None + + @property + def d50(self): + return self._d50 + + @d50.setter + def d50(self, value): + self._d50 = float(value) + self.modified() + + @property + def sigma(self): + return self._sigma + + @sigma.setter + def sigma(self, value): + self._sigma = float(value) + self.modified() @property def header(self): diff --git a/src/Model/Study.py b/src/Model/Study.py index f32e90bf..23113ab9 100644 --- a/src/Model/Study.py +++ b/src/Model/Study.py @@ -37,7 +37,7 @@ logger = logging.getLogger() class Study(SQLModel): - _version = "0.2.3" + _version = "0.2.4" _sub_classes = [ Scenario,