diff --git a/src/Model/InitialConditionsAdisTS/InitialConditionsAdisTS.py b/src/Model/InitialConditionsAdisTS/InitialConditionsAdisTS.py new file mode 100644 index 0000000000000000000000000000000000000000..1a8d59c6c300122265357d3057e8967ff5e33484 --- /dev/null +++ b/src/Model/InitialConditionsAdisTS/InitialConditionsAdisTS.py @@ -0,0 +1,29 @@ +# InitialConditionsAdisTS.py -- Pamhyr +# Copyright (C) 2023-2024 INRAE +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +# -*- coding: utf-8 -*- + +import logging +from functools import reduce + +from tools import trace, timer, old_pamhyr_date_to_timestamp + +from Model.Tools.PamhyrDB import SQLSubModel +from Model.Except import NotImplementedMethodeError + +from Model.InitialConditionsAdisTS.InitialConditionsAdisTSSpec import ICAdisTSSpec + +logger = logging.getLogger() diff --git a/src/Model/InitialConditionsAdisTS/InitialConditionsAdisTSList.py b/src/Model/InitialConditionsAdisTS/InitialConditionsAdisTSList.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/Model/InitialConditionsAdisTS/InitialConditionsAdisTSSpec.py b/src/Model/InitialConditionsAdisTS/InitialConditionsAdisTSSpec.py new file mode 100644 index 0000000000000000000000000000000000000000..ab26bd8cd650b7866ce60db8f2b3f9c309faf2b9 --- /dev/null +++ b/src/Model/InitialConditionsAdisTS/InitialConditionsAdisTSSpec.py @@ -0,0 +1,237 @@ +# InitialConditionsAdisTSSpec.py -- Pamhyr +# Copyright (C) 2023-2024 INRAE +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +# -*- coding: utf-8 -*- + +import logging + +from tools import trace, timer + +from Model.Tools.PamhyrDB import SQLSubModel +from Model.Except import NotImplementedMethodeError + +logger = logging.getLogger() + +class ICAdisTSSpec(SQLSubModel): + _sub_classes = [ + ] + _id_cnt = 0 + + def __init__(self, id: int = -1, name: str = "", + status=None): + super(ICAdisTSSpec, self).__init__() + + self._status = status + + if id == -1: + self.id = ICAdisTSSpec._id_cnt + else: + self.id = id + + self._name_section = name + self._reach = None + self._start_kp = None + self._end_kp = None + self._concentration = None + self._eg = None + self._em = None + self._ed = None + self._rate = None + self._enabled = True + + ICAdisTSSpec._id_cnt = max(ICAdisTSSpec._id_cnt + 1, self.id) + + @classmethod + def _db_create(cls, execute): + execute(""" + CREATE TABLE initial_conditions_spec( + id INTEGER NOT NULL PRIMARY KEY, + ic_default INTEGER NOT NULL, + name TEXT NOT NULL, + reach INTEGER NOT NULL, + start_kp REAL NOT NULL, + end_kp REAL NOT NULL, + eg REAL NOT NULL, + em REAL NOT NULL, + ed REAL NOT NULL, + rate REAL NOT NULL, + enabled BOOLEAN NOT NULL, + FOREIGN KEY(ic_default) REFERENCES initial_conditions(id), + FOREIGN KEY(reach) REFERENCES river_reach(id) + ) + """) + + return cls._create_submodel(execute) + + @classmethod + def _db_update(cls, execute, version): + major, minor, release = version.strip().split(".") + if major == minor == "0": + if int(release) < 6: + cls._db_create(execute) + + return True + + @classmethod + def _db_load(cls, execute, data=None): + new = [] + + table = execute( + "SELECT id, ic_default, name, reach, start_kp, end_kp, " + + "eg, em, ed, rate, enabled " + + "FROM initial_conditions_spec " + + f"WHERE ic_default = {data['ic_default_id']} " + ) + + for row in table: + name = row[2] + reach = row[3] + start_kp = row[4] + end_kp = row[5] + eg = row[6] + em = row[7] + ed = row[8] + rate = row[9] + enabled = (row[10] == 1) + + new_spec = [name, reach, start_kp, end_kp, eg, em, ed, rate, enabled] + new.append(new_spec) + + return new + + def _db_save(self, execute, data=None): + ic_default = data['ic_default_id'] + + sql = ( + "INSERT INTO " + + "initial_conditions_spec(id, ic_default, name, reach, " + + "start_kp, end_kp, eg, em, ed, rate, enabled) " + + "VALUES (" + + f"{self.id}, " + + f"{ic_default}, " + + f"'{self._db_format(self._name_section)}', " + + f"{self._reach}, " + + f"{self._start_kp}, " + + f"{self._end_kp}, " + + f"{self._eg}, " + + f"{self._em}, " + + f"{self._ed}, " + + f"{self._rate}, " + + f"{self._enabled}" + + ")" + ) + execute(sql) + + return True + + @property + def name(self): + return self._name_section + + @name.setter + def name(self, name): + self._name_section = name + self._status.modified() + + @property + def reach(self): + return self._reach + + @reach.setter + def reach(self, reach): + self._reach = reach + self._status.modified() + + @property + def start_kp(self): + return self._start_kp + + @start_kp.setter + def start_kp(self, start_kp): + self._start_kp = start_kp + self._status.modified() + + @property + def end_kp(self): + return self._end_kp + + @end_kp.setter + def end_kp(self, end_kp): + self._end_kp = end_kp + self._status.modified() + + @property + def concentration(self): + return self._concentration + + @concentration.setter + def concentration(self, concentration): + self._concentration = concentration + self._status.modified() + + @property + def eg(self): + return self._eg + + @eg.setter + def eg(self, eg): + self._eg = eg + self._status.modified() + + @property + def em(self): + return self._em + + @em.setter + def em(self, em): + self._em = em + self._status.modified() + + @property + def ed(self): + return self._ed + + @ed.setter + def ed(self, ed): + self._ed = ed + self._status.modified() + + @property + def rate(self): + return self._rate + + @rate.setter + def rate(self, rate): + self._rate = rate + self._status.modified() + + @property + def enabled(self): + return self._enabled + + @enabled.setter + def enabled(self, enabled): + self._enabled = enabled + self._status.modified() + + + + + + + + +