mirror of https://gitlab.com/pamhyr/pamhyr2
Compare commits
7 Commits
a3f20796d7
...
4ac86b9acb
| Author | SHA1 | Date |
|---|---|---|
|
|
4ac86b9acb | |
|
|
00c9ecde52 | |
|
|
ae49908a42 | |
|
|
37cf42c524 | |
|
|
c43a26870e | |
|
|
5a6574921a | |
|
|
7fa86c29e7 |
|
|
@ -72,7 +72,7 @@ class Data(SQLSubModel):
|
|||
major, minor, release = version.strip().split(".")
|
||||
|
||||
if major == "0" and int(minor) < 1:
|
||||
cls._db_update_to_0_1_0(execute, data)
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
if major == "0" and minor == "1":
|
||||
if int(release) < 2:
|
||||
|
|
@ -84,7 +84,7 @@ class Data(SQLSubModel):
|
|||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0(cls, execute, data):
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "boundary_condition_data"
|
||||
bcs = data['id2pid']['boundary_condition']
|
||||
|
||||
|
|
@ -105,10 +105,10 @@ class Data(SQLSubModel):
|
|||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||
|
||||
cls._db_update_to_0_1_0_set_bc_pid(execute, table, bcs)
|
||||
cls._db_update_to_0_2_0_set_bc_pid(execute, table, bcs)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0_set_bc_pid(cls, execute, table, bcs):
|
||||
def _db_update_to_0_2_0_set_bc_pid(cls, execute, table, bcs):
|
||||
els = execute(
|
||||
f"SELECT pamhyr_id, bc FROM {table}"
|
||||
)
|
||||
|
|
@ -249,7 +249,7 @@ class BoundaryCondition(SQLSubModel):
|
|||
major, minor, release = version.strip().split(".")
|
||||
|
||||
if major == minor == "0":
|
||||
cls._db_update_to_0_1_0(execute, data)
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
if major == "0" and minor == "1":
|
||||
if int(release) < 2:
|
||||
|
|
@ -261,7 +261,7 @@ class BoundaryCondition(SQLSubModel):
|
|||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0(cls, execute, data):
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "boundary_condition"
|
||||
nodes = data['id2pid']['river_node']
|
||||
|
||||
|
|
@ -281,7 +281,7 @@ class BoundaryCondition(SQLSubModel):
|
|||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||
|
||||
cls._db_update_to_0_1_0_set_node_pid(execute, table, nodes)
|
||||
cls._db_update_to_0_2_0_set_node_pid(execute, table, nodes)
|
||||
|
||||
@classmethod
|
||||
def _get_ctor_from_type(cls, t):
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ from tools import (
|
|||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
from Model.Scenario import Scenario
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
|
@ -52,30 +53,41 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
|||
self._types = [self.time_convert, float]
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute):
|
||||
execute("""
|
||||
CREATE TABLE boundary_condition_adists(
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
def _db_create(cls, execute, ext=""):
|
||||
cls._db_create_bca(execute, ext)
|
||||
cls._db_create_bca_data(execute, ext)
|
||||
|
||||
return cls._create_submodel(execute)
|
||||
|
||||
@classmethod
|
||||
def _db_create_bca(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
CREATE TABLE boundary_condition_adists{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
pollutant INTEGER NOT NULL,
|
||||
type TEXT NOT NULL,
|
||||
node INTEGER,
|
||||
FOREIGN KEY(pollutant) REFERENCES Pollutants(id),
|
||||
FOREIGN KEY(node) REFERENCES river_node(id)
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
FOREIGN KEY(pollutant) REFERENCES Pollutants(pamhyr_id),
|
||||
FOREIGN KEY(node) REFERENCES river_node(pamhyr_id)
|
||||
)
|
||||
""")
|
||||
|
||||
execute("""
|
||||
CREATE TABLE boundary_condition_data_adists(
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
@classmethod
|
||||
def _db_create_bca_data(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
CREATE TABLE boundary_condition_data_adists{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
data0 TEXT NOT NULL,
|
||||
data1 TEXT NOT NULL,
|
||||
bc INTEGER,
|
||||
FOREIGN KEY(bc) REFERENCES boundary_condition_adists(id)
|
||||
bca INTEGER,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
FOREIGN KEY(bca) REFERENCES boundary_condition_adists(pamhyr_id)
|
||||
)
|
||||
""")
|
||||
|
||||
return cls._create_submodel(execute)
|
||||
|
||||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
major, minor, release = version.strip().split(".")
|
||||
|
|
@ -83,8 +95,55 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
|||
if int(release) < 7:
|
||||
cls._db_create(execute)
|
||||
|
||||
if major == "0" and int(minor) < 2:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "boundary_condition_adists"
|
||||
nodes = data['id2pid']['river_node']
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
cls._db_create_bca(execute, ext="_tmp")
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table}_tmp " +
|
||||
"(pamhyr_id, pollutant, type, node, scenario) " +
|
||||
"SELECT pamhyr_id, pollutant, type, node, scenario " +
|
||||
f"FROM {table}"
|
||||
)
|
||||
|
||||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||
|
||||
cls._db_update_to_0_2_0_set_node_pid(execute, table, reachs)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_2_0_data(cls, execute, data):
|
||||
table = "boundary_condition_data_adists"
|
||||
reachs = data['id2pid']['river_reach']
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
cls._db_create_bca_data(execute, ext="_tmp")
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table}_tmp " +
|
||||
"(pamhyr_id, data0, data1, bca, scenario) " +
|
||||
"SELECT pamhyr_id, data0, data1, bc, scenario) " +
|
||||
f"FROM {table}"
|
||||
)
|
||||
|
||||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||
|
||||
cls._db_update_to_0_2_0_set_reach_pid(execute, table, reachs)
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
|
|
|
|||
|
|
@ -45,14 +45,20 @@ class BoundaryConditionsAdisTSList(PamhyrModelList):
|
|||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
execute("DELETE FROM boundary_condition_adists")
|
||||
execute("DELETE FROM boundary_condition_data_adists")
|
||||
execute(
|
||||
"DELETE FROM boundary_condition_adists" +
|
||||
f"WHERE scenario = {self._status.scenario_id}"
|
||||
)
|
||||
execute(
|
||||
"DELETE FROM boundary_condition_data_adists" +
|
||||
f"WHERE scenario = {self._status.scenario_id}"
|
||||
)
|
||||
|
||||
if data is None:
|
||||
data = {}
|
||||
|
||||
for bc in self._lst:
|
||||
bc._db_save(execute, data=data)
|
||||
for bca in self._lst:
|
||||
bca._db_save(execute, data=data)
|
||||
|
||||
return True
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ from tools import trace, timer, old_pamhyr_date_to_timestamp
|
|||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
from Model.Scenario import Scenario
|
||||
|
||||
from Model.D90AdisTS.D90AdisTSSpec import D90AdisTSSpec
|
||||
|
||||
|
|
@ -50,15 +51,17 @@ class D90AdisTS(SQLSubModel):
|
|||
self._data = []
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute):
|
||||
execute("""
|
||||
CREATE TABLE d90_adists(
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
d90 REAL NOT NULL,
|
||||
enabled BOOLEAN NOT NULL
|
||||
)
|
||||
""")
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
CREATE TABLE d90_adists{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
name TEXT NOT NULL,
|
||||
d90 REAL NOT NULL,
|
||||
enabled BOOLEAN NOT NULL,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()}
|
||||
)
|
||||
""")
|
||||
|
||||
return cls._create_submodel(execute)
|
||||
|
||||
|
|
@ -69,8 +72,30 @@ class D90AdisTS(SQLSubModel):
|
|||
if int(release) < 6:
|
||||
cls._db_create(execute)
|
||||
|
||||
if major == "0" and int(minor) < 2:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "d90_adists"
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
cls._db_create_lca(execute, ext="_tmp")
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table}_tmp " +
|
||||
"(pamhyr_id, name, d90, enabled, scenario) " +
|
||||
"SELECT pamhyr_id, name, d90, enabled, scenario " +
|
||||
f"FROM {table}"
|
||||
)
|
||||
|
||||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
|
|
|
|||
|
|
@ -42,7 +42,10 @@ class D90AdisTSList(PamhyrModelList):
|
|||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
execute("DELETE FROM d90_adists")
|
||||
execute(
|
||||
"DELETE FROM d90_adists" +
|
||||
f"WHERE scenario = {self._status.scenario_id}"
|
||||
)
|
||||
|
||||
if data is None:
|
||||
data = {}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ from tools import trace, timer
|
|||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
from Model.Scenario import Scenario
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
|
@ -52,21 +53,23 @@ class D90AdisTSSpec(SQLSubModel):
|
|||
D90AdisTSSpec._id_cnt = max(D90AdisTSSpec._id_cnt + 1, self.id)
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute):
|
||||
execute("""
|
||||
CREATE TABLE d90_spec(
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
d90_default INTEGER NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
reach INTEGER NOT NULL,
|
||||
start_rk REAL NOT NULL,
|
||||
end_rk REAL NOT NULL,
|
||||
d90 REAL NOT NULL,
|
||||
enabled BOOLEAN NOT NULL,
|
||||
FOREIGN KEY(d90_default) REFERENCES d90_adists(id),
|
||||
FOREIGN KEY(reach) REFERENCES river_reach(id)
|
||||
)
|
||||
""")
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
CREATE TABLE d90_adists_spec{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
d90_default INTEGER NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
reach INTEGER NOT NULL,
|
||||
start_rk REAL NOT NULL,
|
||||
end_rk REAL NOT NULL,
|
||||
d90 REAL NOT NULL,
|
||||
enabled BOOLEAN NOT NULL,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
FOREIGN KEY(d90_default) REFERENCES d90_adists(pamhyr_id),
|
||||
FOREIGN KEY(reach) REFERENCES river_reach(pamhyr_id)
|
||||
)
|
||||
""")
|
||||
|
||||
return cls._create_submodel(execute)
|
||||
|
||||
|
|
@ -77,8 +80,31 @@ class D90AdisTSSpec(SQLSubModel):
|
|||
if int(release) < 6:
|
||||
cls._db_create(execute)
|
||||
|
||||
if major == "0" and int(minor) < 2:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "d90_spec"
|
||||
table_new = "d90_adists_spec"
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
cls._db_create_lca(execute, ext="_tmp")
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table_new}_tmp " +
|
||||
"(pamhyr_id, name, d90, enabled, scenario) " +
|
||||
"SELECT pamhyr_id, name, d90, enabled, scenario " +
|
||||
f"FROM {table}"
|
||||
)
|
||||
|
||||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table_new}_tmp RENAME TO {table_new}")
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ from tools import trace, timer, old_pamhyr_date_to_timestamp
|
|||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
from Model.Scenario import Scenario
|
||||
|
||||
from Model.DIFAdisTS.DIFAdisTSSpec import DIFAdisTSSpec
|
||||
|
||||
|
|
@ -53,18 +54,20 @@ class DIFAdisTS(SQLSubModel):
|
|||
self._data = []
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute):
|
||||
execute("""
|
||||
CREATE TABLE dif_adists(
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
method TEXT NOT NULL,
|
||||
dif REAL NOT NULL,
|
||||
b REAL,
|
||||
c REAL,
|
||||
enabled BOOLEAN NOT NULL
|
||||
)
|
||||
""")
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
CREATE TABLE dif_adists{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
name TEXT NOT NULL,
|
||||
method TEXT NOT NULL,
|
||||
dif REAL NOT NULL,
|
||||
b REAL,
|
||||
c REAL,
|
||||
enabled BOOLEAN NOT NULL,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()}
|
||||
)
|
||||
""")
|
||||
|
||||
return cls._create_submodel(execute)
|
||||
|
||||
|
|
@ -75,8 +78,30 @@ class DIFAdisTS(SQLSubModel):
|
|||
if int(release) < 6:
|
||||
cls._db_create(execute)
|
||||
|
||||
if major == "0" and int(minor) < 2:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "dif_adists"
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
cls._db_create_lca(execute, ext="_tmp")
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table}_tmp " +
|
||||
"(pamhyr_id, name, method, dif, b, c, enabled, scenario) " +
|
||||
"SELECT pamhyr_id, name, method, dif, b, c, enabled, scenario " +
|
||||
f"FROM {table}"
|
||||
)
|
||||
|
||||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
|
|
@ -137,7 +162,7 @@ class DIFAdisTS(SQLSubModel):
|
|||
sql = (
|
||||
"INSERT INTO " +
|
||||
"dif_adists(" +
|
||||
"id, name, method, dif, b, c, enabled" +
|
||||
"pamhyr_id, name, method, dif, b, c, enabled" +
|
||||
") " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, '{self._db_format(self._name)}', " +
|
||||
|
|
@ -150,7 +175,7 @@ class DIFAdisTS(SQLSubModel):
|
|||
|
||||
data['dif_default_id'] = self.id
|
||||
execute(
|
||||
"DELETE FROM dif_spec " +
|
||||
"DELETE FROM dif_adists_spec " +
|
||||
f"WHERE dif_default = {self.id}"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,10 @@ class DIFAdisTSList(PamhyrModelList):
|
|||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
execute("DELETE FROM dif_adists")
|
||||
execute(
|
||||
"DELETE FROM dif_adists" +
|
||||
f"WHERE scenario = {self._status.scenario_id}"
|
||||
)
|
||||
|
||||
if data is None:
|
||||
data = {}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ from tools import trace, timer
|
|||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
from Model.Scenario import Scenario
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
|
@ -54,23 +55,25 @@ class DIFAdisTSSpec(SQLSubModel):
|
|||
DIFAdisTSSpec._id_cnt = max(DIFAdisTSSpec._id_cnt + 1, self.id)
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute):
|
||||
execute("""
|
||||
CREATE TABLE dif_spec(
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
dif_default INTEGER NOT NULL,
|
||||
method TEXT NOT NULL,
|
||||
reach INTEGER NOT NULL,
|
||||
start_rk REAL NOT NULL,
|
||||
end_rk REAL NOT NULL,
|
||||
dif REAL NOT NULL,
|
||||
b REAL,
|
||||
c REAL,
|
||||
enabled BOOLEAN NOT NULL,
|
||||
FOREIGN KEY(dif_default) REFERENCES dif_adists(id),
|
||||
FOREIGN KEY(reach) REFERENCES river_reach(id)
|
||||
)
|
||||
""")
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
CREATE TABLE dif_adists_spec{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
dif_default INTEGER NOT NULL,
|
||||
method TEXT NOT NULL,
|
||||
reach INTEGER NOT NULL,
|
||||
start_rk REAL NOT NULL,
|
||||
end_rk REAL NOT NULL,
|
||||
dif REAL NOT NULL,
|
||||
b REAL,
|
||||
c REAL,
|
||||
enabled BOOLEAN NOT NULL,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
FOREIGN KEY(dif_default) REFERENCES dif_adists(id),
|
||||
FOREIGN KEY(reach) REFERENCES river_reach(id)
|
||||
)
|
||||
""")
|
||||
|
||||
return cls._create_submodel(execute)
|
||||
|
||||
|
|
@ -81,8 +84,34 @@ class DIFAdisTSSpec(SQLSubModel):
|
|||
if int(release) < 6:
|
||||
cls._db_create(execute)
|
||||
|
||||
if major == "0" and int(minor) < 2:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "dif_spec"
|
||||
table_new = "dif_adists_spec"
|
||||
reachs = data['id2pid']['river_reach']
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
cls._db_create_lca(execute, ext="_tmp")
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table_new}_tmp " +
|
||||
"(pamhyr_id, pollutant, reach, begin_rk, end_rk, scenario) " +
|
||||
"SELECT pamhyr_id, pollutant, edge, begin_rk, end_rk, scenario " +
|
||||
f"FROM {table}"
|
||||
)
|
||||
|
||||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table_new}_tmp RENAME TO {table_new}")
|
||||
|
||||
cls._db_update_to_0_2_0_set_reach_pid(execute, table, reachs)
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ class Friction(SQLSubModel):
|
|||
"RENAME COLUMN begin_kp TO begin_rk")
|
||||
execute("ALTER TABLE friction RENAME COLUMN end_kp TO end_rk")
|
||||
|
||||
cls._db_update_to_0_1_0(execute, data)
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
if major == "0" and minor == "1":
|
||||
if int(release) < 2:
|
||||
|
|
@ -90,7 +90,7 @@ class Friction(SQLSubModel):
|
|||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0(cls, execute, data):
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "friction"
|
||||
reachs = data['id2pid']['river_reach']
|
||||
stricklers = data['id2pid']['stricklers']
|
||||
|
|
@ -112,11 +112,11 @@ class Friction(SQLSubModel):
|
|||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||
|
||||
cls._db_update_to_0_1_0_set_reach_pid(execute, table, reachs)
|
||||
cls._db_update_to_0_1_0_set_stricklers_pid(execute, table, stricklers)
|
||||
cls._db_update_to_0_2_0_set_reach_pid(execute, table, reachs)
|
||||
cls._db_update_to_0_2_0_set_stricklers_pid(execute, table, stricklers)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0_set_stricklers_pid(cls, execute, table,
|
||||
def _db_update_to_0_2_0_set_stricklers_pid(cls, execute, table,
|
||||
stricklers):
|
||||
els = execute(
|
||||
f"SELECT pamhyr_id, begin_strickler, end_strickler FROM {table}"
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ class PointXYZ(Point, SQLSubModel):
|
|||
"""
|
||||
)
|
||||
|
||||
cls._db_update_to_0_1_0(execute, data)
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
if major == "0" and minor == "1":
|
||||
if int(release) < 2:
|
||||
|
|
@ -93,7 +93,7 @@ class PointXYZ(Point, SQLSubModel):
|
|||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0(cls, execute, data):
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "geometry_pointXYZ"
|
||||
id2pid = data['id2pid']
|
||||
profiles = id2pid['geometry_profileXYZ']
|
||||
|
|
@ -113,14 +113,14 @@ class PointXYZ(Point, SQLSubModel):
|
|||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||
|
||||
cls._db_update_to_0_1_0_set_profile_pid(execute, table, profiles)
|
||||
cls._db_update_to_0_2_0_set_profile_pid(execute, table, profiles)
|
||||
|
||||
if 'sedimentary_layer' in id2pid:
|
||||
sl = id2pid['sedimentary_layer']
|
||||
cls._db_update_to_0_1_0_set_sl_pid(execute, table, sl)
|
||||
cls._db_update_to_0_2_0_set_sl_pid(execute, table, sl)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0_set_profile_pid(cls, execute, table, profiles):
|
||||
def _db_update_to_0_2_0_set_profile_pid(cls, execute, table, profiles):
|
||||
els = execute(
|
||||
f"SELECT pamhyr_id, profile FROM {table}"
|
||||
)
|
||||
|
|
@ -143,7 +143,7 @@ class PointXYZ(Point, SQLSubModel):
|
|||
)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0_set_sl_pid(cls, execute, table, sl):
|
||||
def _db_update_to_0_2_0_set_sl_pid(cls, execute, table, sl):
|
||||
els = execute(
|
||||
f"SELECT pamhyr_id, sl FROM {table}"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||
"""
|
||||
)
|
||||
|
||||
cls._db_update_to_0_1_0(execute, data)
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
if major == "0" and minor == "1":
|
||||
if int(release) < 2:
|
||||
|
|
@ -149,7 +149,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0(cls, execute, data):
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "geometry_profileXYZ"
|
||||
id2pid = data['id2pid']
|
||||
reachs = id2pid['river_reach']
|
||||
|
|
@ -173,11 +173,11 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||
|
||||
cls._db_update_to_0_1_0_set_reach_pid(execute, table, reachs)
|
||||
cls._db_update_to_0_2_0_set_reach_pid(execute, table, reachs)
|
||||
|
||||
if 'sedimentary_layer' in id2pid:
|
||||
sl = id2pid['sedimentary_layer']
|
||||
cls._db_update_to_0_1_0_set_sl_pid(execute, table, sl)
|
||||
cls._db_update_to_0_2_0_set_sl_pid(execute, table, sl)
|
||||
|
||||
@classmethod
|
||||
def _db_update_cleanup_points(cls, execute):
|
||||
|
|
@ -198,7 +198,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||
)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0_set_sl_pid(cls, execute, table, sl):
|
||||
def _db_update_to_0_2_0_set_sl_pid(cls, execute, table, sl):
|
||||
els = execute(
|
||||
f"SELECT pamhyr_id, sl FROM {table}"
|
||||
)
|
||||
|
|
@ -988,8 +988,12 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||
self.point(i+1)
|
||||
)
|
||||
|
||||
self.modified()
|
||||
|
||||
def shift(self, x, y, z):
|
||||
for p in self.points:
|
||||
p.x = p.x + x
|
||||
p.y = p.y + y
|
||||
p.z = p.z + z
|
||||
|
||||
self.modified()
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ class BasicHS(SQLSubModel):
|
|||
cls._db_create(execute)
|
||||
return True
|
||||
else:
|
||||
cls._db_update_to_0_1_0(execute, data)
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
if major == "0" and minor == "1":
|
||||
if int(release) < 2:
|
||||
|
|
@ -90,12 +90,12 @@ class BasicHS(SQLSubModel):
|
|||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0(cls, execute, data):
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "hydraulic_structures_basic"
|
||||
hs = data['id2pid']['hydraulic_structures']
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
cls._db_update_to_0_1_0_set_hs_pid(execute, table, hs)
|
||||
cls._db_update_to_0_2_0_set_hs_pid(execute, table, hs)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
cls._db_create(execute, ext="_tmp")
|
||||
|
|
@ -111,7 +111,7 @@ class BasicHS(SQLSubModel):
|
|||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0_set_hs_pid(cls, execute, table, hs):
|
||||
def _db_update_to_0_2_0_set_hs_pid(cls, execute, table, hs):
|
||||
els = execute(
|
||||
f"SELECT pamhyr_id, hs FROM {table}"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -62,17 +62,17 @@ class BHSValue(SQLSubModel):
|
|||
cls._db_create(execute)
|
||||
return True
|
||||
else:
|
||||
cls._db_update_to_0_1_0(execute, data)
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0(cls, execute, data):
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "hydraulic_structures_basic_value"
|
||||
bhs = data['id2pid']['hydraulic_structures_basic']
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
cls._db_update_to_0_1_0_set_bhs_pid(execute, table, bhs)
|
||||
cls._db_update_to_0_2_0_set_bhs_pid(execute, table, bhs)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
cls._db_create(execute, ext="_tmp")
|
||||
|
|
@ -88,7 +88,7 @@ class BHSValue(SQLSubModel):
|
|||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0_set_bhs_pid(cls, execute, table, bhs):
|
||||
def _db_update_to_0_2_0_set_bhs_pid(cls, execute, table, bhs):
|
||||
els = execute(
|
||||
f"SELECT pamhyr_id, bhs FROM {table}"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ class HydraulicStructure(SQLSubModel):
|
|||
"""
|
||||
)
|
||||
|
||||
cls._db_update_to_0_1_0(execute, data)
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
if major == "0" and minor == "1":
|
||||
if rl < 1:
|
||||
|
|
@ -115,12 +115,12 @@ class HydraulicStructure(SQLSubModel):
|
|||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0(cls, execute, data):
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "hydraulic_structures"
|
||||
reachs = data['id2pid']['river_reach']
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
cls._db_update_to_0_1_0_set_reach_pid(execute, table, reachs)
|
||||
cls._db_update_to_0_2_0_set_reach_pid(execute, table, reachs)
|
||||
cls._db_update_to_0_1_1(
|
||||
execute, data,
|
||||
origin_version="0.0.*"
|
||||
|
|
@ -143,7 +143,7 @@ class HydraulicStructure(SQLSubModel):
|
|||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0_set_reach_pid(cls, execute, table, reachs):
|
||||
def _db_update_to_0_2_0_set_reach_pid(cls, execute, table, reachs):
|
||||
els = execute(
|
||||
f"SELECT pamhyr_id, input_reach, output_reach FROM {table}"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ class Data(SQLSubModel):
|
|||
"ALTER TABLE initial_conditions RENAME COLUMN kp TO rk"
|
||||
)
|
||||
|
||||
cls._db_update_to_0_1_0(execute, data)
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
if major == "0" and minor == "1":
|
||||
if int(release) < 1:
|
||||
|
|
@ -103,12 +103,12 @@ class Data(SQLSubModel):
|
|||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0(cls, execute, data):
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "initial_conditions"
|
||||
reachs = data['id2pid']['river_reach']
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
cls._db_update_to_0_1_0_set_reach_pid(execute, table, reachs)
|
||||
cls._db_update_to_0_2_0_set_reach_pid(execute, table, reachs)
|
||||
cls._db_update_to_0_1_1(
|
||||
execute, data,
|
||||
origin_version="0.0.*"
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ from tools import trace, timer, old_pamhyr_date_to_timestamp
|
|||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
from Model.Scenario import Scenario
|
||||
|
||||
from Model.InitialConditionsAdisTS.InitialConditionsAdisTSSpec \
|
||||
import ICAdisTSSpec
|
||||
|
|
@ -55,20 +56,22 @@ class InitialConditionsAdisTS(SQLSubModel):
|
|||
self._data = []
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute):
|
||||
execute("""
|
||||
CREATE TABLE initial_conditions_adists(
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
pollutant INTEGER NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
concentration REAL NOT NULL,
|
||||
eg REAL NOT NULL,
|
||||
em REAL NOT NULL,
|
||||
ed REAL NOT NULL,
|
||||
enabled BOOLEAN NOT NULL,
|
||||
FOREIGN KEY(pollutant) REFERENCES Pollutants(id)
|
||||
)
|
||||
""")
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
CREATE TABLE initial_conditions_adists{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
pollutant INTEGER NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
concentration REAL NOT NULL,
|
||||
eg REAL NOT NULL,
|
||||
em REAL NOT NULL,
|
||||
ed REAL NOT NULL,
|
||||
enabled BOOLEAN NOT NULL,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
FOREIGN KEY(pollutant) REFERENCES Pollutants(pamhyr_id)
|
||||
)
|
||||
""")
|
||||
|
||||
return cls._create_submodel(execute)
|
||||
|
||||
|
|
@ -79,8 +82,33 @@ class InitialConditionsAdisTS(SQLSubModel):
|
|||
if int(release) < 6:
|
||||
cls._db_create(execute)
|
||||
|
||||
if major == "0" and int(minor) < 2:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "initial_conditions_adists"
|
||||
reachs = data['id2pid']['river_reach']
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
cls._db_create_lca(execute, ext="_tmp")
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table}_tmp " +
|
||||
"(pamhyr_id, pollutant, reach, begin_rk, end_rk, scenario) " +
|
||||
"SELECT pamhyr_id, pollutant, edge, begin_rk, end_rk, scenario) " +
|
||||
f"FROM {table}"
|
||||
)
|
||||
|
||||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||
|
||||
cls._db_update_to_0_2_0_set_reach_pid(execute, table, reachs)
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
|
|
|
|||
|
|
@ -43,7 +43,10 @@ class InitialConditionsAdisTSList(PamhyrModelList):
|
|||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
execute("DELETE FROM initial_conditions_adists")
|
||||
execute(
|
||||
"DELETE FROM initial_conditions_adists" +
|
||||
f"WHERE scenario = {self._status.scenario_id}"
|
||||
)
|
||||
|
||||
if data is None:
|
||||
data = {}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ from tools import trace, timer
|
|||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
from Model.Scenario import Scenario
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
|
@ -56,25 +57,28 @@ class ICAdisTSSpec(SQLSubModel):
|
|||
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_rk REAL NOT NULL,
|
||||
end_rk REAL NOT NULL,
|
||||
concentration 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_adists(id),
|
||||
FOREIGN KEY(reach) REFERENCES river_reach(id)
|
||||
)
|
||||
""")
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
CREATE TABLE initial_conditions_spec{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
ic_default INTEGER NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
reach INTEGER NOT NULL,
|
||||
start_rk REAL NOT NULL,
|
||||
end_rk REAL NOT NULL,
|
||||
concentration REAL NOT NULL,
|
||||
eg REAL NOT NULL,
|
||||
em REAL NOT NULL,
|
||||
ed REAL NOT NULL,
|
||||
rate REAL NOT NULL,
|
||||
enabled BOOLEAN NOT NULL,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
FOREIGN KEY(ic_default)
|
||||
REFERENCES initial_conditions_adists(pamhyr_id),
|
||||
FOREIGN KEY(reach) REFERENCES river_reach(pamhyr_id)
|
||||
)
|
||||
""")
|
||||
|
||||
return cls._create_submodel(execute)
|
||||
|
||||
|
|
@ -85,8 +89,35 @@ class ICAdisTSSpec(SQLSubModel):
|
|||
if int(release) < 6:
|
||||
cls._db_create(execute)
|
||||
|
||||
if major == "0" and int(minor) < 2:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "initial_conditions_spec"
|
||||
reachs = data['id2pid']['river_reach']
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
cls._db_create_lca(execute, ext="_tmp")
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table}_tmp " +
|
||||
"(pamhyr_id, ic_default, name, reach, start_rk, end_rk, " +
|
||||
"concentration, eg, em, ed, rate, enabled, scenario) " +
|
||||
"SELECT pamhyr_id, ic_default, name, reach, start_rk, end_rk, " +
|
||||
"concentration, eg, em, ed, rate, enabled, scenario " +
|
||||
f"FROM {table}"
|
||||
)
|
||||
|
||||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||
|
||||
cls._db_update_to_0_2_0_set_reach_pid(execute, table, reachs)
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ class Data(SQLSubModel):
|
|||
major, minor, release = version.strip().split(".")
|
||||
|
||||
if major == minor == "0":
|
||||
cls._db_update_to_0_1_0(execute, data)
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
if major == "0" and minor == "1":
|
||||
if int(release) < 2:
|
||||
|
|
@ -85,7 +85,7 @@ class Data(SQLSubModel):
|
|||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0(cls, execute, data=None):
|
||||
def _db_update_to_0_2_0(cls, execute, data=None):
|
||||
table = "lateral_contribution_data"
|
||||
lcs = data['id2pid']['lateral_contribution']
|
||||
|
||||
|
|
@ -103,10 +103,10 @@ class Data(SQLSubModel):
|
|||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||
|
||||
cls._db_update_to_0_1_0_set_lc_pid(execute, table, lcs)
|
||||
cls._db_update_to_0_2_0_set_lc_pid(execute, table, lcs)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0_set_lc_pid(cls, execute, table, lcs):
|
||||
def _db_update_to_0_2_0_set_lc_pid(cls, execute, table, lcs):
|
||||
els = execute(
|
||||
f"SELECT pamhyr_id, lc FROM {table}"
|
||||
)
|
||||
|
|
@ -270,7 +270,7 @@ class LateralContribution(SQLSubModel):
|
|||
"""
|
||||
)
|
||||
|
||||
cls._db_update_to_0_1_0(execute, data)
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
if major == "0" and minor == "1":
|
||||
if int(release) < 2:
|
||||
|
|
@ -282,7 +282,7 @@ class LateralContribution(SQLSubModel):
|
|||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0(cls, execute, data):
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "lateral_contribution"
|
||||
reachs = data['id2pid']['river_reach']
|
||||
|
||||
|
|
@ -301,7 +301,7 @@ class LateralContribution(SQLSubModel):
|
|||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||
|
||||
cls._db_update_to_0_1_0_set_reach_pid(execute, table, reachs)
|
||||
cls._db_update_to_0_2_0_set_reach_pid(execute, table, reachs)
|
||||
|
||||
@classmethod
|
||||
def _get_ctor_from_type(cls, t):
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ from tools import (
|
|||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
from Model.Scenario import Scenario
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
|
@ -53,31 +54,42 @@ class LateralContributionAdisTS(SQLSubModel):
|
|||
self._types = [self.time_convert, float]
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute):
|
||||
execute("""
|
||||
CREATE TABLE lateral_contribution_adists(
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
pollutant INTEGER NOT NULL,
|
||||
edge INTEGER NOT NULL,
|
||||
begin_rk REAL NOT NULL,
|
||||
end_rk REAL NOT NULL,
|
||||
FOREIGN KEY(pollutant) REFERENCES Pollutants(id),
|
||||
FOREIGN KEY(edge) REFERENCES river_reach(id)
|
||||
)
|
||||
""")
|
||||
|
||||
execute("""
|
||||
CREATE TABLE lateral_contribution_data_adists(
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
data0 TEXT NOT NULL,
|
||||
data1 TEXT NOT NULL,
|
||||
lc INTEGER,
|
||||
FOREIGN KEY(lc) REFERENCES lateral_contribution(id)
|
||||
)
|
||||
""")
|
||||
def _db_create(cls, execute, ext=""):
|
||||
cls._db_create_lca(execute, ext)
|
||||
cls._db_create_lca_data(execute, ext)
|
||||
|
||||
return cls._create_submodel(execute)
|
||||
|
||||
@classmethod
|
||||
def _db_create_lca(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
CREATE TABLE lateral_contribution_adists{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
pollutant INTEGER NOT NULL,
|
||||
reach INTEGER NOT NULL,
|
||||
begin_rk REAL NOT NULL,
|
||||
end_rk REAL NOT NULL,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
FOREIGN KEY(pollutant) REFERENCES Pollutants(pamhyr_id),
|
||||
FOREIGN KEY(reach) REFERENCES river_reach(pamhyr_id)
|
||||
)
|
||||
""")
|
||||
|
||||
@classmethod
|
||||
def _db_create_lca_data(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
CREATE TABLE lateral_contribution_data_adists{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
data0 TEXT NOT NULL,
|
||||
data1 TEXT NOT NULL,
|
||||
lca INTEGER,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
FOREIGN KEY(lca) REFERENCES lateral_contribution_adists(pamhyr_id)
|
||||
)
|
||||
""")
|
||||
|
||||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
major, minor, release = version.strip().split(".")
|
||||
|
|
@ -85,60 +97,127 @@ class LateralContributionAdisTS(SQLSubModel):
|
|||
if int(release) < 7:
|
||||
cls._db_create(execute)
|
||||
|
||||
if major == "0" and int(minor) < 2:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "lateral_contribution_adists"
|
||||
reachs = data['id2pid']['river_reach']
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
cls._db_create_lca(execute, ext="_tmp")
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table}_tmp " +
|
||||
"(pamhyr_id, pollutant, reach, begin_rk, end_rk, scenario) " +
|
||||
"SELECT pamhyr_id, pollutant, edge, begin_rk, end_rk, scenario " +
|
||||
f"FROM {table}"
|
||||
)
|
||||
|
||||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||
|
||||
cls._db_update_to_0_2_0_set_reach_pid(execute, table, reachs)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_2_0_data(cls, execute, data):
|
||||
table = "lateral_contribution_data_adists"
|
||||
reachs = data['id2pid']['river_reach']
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
cls._db_create_lca_data(execute, ext="_tmp")
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table}_tmp " +
|
||||
"(pamhyr_id, data0, data1, lca, scenario) " +
|
||||
"SELECT pamhyr_id, data0, data1, lc, scenario) " +
|
||||
f"FROM {table}"
|
||||
)
|
||||
|
||||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||
|
||||
cls._db_update_to_0_2_0_set_reach_pid(execute, table, reachs)
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
|
||||
scenario = data["scenario"]
|
||||
loaded = data['loaded_pid']
|
||||
|
||||
table = execute(
|
||||
"SELECT id, pollutant, edge, begin_rk, end_rk " +
|
||||
"FROM lateral_contribution_adists"
|
||||
"FROM lateral_contribution_adists" +
|
||||
f"WHERE scenario = {scenario.id} " +
|
||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
|
||||
)
|
||||
|
||||
if table is not None:
|
||||
for row in table:
|
||||
lc = cls(
|
||||
lca = cls(
|
||||
id=row[0],
|
||||
pollutant=row[1],
|
||||
status=data['status']
|
||||
)
|
||||
|
||||
lc.edge = row[2]
|
||||
lc.begin_rk = row[3]
|
||||
lc.end_rk = row[4]
|
||||
lca.edge = row[2]
|
||||
lca.begin_rk = row[3]
|
||||
lca.end_rk = row[4]
|
||||
|
||||
values = execute(
|
||||
"SELECT data0," +
|
||||
" data1 FROM lateral_contribution_data_adists " +
|
||||
f"WHERE lc = '{lc.id}'"
|
||||
f"WHERE scenario = {scenario.id} " +
|
||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
|
||||
f"AND lca = '{lca.id}'"
|
||||
)
|
||||
|
||||
# Write data
|
||||
for v in values:
|
||||
data0 = lc._types[0](v[0])
|
||||
data1 = lc._types[1](v[1])
|
||||
data0 = lca._types[0](v[0])
|
||||
data1 = lca._types[1](v[1])
|
||||
# Replace data at pos ind
|
||||
lc._data.append((data0, data1))
|
||||
lca._data.append((data0, data1))
|
||||
|
||||
new.append(lc)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
new += cls._db_load(execute, data)
|
||||
data["scenario"] = scenario
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
execute(f"DELETE FROM lateral_contribution_adists" +
|
||||
f" WHERE id = {self.id}")
|
||||
execute(f"DELETE FROM lateral_contribution_data_adists" +
|
||||
f" WHERE lc = {self.id}")
|
||||
execute(
|
||||
f"DELETE FROM lateral_contribution_adists" +
|
||||
f" WHERE id = {self.id} " +
|
||||
f"AND scenario = {self._status.scenario_id}"
|
||||
)
|
||||
execute(
|
||||
f"DELETE FROM lateral_contribution_data_adists" +
|
||||
f" WHERE lc = {self.id} " +
|
||||
f"AND scenario = {self._status.scenario_id}"
|
||||
)
|
||||
|
||||
sql = (
|
||||
"INSERT INTO " +
|
||||
"lateral_contribution_adists(id, " +
|
||||
"pollutant, edge, begin_rk, end_rk) " +
|
||||
"pollutant, reach, begin_rk, end_rk, scenario) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, {self._pollutant}, {self.edge}, " +
|
||||
f"{self._begin_rk}, {self._end_rk}" +
|
||||
f"{self._status.scenario_id}" +
|
||||
")"
|
||||
)
|
||||
execute(sql)
|
||||
|
|
|
|||
|
|
@ -45,8 +45,14 @@ class LateralContributionsAdisTSList(PamhyrModelList):
|
|||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
execute("DELETE FROM lateral_contribution_adists")
|
||||
execute("DELETE FROM lateral_contribution_data_adists")
|
||||
execute(
|
||||
"DELETE FROM lateral_contribution_adists" +
|
||||
f"WHERE scenario = {self._status.scenario_id}"
|
||||
)
|
||||
execute(
|
||||
"DELETE FROM lateral_contribution_data_adists" +
|
||||
f"WHERE scenario = {self._status.scenario_id}"
|
||||
)
|
||||
|
||||
if data is None:
|
||||
data = {}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ from tools import (
|
|||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
from Model.Scenario import Scenario
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
|
@ -77,13 +78,15 @@ class OutputRKAdists(SQLSubModel):
|
|||
self._status.modified()
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute):
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(
|
||||
"CREATE TABLE OutputRKAdists(" +
|
||||
"id INTEGER NOT NULL PRIMARY KEY, " +
|
||||
f"CREATE TABLE OutputRKAdists{ext}(" +
|
||||
f"{cls.create_db_add_pamhyr_id()},"
|
||||
"reach INTEGER NOT NULL, " +
|
||||
"rk REAL NOT NULL, " +
|
||||
"title TEXT NOT NULL, " +
|
||||
f"{Scenario.create_db_add_scenario()},"
|
||||
f"{Scenario.create_db_add_scenario_fk()},"
|
||||
"FOREIGN KEY(reach) REFERENCES river_reach(id)" +
|
||||
")"
|
||||
)
|
||||
|
|
@ -97,8 +100,34 @@ class OutputRKAdists(SQLSubModel):
|
|||
if int(release) < 7:
|
||||
cls._db_create(execute)
|
||||
|
||||
if major == "0" and int(minor) <= 2:
|
||||
if int(release) <= 0:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "OutputRKAdists"
|
||||
reachs = data['id2pid']['river_reach']
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
cls._db_create(execute, ext="_tmp")
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table}_tmp " +
|
||||
"(pamhyr_id, reach, rk, title, scenario) " +
|
||||
"SELECT pamhyr_id, reach, rk, scenario " +
|
||||
f"FROM {table}"
|
||||
)
|
||||
|
||||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||
|
||||
cls._db_update_to_0_2_0_set_reach_pid(execute, table, reachs)
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
|
|
|
|||
|
|
@ -38,7 +38,10 @@ class OutputRKAdistsList(PamhyrModelList):
|
|||
ok = True
|
||||
|
||||
# Delete previous data
|
||||
execute("DELETE FROM OutputRKAdists")
|
||||
execute(
|
||||
"DELETE FROM OutputRKAdists" +
|
||||
f"AND scenario = {self._status.scenario_id}"
|
||||
)
|
||||
|
||||
for sl in self._lst:
|
||||
ok &= sl._db_save(execute, data)
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ class Data(SQLSubModel):
|
|||
|
||||
if major == minor == "0":
|
||||
if int(release) > 5:
|
||||
cls._db_update_to_0_1_0(execute, data)
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
if major == "0" and int(minor) <= 1:
|
||||
if int(release) < 2:
|
||||
|
|
@ -76,7 +76,7 @@ class Data(SQLSubModel):
|
|||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0(cls, execute, data):
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "reservoir_data"
|
||||
id2pid = data['id2pid']
|
||||
|
||||
|
|
@ -99,12 +99,12 @@ class Data(SQLSubModel):
|
|||
|
||||
if 'reservoir' in id2pid:
|
||||
reservoirs = id2pid['reservoir']
|
||||
cls._db_update_to_0_1_0_set_reservoir_pid(
|
||||
cls._db_update_to_0_2_0_set_reservoir_pid(
|
||||
execute, table, reservoirs
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0_set_reservoir_pid(cls, execute, table, reservoirs):
|
||||
def _db_update_to_0_2_0_set_reservoir_pid(cls, execute, table, reservoirs):
|
||||
bcs = execute(
|
||||
f"SELECT pamhyr_id, reservoir FROM {table}"
|
||||
)
|
||||
|
|
@ -241,7 +241,7 @@ class Reservoir(SQLSubModel):
|
|||
cls._db_create(execute)
|
||||
return True
|
||||
|
||||
cls._db_update_to_0_1_0(execute, data)
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
if major == "0" and minor == "1":
|
||||
if int(release) < 2:
|
||||
|
|
@ -253,12 +253,12 @@ class Reservoir(SQLSubModel):
|
|||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0(cls, execute, data):
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "reservoir"
|
||||
nodes = data['id2pid']['river_node']
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data=data)
|
||||
cls._db_update_to_0_1_0_set_node_pid(execute, table, nodes)
|
||||
cls._db_update_to_0_2_0_set_node_pid(execute, table, nodes)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
print(execute(f"SELECT * FROM {table}"))
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ class RiverNode(Node):
|
|||
major, minor, release = version.strip().split(".")
|
||||
|
||||
if major == minor == "0":
|
||||
cls._db_update_to_0_1_0(execute, data=data)
|
||||
cls._db_update_to_0_2_0(execute, data=data)
|
||||
|
||||
if major == "0" and minor == "1":
|
||||
if int(release) < 2:
|
||||
|
|
@ -113,7 +113,7 @@ class RiverNode(Node):
|
|||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0(cls, execute, data=None):
|
||||
def _db_update_to_0_2_0(cls, execute, data=None):
|
||||
table = "river_node"
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
|
|
@ -250,7 +250,7 @@ class RiverReach(Edge):
|
|||
major, minor, release = version.strip().split(".")
|
||||
|
||||
if major == minor == "0":
|
||||
cls._db_update_to_0_1_0(execute, data)
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
if major == "0" and minor == "1":
|
||||
if int(release) < 2:
|
||||
|
|
@ -262,7 +262,7 @@ class RiverReach(Edge):
|
|||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0(cls, execute, data=None):
|
||||
def _db_update_to_0_2_0(cls, execute, data=None):
|
||||
table = "river_reach"
|
||||
nodes = data['id2pid']['river_node']
|
||||
|
||||
|
|
@ -282,10 +282,10 @@ class RiverReach(Edge):
|
|||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||
|
||||
cls._db_update_to_0_1_0_set_node_pid(execute, table, nodes)
|
||||
cls._db_update_to_0_2_0_set_node_pid(execute, table, nodes)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0_set_node_pid(cls, execute, table, nodes):
|
||||
def _db_update_to_0_2_0_set_node_pid(cls, execute, table, nodes):
|
||||
bcs = execute(
|
||||
f"SELECT pamhyr_id, node1, node2 FROM {table}"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ class Layer(SQLSubModel):
|
|||
cls._db_create(execute)
|
||||
return True
|
||||
else:
|
||||
cls._db_update_to_0_1_0(execute, data)
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
if major == "0" and minor == "1":
|
||||
if int(release) < 2:
|
||||
|
|
@ -142,7 +142,7 @@ class Layer(SQLSubModel):
|
|||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0(cls, execute, data):
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "sedimentary_layer_layer"
|
||||
sl = data['id2pid']['sedimentary_layer']
|
||||
|
||||
|
|
@ -163,10 +163,10 @@ class Layer(SQLSubModel):
|
|||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||
|
||||
cls._db_update_to_0_1_0_set_sl_pid(execute, table, sl)
|
||||
cls._db_update_to_0_2_0_set_sl_pid(execute, table, sl)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0_set_sl_pid(cls, execute, table, sl):
|
||||
def _db_update_to_0_2_0_set_sl_pid(cls, execute, table, sl):
|
||||
els = execute(
|
||||
f"SELECT pamhyr_id, sl FROM {table}"
|
||||
)
|
||||
|
|
@ -365,7 +365,7 @@ class SedimentLayer(SQLSubModel):
|
|||
cls._db_create(execute)
|
||||
return True
|
||||
else:
|
||||
cls._db_update_to_0_1_0(execute, data)
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
if major == "0" and minor == "1":
|
||||
if int(release) < 2:
|
||||
|
|
@ -377,7 +377,7 @@ class SedimentLayer(SQLSubModel):
|
|||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0(cls, execute, data):
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "sedimentary_layer"
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ class Stricklers(SQLSubModel):
|
|||
def _db_update(cls, execute, version, data=None):
|
||||
major, minor, release = version.strip().split(".")
|
||||
if major == minor == "0":
|
||||
cls._db_update_to_0_1_0(execute, data)
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
if major == "0" and minor == "1":
|
||||
if int(release) < 2:
|
||||
|
|
@ -76,7 +76,7 @@ class Stricklers(SQLSubModel):
|
|||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0(cls, execute, data):
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "stricklers"
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class Study(SQLModel):
|
|||
|
||||
def __init__(self, filename=None, init_new=True):
|
||||
# Metadata
|
||||
self._version = "0.1.7"
|
||||
self._version = "0.2.0"
|
||||
self.creation_date = datetime.now()
|
||||
self.last_modification_date = datetime.now()
|
||||
self.last_save_date = datetime.now()
|
||||
|
|
|
|||
|
|
@ -278,7 +278,7 @@ class SQLSubModel(PamhyrID):
|
|||
raise NotImplementedMethodeError(cls, cls._db_update)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0_set_node_pid(cls, execute, table, nodes):
|
||||
def _db_update_to_0_2_0_set_node_pid(cls, execute, table, nodes):
|
||||
els = execute(
|
||||
f"SELECT pamhyr_id, node FROM {table}"
|
||||
)
|
||||
|
|
@ -298,7 +298,7 @@ class SQLSubModel(PamhyrID):
|
|||
)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0_set_reach_pid(cls, execute, table, reachs):
|
||||
def _db_update_to_0_2_0_set_reach_pid(cls, execute, table, reachs):
|
||||
els = execute(
|
||||
f"SELECT pamhyr_id, reach FROM {table}"
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue