mirror of https://gitlab.com/pamhyr/pamhyr2
Compare commits
9 Commits
739eb56006
...
23a0bc33fa
| Author | SHA1 | Date |
|---|---|---|
|
|
23a0bc33fa | |
|
|
93340a48b1 | |
|
|
0379a8ee02 | |
|
|
6cce02650b | |
|
|
6e79fe4cd5 | |
|
|
f66d8c7a34 | |
|
|
826e532605 | |
|
|
fc35f2fbcc | |
|
|
216239bfce |
|
|
@ -91,12 +91,17 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
|||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
major, minor, release = version.strip().split(".")
|
||||
created = False
|
||||
|
||||
if major == "0" and int(minor) <= 1:
|
||||
if int(release) < 7:
|
||||
cls._db_create(execute)
|
||||
created = True
|
||||
|
||||
elif major == "0" and int(minor) < 2:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
if major == "0" and int(minor) < 2:
|
||||
if not created:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
cls._db_update_to_0_2_0_data(execute, data)
|
||||
|
||||
return True
|
||||
|
||||
|
|
@ -120,12 +125,11 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
|||
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)
|
||||
cls._db_update_to_0_2_0_set_node_pid(execute, table, nodes)
|
||||
|
||||
@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)
|
||||
|
|
@ -135,15 +139,13 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
|||
execute(
|
||||
f"INSERT INTO {table}_tmp " +
|
||||
"(pamhyr_id, data0, data1, bca, scenario) " +
|
||||
"SELECT pamhyr_id, data0, data1, bc, 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 = []
|
||||
|
|
@ -197,7 +199,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
|||
values = execute(
|
||||
"SELECT data0, data1 FROM " +
|
||||
"boundary_condition_data_adists " +
|
||||
f"WHERE bc = '{bc.id}' " +
|
||||
f"WHERE bca = '{bc.id}' " +
|
||||
f"AND scenario = {scenario.id}"
|
||||
)
|
||||
|
||||
|
|
@ -228,7 +230,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
|||
)
|
||||
execute(
|
||||
"DELETE FROM boundary_condition_data_adists " +
|
||||
f"WHERE bc = {self.id} " +
|
||||
f"WHERE bca = {self.id} " +
|
||||
f"AND scenario = {self._status.scenario_id} "
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -67,12 +67,16 @@ class D90AdisTS(SQLSubModel):
|
|||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
major, minor, release = version.strip().split(".")
|
||||
created = False
|
||||
|
||||
if major == "0" and int(minor) <= 1:
|
||||
if int(release) < 6:
|
||||
cls._db_create(execute)
|
||||
created = True
|
||||
|
||||
elif major == "0" and int(minor) < 2:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
if major == "0" and int(minor) < 2:
|
||||
if not created:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
return True
|
||||
|
||||
|
|
@ -83,7 +87,7 @@ class D90AdisTS(SQLSubModel):
|
|||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
cls._db_create_lca(execute, ext="_tmp")
|
||||
cls._db_create(execute, ext="_tmp")
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table}_tmp " +
|
||||
|
|
@ -116,14 +120,14 @@ class D90AdisTS(SQLSubModel):
|
|||
for row in table:
|
||||
it = iter(row)
|
||||
|
||||
d90_id = next(it)
|
||||
pid = next(it)
|
||||
name = next(it)
|
||||
value_d90 = next(it)
|
||||
enabled = (next(it) == 1)
|
||||
owner_scenario = next(it)
|
||||
|
||||
d90 = cls(
|
||||
id=d90_id,
|
||||
id=pid,
|
||||
name=name,
|
||||
status=status,
|
||||
owner_scenario=owner_scenario
|
||||
|
|
@ -132,8 +136,8 @@ class D90AdisTS(SQLSubModel):
|
|||
d90.d90 = value_d90
|
||||
d90.enabled = enabled
|
||||
|
||||
data['d90_default_id'] = d90_id
|
||||
d90._data = d90AdisTSSpec._db_load(execute, data)
|
||||
data['d90_default_id'] = pid
|
||||
d90._data = D90AdisTSSpec._db_load(execute, data)
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(d90)
|
||||
|
|
|
|||
|
|
@ -70,12 +70,16 @@ class D90AdisTSSpec(SQLSubModel):
|
|||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
major, minor, release = version.strip().split(".")
|
||||
created = False
|
||||
|
||||
if major == 0 and minor < 1:
|
||||
if int(release) < 6:
|
||||
cls._db_create(execute)
|
||||
created = True
|
||||
|
||||
if major == "0" and int(minor) < 2:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
if not created:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
return True
|
||||
|
||||
|
|
@ -87,7 +91,7 @@ class D90AdisTSSpec(SQLSubModel):
|
|||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
cls._db_create_lca(execute, ext="_tmp")
|
||||
cls._db_create(execute, ext="_tmp")
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table_new}_tmp " +
|
||||
|
|
@ -110,7 +114,7 @@ class D90AdisTSSpec(SQLSubModel):
|
|||
return new
|
||||
|
||||
table = execute(
|
||||
"SELECT id, name, reach, start_rk, end_rk, " +
|
||||
"SELECT pamhyr_id, name, reach, start_rk, end_rk, " +
|
||||
"d90, enabled, scenario " +
|
||||
"FROM d90_adists_spec " +
|
||||
f"WHERE d90_default = {data['d90_default_id']} " +
|
||||
|
|
|
|||
|
|
@ -74,12 +74,16 @@ class DIFAdisTS(SQLSubModel):
|
|||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
major, minor, release = version.strip().split(".")
|
||||
created = False
|
||||
|
||||
if major == "0" and int(minor) <= 1:
|
||||
if int(release) < 6:
|
||||
cls._db_create(execute)
|
||||
created = True
|
||||
|
||||
elif major == "0" and int(minor) < 2:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
if major == "0" and int(minor) < 2:
|
||||
if not created:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
return True
|
||||
|
||||
|
|
@ -90,7 +94,7 @@ class DIFAdisTS(SQLSubModel):
|
|||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
cls._db_create_lca(execute, ext="_tmp")
|
||||
cls._db_create(execute, ext="_tmp")
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table}_tmp " +
|
||||
|
|
@ -146,7 +150,7 @@ class DIFAdisTS(SQLSubModel):
|
|||
dif.enabled = enabled
|
||||
|
||||
data['dif_default_id'] = pid
|
||||
dif._data = difAdisTSSpec._db_load(execute, data)
|
||||
dif._data = DIFAdisTSSpec._db_load(execute, data)
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(dif)
|
||||
|
|
|
|||
|
|
@ -80,12 +80,16 @@ class DIFAdisTSSpec(SQLSubModel):
|
|||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
major, minor, release = version.strip().split(".")
|
||||
created = False
|
||||
|
||||
if major == 0 and minor < 1:
|
||||
if int(release) < 6:
|
||||
cls._db_create(execute)
|
||||
created = True
|
||||
|
||||
if major == "0" and int(minor) < 2:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
if not created:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
return True
|
||||
|
||||
|
|
@ -98,7 +102,7 @@ class DIFAdisTSSpec(SQLSubModel):
|
|||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
cls._db_create_lca(execute, ext="_tmp")
|
||||
cls._db_create(execute, ext="_tmp")
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table_new}_tmp " +
|
||||
|
|
@ -123,9 +127,9 @@ class DIFAdisTSSpec(SQLSubModel):
|
|||
return new
|
||||
|
||||
table = execute(
|
||||
"SELECT id, method, reach, start_rk, end_rk, " +
|
||||
"SELECT pamhyr_id, method, reach, start_rk, end_rk, " +
|
||||
"dif, b, c, enabled, scenario " +
|
||||
"FROM dif_spec " +
|
||||
"FROM dif_adists_spec " +
|
||||
f"WHERE dif_default = {data['dif_default_id']} " +
|
||||
f"AND scenario = {scenario.id} " +
|
||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
|
||||
|
|
@ -178,7 +182,7 @@ class DIFAdisTSSpec(SQLSubModel):
|
|||
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
"dif_spec(id, dif_default, method, reach, " +
|
||||
"dif_adists_spec(pamhyr_id, dif_default, method, reach, " +
|
||||
"start_rk, end_rk, dif, b, c, enabled, scenario) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, {dif_default}, " +
|
||||
|
|
|
|||
|
|
@ -128,10 +128,13 @@ class Friction(SQLSubModel):
|
|||
b_s_id = next(it)
|
||||
e_s_id = next(it)
|
||||
|
||||
b_s = stricklers[b_s_id] if b_s_id != -1 else -1
|
||||
e_s = stricklers[e_s_id] if e_s_id != -1 else -1
|
||||
|
||||
execute(
|
||||
f"UPDATE {table} " +
|
||||
f"SET begin_strickler = {stricklers[b_s_id]}, " +
|
||||
f"end_strickler = {stricklers[e_s_id]} " +
|
||||
f"SET begin_strickler = {b_s}, " +
|
||||
f"end_strickler = {e_s} " +
|
||||
f"WHERE pamhyr_id = {pid}"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ class Point(object):
|
|||
profile=None, status=None,
|
||||
owner_scenario=-1):
|
||||
super(Point, self).__init__(
|
||||
status=status,
|
||||
id=id, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -164,13 +164,15 @@ class PointXYZ(Point, SQLSubModel):
|
|||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
|
||||
status = data["status"]
|
||||
profile = data["profile"]
|
||||
scenario = data["scenario"]
|
||||
loaded = data['loaded_pid']
|
||||
|
||||
if scenario is None:
|
||||
return
|
||||
return new
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, deleted, " +
|
||||
|
|
@ -194,7 +196,7 @@ class PointXYZ(Point, SQLSubModel):
|
|||
sl = next(it)
|
||||
owner_scenario = next(it)
|
||||
|
||||
new = cls(
|
||||
point = cls(
|
||||
id=pid,
|
||||
name=name,
|
||||
x=x, y=y, z=z,
|
||||
|
|
@ -203,12 +205,12 @@ class PointXYZ(Point, SQLSubModel):
|
|||
owner_scenario=owner_scenario
|
||||
)
|
||||
if deleted:
|
||||
new.set_as_deleted()
|
||||
point.set_as_deleted()
|
||||
|
||||
if sl == -1 or sl is None:
|
||||
new._sl = None
|
||||
point._sl = None
|
||||
else:
|
||||
new._sl = next(
|
||||
point._sl = next(
|
||||
filter(
|
||||
lambda s: s.pamhyr_id == sl,
|
||||
data["sediment_layers_list"].sediment_layers
|
||||
|
|
@ -216,12 +218,14 @@ class PointXYZ(Point, SQLSubModel):
|
|||
)
|
||||
|
||||
loaded.add(pid)
|
||||
yield new
|
||||
new.append(point)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
yield from cls._db_load(execute, data)
|
||||
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
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||
|
||||
def __init__(self,
|
||||
id: int = -1,
|
||||
ind: int = -1,
|
||||
name: str = "",
|
||||
rk: float = 0.,
|
||||
reach=None,
|
||||
|
|
@ -70,9 +71,8 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||
"""
|
||||
super(ProfileXYZ, self).__init__(
|
||||
id=id,
|
||||
num=num,
|
||||
name=name,
|
||||
rk=rk,
|
||||
num=num, rk=rk,
|
||||
code1=code1, code2=code2,
|
||||
_type="XYZ",
|
||||
reach=reach,
|
||||
|
|
@ -80,6 +80,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._db_ind = ind
|
||||
self.tab = Tabulation([], [], [])
|
||||
self.tab_up_to_date = False
|
||||
self.time_z = 0.0
|
||||
|
|
@ -219,16 +220,18 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
|
||||
status = data["status"]
|
||||
scenario = data["scenario"]
|
||||
loaded = data['loaded_pid']
|
||||
reach = data["reach"]
|
||||
|
||||
if scenario is None:
|
||||
return
|
||||
return new
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, deleted, name, rk, num, " +
|
||||
"SELECT pamhyr_id, ind, deleted, name, rk, num, " +
|
||||
"code1, code2, sl, scenario " +
|
||||
"FROM geometry_profileXYZ " +
|
||||
f"WHERE reach = {reach.id} " +
|
||||
|
|
@ -241,6 +244,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||
it = iter(row)
|
||||
|
||||
pid = next(it)
|
||||
ind = next(it)
|
||||
deleted = (next(it) == 1)
|
||||
name = next(it)
|
||||
rk = next(it)
|
||||
|
|
@ -250,8 +254,8 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||
sl = next(it)
|
||||
owner_scenario = next(it)
|
||||
|
||||
new = cls(
|
||||
id=pid, num=num,
|
||||
profile = cls(
|
||||
id=pid, ind=ind, num=num,
|
||||
name=name, rk=rk,
|
||||
code1=code1, code2=code2,
|
||||
reach=reach,
|
||||
|
|
@ -259,27 +263,31 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||
owner_scenario=owner_scenario
|
||||
)
|
||||
if deleted:
|
||||
new.set_as_deleted()
|
||||
profile.set_as_deleted()
|
||||
|
||||
if sl == -1 or sl is None:
|
||||
new._sl = None
|
||||
profile._sl = None
|
||||
else:
|
||||
new._sl = next(
|
||||
profile._sl = next(
|
||||
filter(
|
||||
lambda s: s.id == sl,
|
||||
data["sediment_layers_list"].sediment_layers
|
||||
), None)
|
||||
),
|
||||
None
|
||||
)
|
||||
|
||||
data["profile"] = new
|
||||
new._points = PointXYZ._db_load(execute, data.copy())
|
||||
data["profile"] = profile
|
||||
profile._points = PointXYZ._db_load(execute, data.copy())
|
||||
|
||||
loaded.add(pid)
|
||||
yield new
|
||||
new.append(profile)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
yield from cls._db_load(execute, data)
|
||||
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
|
||||
|
|
@ -991,7 +999,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||
self.modified()
|
||||
|
||||
def shift(self, x, y, z):
|
||||
for p in self.points:
|
||||
for p in self._points:
|
||||
p.x = p.x + x
|
||||
p.y = p.y + y
|
||||
p.z = p.z + z
|
||||
|
|
|
|||
|
|
@ -72,9 +72,12 @@ class Reach(SQLSubModel):
|
|||
def _db_load(cls, execute, data=None):
|
||||
new = cls(status=data["status"], parent=data["reach"])
|
||||
|
||||
new._profiles = ProfileXYZ._db_load(
|
||||
execute,
|
||||
data=data.copy()
|
||||
new._profiles = sorted(
|
||||
ProfileXYZ._db_load(
|
||||
execute,
|
||||
data=data.copy()
|
||||
),
|
||||
key=lambda p: p._db_ind
|
||||
)
|
||||
|
||||
return new
|
||||
|
|
|
|||
|
|
@ -78,12 +78,16 @@ class InitialConditionsAdisTS(SQLSubModel):
|
|||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
major, minor, release = version.strip().split(".")
|
||||
created = False
|
||||
|
||||
if major == "0" and int(minor) <= 1:
|
||||
if int(release) < 6:
|
||||
cls._db_create(execute)
|
||||
created = True
|
||||
|
||||
elif major == "0" and int(minor) < 2:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
if major == "0" and int(minor) < 2:
|
||||
if not created:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
return True
|
||||
|
||||
|
|
@ -95,22 +99,20 @@ class InitialConditionsAdisTS(SQLSubModel):
|
|||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
cls._db_create_lca(execute, ext="_tmp")
|
||||
cls._db_create(execute, ext="_tmp")
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table}_tmp " +
|
||||
"(pamhyr_id, pollutant, name, concentration, " +
|
||||
"eg, em, ed, scenario) " +
|
||||
"eg, em, ed, enabled, scenario) " +
|
||||
"SELECT pamhyr_id, pollutant, name, concentration, " +
|
||||
"eg, em, ed, scenario " +
|
||||
"eg, em, ed, 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 = []
|
||||
|
|
@ -161,7 +163,7 @@ class InitialConditionsAdisTS(SQLSubModel):
|
|||
ic._data = ICAdisTSSpec._db_load(execute, data)
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(IC)
|
||||
new.append(ic)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
new += cls._db_load(execute, data)
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ class ICAdisTSSpec(SQLSubModel):
|
|||
@classmethod
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
CREATE TABLE initial_conditions_spec{ext}(
|
||||
CREATE TABLE initial_conditions_adists_spec{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
ic_default INTEGER NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
|
|
@ -76,27 +76,32 @@ class ICAdisTSSpec(SQLSubModel):
|
|||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
major, minor, release = version.strip().split(".")
|
||||
created = False
|
||||
|
||||
if major == 0 and minor < 1:
|
||||
if int(release) < 6:
|
||||
cls._db_create(execute)
|
||||
created =True
|
||||
|
||||
elif major == "0" and int(minor) < 2:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
if major == "0" and int(minor) < 2:
|
||||
if not created:
|
||||
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"
|
||||
table_new = "initial_conditions_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")
|
||||
cls._db_create(execute, ext="_tmp")
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table}_tmp " +
|
||||
f"INSERT INTO {table_new}_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, " +
|
||||
|
|
@ -105,9 +110,9 @@ class ICAdisTSSpec(SQLSubModel):
|
|||
)
|
||||
|
||||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {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)
|
||||
cls._db_update_to_0_2_0_set_reach_pid(execute, table_new, reachs)
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
|
|
@ -121,9 +126,9 @@ class ICAdisTSSpec(SQLSubModel):
|
|||
return new
|
||||
|
||||
table = execute(
|
||||
"SELECT id, name, reach, start_rk, end_rk, " +
|
||||
"SELECT pamhyr_id, name, reach, start_rk, end_rk, " +
|
||||
"concentration, eg, em, ed, rate, enabled, scenario " +
|
||||
"FROM initial_conditions_spec " +
|
||||
"FROM initial_conditions_adists_spec " +
|
||||
f"WHERE ic_default = {data['ic_default_id']} " +
|
||||
f"AND scenario = {scenario.id} " +
|
||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
|
||||
|
|
@ -179,7 +184,7 @@ class ICAdisTSSpec(SQLSubModel):
|
|||
|
||||
sql = (
|
||||
"INSERT INTO " +
|
||||
"initial_conditions_spec(id, ic_default, name, reach, " +
|
||||
"initial_conditions_adists_spec(id, ic_default, name, reach, " +
|
||||
"start_rk, end_rk, concentration, eg, em, ed, rate, " +
|
||||
"enabled, scenario) " +
|
||||
"VALUES (" +
|
||||
|
|
|
|||
|
|
@ -93,12 +93,16 @@ class LateralContributionAdisTS(SQLSubModel):
|
|||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
major, minor, release = version.strip().split(".")
|
||||
created = False
|
||||
|
||||
if major == "0" and int(minor) <= 1:
|
||||
if int(release) < 7:
|
||||
cls._db_create(execute)
|
||||
created = True
|
||||
|
||||
elif major == "0" and int(minor) < 2:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
if major == "0" and int(minor) < 2:
|
||||
if not created:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
return True
|
||||
|
||||
|
|
@ -127,7 +131,6 @@ class LateralContributionAdisTS(SQLSubModel):
|
|||
@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)
|
||||
|
|
@ -137,15 +140,13 @@ class LateralContributionAdisTS(SQLSubModel):
|
|||
execute(
|
||||
f"INSERT INTO {table}_tmp " +
|
||||
"(pamhyr_id, data0, data1, lca, scenario) " +
|
||||
"SELECT pamhyr_id, data0, data1, lc, 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 = []
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ class OutputRKAdists(SQLSubModel):
|
|||
@classmethod
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(
|
||||
f"CREATE TABLE OutputRKAdists{ext}(" +
|
||||
f"CREATE TABLE output_rk_adists{ext}(" +
|
||||
f"{cls.create_db_add_pamhyr_id()},"
|
||||
"reach INTEGER NOT NULL, " +
|
||||
"rk REAL NOT NULL, " +
|
||||
|
|
@ -94,12 +94,15 @@ class OutputRKAdists(SQLSubModel):
|
|||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
major, minor, release = version.strip().split(".")
|
||||
created = False
|
||||
|
||||
if major == "0" and int(minor) <= 1:
|
||||
if int(release) < 7:
|
||||
cls._db_create(execute)
|
||||
created = True
|
||||
|
||||
elif major == "0" and int(minor) <= 2:
|
||||
if int(release) <= 0:
|
||||
if major == "0" and int(minor) <= 2:
|
||||
if not created:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
return True
|
||||
|
|
@ -107,6 +110,7 @@ class OutputRKAdists(SQLSubModel):
|
|||
@classmethod
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "OutputRKAdists"
|
||||
table_new = "output_rk_adists"
|
||||
reachs = data['id2pid']['river_reach']
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
|
|
@ -115,16 +119,16 @@ class OutputRKAdists(SQLSubModel):
|
|||
cls._db_create(execute, ext="_tmp")
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table}_tmp " +
|
||||
f"INSERT INTO {table_new}_tmp " +
|
||||
"(pamhyr_id, reach, rk, title, scenario) " +
|
||||
"SELECT pamhyr_id, reach, rk, scenario " +
|
||||
"SELECT pamhyr_id, reach, rk, title, scenario " +
|
||||
f"FROM {table}"
|
||||
)
|
||||
|
||||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {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)
|
||||
cls._db_update_to_0_2_0_set_reach_pid(execute, table_new, reachs)
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
|
|
@ -141,7 +145,7 @@ class OutputRKAdists(SQLSubModel):
|
|||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, reach, rk, title, scenario " +
|
||||
f"FROM OutputRKAdists"
|
||||
f"FROM output_rk_adists"
|
||||
)
|
||||
|
||||
if table is not None:
|
||||
|
|
@ -175,14 +179,14 @@ class OutputRKAdists(SQLSubModel):
|
|||
return True
|
||||
|
||||
execute(
|
||||
"DELETE FROM OutputRKAdists " +
|
||||
"DELETE FROM output_rk_adists " +
|
||||
f"WHERE pamhyr_id = {self.id} " +
|
||||
f"AND scenario = {self._status.scenario_id} "
|
||||
)
|
||||
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
"OutputRKAdists(pamhyr_id, reach, rk, title, scenario) " +
|
||||
"output_rk_adists(pamhyr_id, reach, rk, title, scenario) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, {self._reach}, {self._rk}, " +
|
||||
f"'{self._db_format(self._title)}'" +
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class OutputRKAdistsList(PamhyrModelList):
|
|||
|
||||
# Delete previous data
|
||||
execute(
|
||||
"DELETE FROM OutputRKAdists " +
|
||||
"DELETE FROM output_rk_adists " +
|
||||
f"WHERE scenario = {self._status.scenario_id}"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -107,13 +107,17 @@ class Pollutants(SQLSubModel):
|
|||
@classmethod
|
||||
def _db_update(cls, execute, version, data=None):
|
||||
major, minor, release = version.strip().split(".")
|
||||
created = False
|
||||
|
||||
if major == "0" and int(minor) <= 1:
|
||||
if int(release) < 7:
|
||||
cls._db_create(execute)
|
||||
created = True
|
||||
|
||||
elif major == "0" and int(minor) < 2:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
cls._db_update_to_0_2_0_char(execute, data)
|
||||
if major == "0" and int(minor) < 2:
|
||||
if not created:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
cls._db_update_to_0_2_0_char(execute, data)
|
||||
|
||||
return True
|
||||
|
||||
|
|
@ -125,12 +129,12 @@ class Pollutants(SQLSubModel):
|
|||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
cls._db_create_lca(execute, ext="_tmp")
|
||||
cls._db_create_pol(execute, ext="_tmp")
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table_new}_tmp " +
|
||||
"(pamhyr_id, name, scenario) " +
|
||||
"SELECT pamhyr_id, name, scenario) " +
|
||||
"SELECT pamhyr_id, name, scenario " +
|
||||
f"FROM {table}"
|
||||
)
|
||||
|
||||
|
|
@ -145,7 +149,7 @@ class Pollutants(SQLSubModel):
|
|||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
cls._db_create_lca(execute, ext="_tmp")
|
||||
cls._db_create_pol_char(execute, ext="_tmp")
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table_new}_tmp " +
|
||||
|
|
@ -179,11 +183,11 @@ class Pollutants(SQLSubModel):
|
|||
|
||||
if table is not None:
|
||||
for row in table:
|
||||
id = row[0]
|
||||
pid = row[0]
|
||||
name = row[1]
|
||||
|
||||
new_pollutant = cls(
|
||||
id=id, name=name,
|
||||
id=pid, name=name,
|
||||
status=status
|
||||
)
|
||||
|
||||
|
|
@ -191,7 +195,7 @@ class Pollutants(SQLSubModel):
|
|||
table = execute(
|
||||
"SELECT * " +
|
||||
"FROM pollutants_characteristics " +
|
||||
f"WHERE pollutant = {id}" +
|
||||
f"WHERE pollutant = {pid} " +
|
||||
f"AND scenario = {scenario.id} " +
|
||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))})"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -38,7 +38,10 @@ class PollutantsList(PamhyrModelList):
|
|||
ok = True
|
||||
|
||||
# Delete previous data
|
||||
execute("DELETE FROM Pollutants")
|
||||
execute(
|
||||
"DELETE FROM Pollutants " +
|
||||
f"WHERE scenario = {self._status.scenario_id}"
|
||||
)
|
||||
|
||||
for sl in self._lst:
|
||||
ok &= sl._db_save(execute, data)
|
||||
|
|
|
|||
|
|
@ -475,59 +475,78 @@ class River(Graph):
|
|||
execute, data
|
||||
)
|
||||
data["stricklers"] = new._stricklers
|
||||
data['loaded_pid'] = set()
|
||||
|
||||
# Initial conditions
|
||||
new._sediment_layers = SedimentLayerList._db_load(
|
||||
execute, data
|
||||
)
|
||||
data["sediment_layers_list"] = new._sediment_layers
|
||||
data['loaded_pid'] = set()
|
||||
|
||||
# Network
|
||||
new._nodes = RiverNode._db_load(
|
||||
execute, data
|
||||
)
|
||||
data["nodes"] = new.nodes()
|
||||
data['loaded_pid'] = set()
|
||||
|
||||
new._edges = RiverReach._db_load(
|
||||
execute, data
|
||||
)
|
||||
data["edges"] = new.edges()
|
||||
data['loaded_pid'] = set()
|
||||
|
||||
# Boundary Condition
|
||||
new._boundary_condition = BoundaryConditionList._db_load(
|
||||
execute, data
|
||||
)
|
||||
|
||||
data['loaded_pid'] = set()
|
||||
|
||||
# Lateral Contribution
|
||||
new._lateral_contribution = LateralContributionList._db_load(
|
||||
execute, data
|
||||
)
|
||||
|
||||
data['loaded_pid'] = set()
|
||||
|
||||
# Initial conditions
|
||||
new._initial_conditions = InitialConditionsDict._db_load(
|
||||
execute, data
|
||||
)
|
||||
|
||||
data['loaded_pid'] = set()
|
||||
|
||||
# Reservoir
|
||||
new._reservoir = ReservoirList._db_load(
|
||||
execute, data
|
||||
)
|
||||
|
||||
data['loaded_pid'] = set()
|
||||
|
||||
# Hydraulic Structures
|
||||
new._hydraulic_structures = HydraulicStructureList._db_load(
|
||||
execute, data
|
||||
)
|
||||
|
||||
data['loaded_pid'] = set()
|
||||
|
||||
# Parameters
|
||||
new._parameters = SolverParametersList._db_load(
|
||||
execute, data
|
||||
)
|
||||
|
||||
data['loaded_pid'] = set()
|
||||
|
||||
# Additional Files
|
||||
new._additional_files = AddFileList._db_load(
|
||||
execute, data
|
||||
)
|
||||
new._rep_lines = REPLineList._db_load(execute, data)
|
||||
|
||||
data['loaded_pid'] = set()
|
||||
|
||||
new._Output_rk_adists = OutputRKAdistsList._db_load(
|
||||
execute, data
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue