Compare commits

..

No commits in common. "0e1e3665a63a74d9145dd9c7562ea1740f34f04a" and "b61c4da8f12819536158fdcd13d03889a36f5137" have entirely different histories.

12 changed files with 205 additions and 435 deletions

View File

@ -32,177 +32,8 @@ from Model.Scenario import Scenario
logger = logging.getLogger() logger = logging.getLogger()
class Data(SQLSubModel):
_sub_classes = []
def __init__(self,
data0, data1,
id: int = -1,
types=[float, float],
status=None,
owner_scenario=-1):
super(Data, self).__init__(
id=id, status=status,
owner_scenario=owner_scenario
)
self._types = types
self._data = [data0, data1]
@classmethod
def _db_create(cls, execute, ext=""):
execute(f"""
CREATE TABLE boundary_condition_data_adists{ext}(
{cls.create_db_add_pamhyr_id()},
deleted BOOLEAN NOT NULL DEFAULT FALSE,
data0 TEXT NOT NULL,
data1 TEXT NOT NULL,
bca INTEGER,
{Scenario.create_db_add_scenario()},
{Scenario.create_db_add_scenario_fk()},
FOREIGN KEY(bca) REFERENCES boundary_condition_adists(pamhyr_id)
)
""")
return True
@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
if major == "0" and int(minor) < 2:
if not created:
cls._db_update_to_0_2_0(execute, data)
if not created:
return cls._update_submodel(execute, version, data)
return True
@classmethod
def _db_update_to_0_2_0(cls, execute, data):
table = "boundary_condition_data_adists"
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, 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_bca_pid(execute, data)
@classmethod
def _db_update_to_0_2_0_set_bca_pid(cls, execute, data):
pid_bca = data["id2pid"]["boundary_condition_adists"]
els = execute(
"SELECT pamhyr_id, bca " +
"FROM boundary_condition_data_adists"
)
for row in els:
it = iter(row)
pid = next(it)
bca_id = next(it)
if bca_id == -1:
continue
execute(
f"UPDATE boundary_condition_data_adists " +
f"SET bca = {pid_bca[bca_id]} " +
f"WHERE pamhyr_id = {pid}"
)
@classmethod
def _db_load(cls, execute, data=None):
new = []
status = data['status']
scenario = data["scenario"]
loaded = data['loaded_pid']
if scenario is None:
return new
bca = data["bca"]
table = execute(
"SELECT pamhyr_id, deleted, data0, data1, scenario FROM " +
"boundary_condition_data_adists " +
f"WHERE bca = {bca.id} " +
f"AND scenario = {scenario.id}"
)
if table is not None:
for row in table:
it = iter(row)
pid = next(it)
deleted = (next(it) == 1)
data0 = next(it)
data1 = next(it)
owner_scenario = next(it)
bc = cls(
data0, data1,
id=pid,
status=status,
owner_scenario=owner_scenario
)
if deleted:
bc.set_as_deleted()
loaded.add(pid)
new.append(bc)
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
bca = data["bca"]
data0 = self._db_format(self._data[0])
data1 = self._db_format(self._data[1])
execute(
"INSERT INTO " +
"boundary_condition_data_adists(" +
"pamhyr_id, data0, data1, bca, scenario) " +
f"VALUES ({self.id}, '{data0}', {data1}, {bca.id}, " +
f"{self._status.scenario_id})"
)
return True
def __getitem__(self, key):
return self._types[key](self._data[key])
def __setitem__(self, key, value):
self._data[key] = self._types[key](value)
class BoundaryConditionAdisTS(SQLSubModel): class BoundaryConditionAdisTS(SQLSubModel):
_sub_classes = [Data] _sub_classes = []
def __init__(self, id: int = -1, def __init__(self, id: int = -1,
pollutant: int = -1, status=None, pollutant: int = -1, status=None,
@ -223,6 +54,13 @@ class BoundaryConditionAdisTS(SQLSubModel):
@classmethod @classmethod
def _db_create(cls, execute, ext=""): 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""" execute(f"""
CREATE TABLE boundary_condition_adists{ext}( CREATE TABLE boundary_condition_adists{ext}(
{cls.create_db_add_pamhyr_id()}, {cls.create_db_add_pamhyr_id()},
@ -237,10 +75,19 @@ class BoundaryConditionAdisTS(SQLSubModel):
) )
""") """)
if ext != "": @classmethod
return True def _db_create_bca_data(cls, execute, ext=""):
execute(f"""
return cls._create_submodel(execute) CREATE TABLE boundary_condition_data_adists{ext}(
{cls.create_db_add_pamhyr_id()},
data0 TEXT NOT NULL,
data1 TEXT NOT NULL,
bca INTEGER,
{Scenario.create_db_add_scenario()},
{Scenario.create_db_add_scenario_fk()},
FOREIGN KEY(bca) REFERENCES boundary_condition_adists(pamhyr_id)
)
""")
@classmethod @classmethod
def _db_update(cls, execute, version, data=None): def _db_update(cls, execute, version, data=None):
@ -255,9 +102,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
if major == "0" and int(minor) < 2: if major == "0" and int(minor) < 2:
if not created: if not created:
cls._db_update_to_0_2_0(execute, data) cls._db_update_to_0_2_0(execute, data)
cls._db_update_to_0_2_0_data(execute, data)
if not created:
return cls._update_submodel(execute, version, data)
return True return True
@ -269,7 +114,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
cls.update_db_add_pamhyr_id(execute, table, data) cls.update_db_add_pamhyr_id(execute, table, data)
Scenario.update_db_add_scenario(execute, table) Scenario.update_db_add_scenario(execute, table)
cls._db_create(execute, ext="_tmp") cls._db_create_bca(execute, ext="_tmp")
execute( execute(
f"INSERT INTO {table}_tmp " + f"INSERT INTO {table}_tmp " +
@ -306,6 +151,49 @@ class BoundaryConditionAdisTS(SQLSubModel):
f"WHERE pamhyr_id = {pid}" f"WHERE pamhyr_id = {pid}"
) )
@classmethod
def _db_update_to_0_2_0_data(cls, execute, data):
table = "boundary_condition_data_adists"
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_bca_pid(execute, data)
@classmethod
def _db_update_to_0_2_0_set_bca_pid(cls, execute, data):
pid_bca = data["id2pid"]["boundary_condition_adists"]
els = execute(
"SELECT pamhyr_id, bca " +
"FROM boundary_condition_data_adists"
)
for row in els:
it = iter(row)
pid = next(it)
bca_id = next(it)
if bca_id == -1:
continue
execute(
f"UPDATE boundary_condition_data_adists " +
f"SET bca = {pid_bca[bca_id]} " +
f"WHERE pamhyr_id = {pid}"
)
@classmethod @classmethod
def _db_load(cls, execute, data=None): def _db_load(cls, execute, data=None):
new = [] new = []
@ -359,8 +247,19 @@ class BoundaryConditionAdisTS(SQLSubModel):
else: else:
bc.node = -1 bc.node = -1
data["bca"] = bc values = execute(
bc._data = Data._db_load(execute, data=data) "SELECT data0, data1 FROM " +
"boundary_condition_data_adists " +
f"WHERE bca = '{bc.id}' " +
f"AND scenario = {scenario.id}"
)
# Write data
for v in values:
data0 = bc._types[0](v[0])
data1 = bc._types[1](v[1])
# Replace data at pos ind
bc._data.append((data0, data1))
loaded.add(pid) loaded.add(pid)
new.append(bc) new.append(bc)
@ -403,15 +302,17 @@ class BoundaryConditionAdisTS(SQLSubModel):
")" ")"
) )
data["bca"] = self
ind = 0
for d in self._data: for d in self._data:
data["ind"] = ind data0 = self._db_format(str(d[0]))
data1 = self._db_format(str(d[1]))
d._db_save(execute, data) execute(
"INSERT INTO " +
ind += 1 "boundary_condition_data_adists(" +
"data0, data1, bc, scenario) " +
f"VALUES ('{data0}', {data1}, {self.id}, " +
f"{self._status.scenario_id})"
)
return True return True

View File

@ -63,9 +63,6 @@ class D90AdisTS(SQLSubModel):
) )
""") """)
if ext != "":
return True
return cls._create_submodel(execute) return cls._create_submodel(execute)
@classmethod @classmethod
@ -82,9 +79,6 @@ class D90AdisTS(SQLSubModel):
if not created: if not created:
cls._db_update_to_0_2_0(execute, data) cls._db_update_to_0_2_0(execute, data)
if not created:
return cls._update_submodel(execute, version, data)
return True return True
@classmethod @classmethod
@ -187,7 +181,7 @@ class D90AdisTS(SQLSubModel):
data['d90_default_id'] = self.id data['d90_default_id'] = self.id
execute( execute(
"DELETE FROM d90_adists_spec " + "DELETE FROM d90_spec " +
f"WHERE d90_default = {self.id} " + f"WHERE d90_default = {self.id} " +
f"AND scenario = {self._status.scenario_id} " f"AND scenario = {self._status.scenario_id} "
) )

View File

@ -28,7 +28,8 @@ logger = logging.getLogger()
class D90AdisTSSpec(SQLSubModel): class D90AdisTSSpec(SQLSubModel):
_sub_classes = [] _sub_classes = [
]
_id_cnt = 0 _id_cnt = 0
def __init__(self, id: int = -1, name: str = "", def __init__(self, id: int = -1, name: str = "",
@ -192,7 +193,7 @@ class D90AdisTSSpec(SQLSubModel):
execute( execute(
"INSERT INTO " + "INSERT INTO " +
"d90_adists_spec(pamhyr_id, deleted, " + "d90_spec(pamhyr_id, deleted, " +
"d90_default, name, reach, " + "d90_default, name, reach, " +
"start_rk, end_rk, d90, enabled, scenario) " + "start_rk, end_rk, d90, enabled, scenario) " +
"VALUES (" + "VALUES (" +

View File

@ -69,9 +69,6 @@ class DIFAdisTS(SQLSubModel):
) )
""") """)
if ext != "":
return True
return cls._create_submodel(execute) return cls._create_submodel(execute)
@classmethod @classmethod
@ -88,9 +85,6 @@ class DIFAdisTS(SQLSubModel):
if not created: if not created:
cls._db_update_to_0_2_0(execute, data) cls._db_update_to_0_2_0(execute, data)
if not created:
return cls._update_submodel(execute, version, data)
return True return True
@classmethod @classmethod
@ -201,7 +195,7 @@ class DIFAdisTS(SQLSubModel):
"VALUES (" + "VALUES (" +
f"{self.id}, '{self._db_format(self._name)}', " + f"{self.id}, '{self._db_format(self._name)}', " +
f"'{self._db_format(self._method)}', " + f"'{self._db_format(self._method)}', " +
f"{dif.id}, {b}, {c}, {self._enabled}, " + f"{dif}, {b}, {c}, {self._enabled}" +
f"{self._status.scenario_id}" + f"{self._status.scenario_id}" +
")" ")"
) )

View File

@ -107,26 +107,22 @@ class DIFAdisTSSpec(SQLSubModel):
execute( execute(
f"INSERT INTO {table_new}_tmp " + f"INSERT INTO {table_new}_tmp " +
"(pamhyr_id, dif_default, " + "(pamhyr_id, pollutant, reach, begin_rk, end_rk, scenario) " +
"method, reach, start_rk, end_rk, " + "SELECT pamhyr_id, pollutant, edge, begin_rk, end_rk, scenario " +
"dif, b, c, scenario) " +
"SELECT pamhyr_id, dif_default, " +
"method, reach, start_rk, end_rk, " +
"dif, b, c, scenario " +
f"FROM {table}" f"FROM {table}"
) )
execute(f"DROP TABLE {table}") execute(f"DROP TABLE {table}")
execute(f"ALTER TABLE {table_new}_tmp RENAME TO {table_new}") execute(f"ALTER TABLE {table_new}_tmp RENAME TO {table_new}")
cls._db_update_to_0_2_0_set_reach_pid(execute, table_new, reachs) cls._db_update_to_0_2_0_set_reach_pid(execute, table, reachs)
cls._db_update_to_0_2_0_set_dif_pid(execute, data) cls._db_update_to_0_2_0_set_dif_pid(execute, data)
@classmethod @classmethod
def _db_update_to_0_2_0_set_dif_pid(cls, execute, data): def _db_update_to_0_2_0_set_dif_pid(cls, execute, data):
pid_dif = data["id2pid"]["dif_adists"] pid_dif = data["id2pid"]["dif_adists"]
els = execute( els = execute(
"SELECT pamhyr_id, dif_default FROM dif_adists_spec" "SELECT pamhyr_id, dif FROM dif_adists_spec"
) )
for row in els: for row in els:
@ -139,7 +135,7 @@ class DIFAdisTSSpec(SQLSubModel):
execute( execute(
f"UPDATE dif_adists_spec" + f"UPDATE dif_adists_spec" +
f"SET dif_default = {pid_dif[dif_id]} " + f"SET dif = {pid_dif[dif_id]} " +
f"WHERE pamhyr_id = {pid}" f"WHERE pamhyr_id = {pid}"
) )

View File

@ -232,7 +232,7 @@ class InitialConditionsAdisTS(SQLSubModel):
sql = ( sql = (
"INSERT INTO " + "INSERT INTO " +
"initial_conditions_adists(" + "initial_conditions_adists(" +
"pamhyr_id, deleted, pollutant, name, concentration, " + "pamhyr_id, deletec, pollutant, name, concentration, " +
"eg, em, ed, enabled, scenario" + "eg, em, ed, enabled, scenario" +
") " + ") " +
"VALUES (" + "VALUES (" +
@ -247,7 +247,7 @@ class InitialConditionsAdisTS(SQLSubModel):
data['ic_default_id'] = self.id data['ic_default_id'] = self.id
execute( execute(
"DELETE FROM initial_conditions_adists_spec " + "DELETE FROM initial_conditions_spec " +
f"WHERE ic_default = {self.id} " + f"WHERE ic_default = {self.id} " +
f"AND scenario = {self._status.scenario_id}" f"AND scenario = {self._status.scenario_id}"
) )

View File

@ -32,25 +32,53 @@ from Model.Scenario import Scenario
logger = logging.getLogger() logger = logging.getLogger()
class Data(SQLSubModel): class LateralContributionAdisTS(SQLSubModel):
_sub_classes = [] _sub_classes = []
def __init__(self, def __init__(self, id: int = -1, pollutant: int = -1,
data0, data1, name: str = "", status=None,
id: int = -1,
types=[float, float],
status=None,
owner_scenario=-1): owner_scenario=-1):
super(Data, self).__init__( super(LateralContributionAdisTS, self).__init__(
id=id, status=status, id=id, status=status,
owner_scenario=owner_scenario owner_scenario=owner_scenario
) )
self._types = types self._status = status
self._data = [data0, data1]
self._pollutant = pollutant
self._reach = None
self._begin_rk = 0.0
self._end_rk = 0.0
self._data = []
self._header = ["time", "rate"]
self._types = [self.time_convert, float]
@classmethod @classmethod
def _db_create(cls, execute, ext=""): 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()},
deleted BOOLEAN NOT NULL DEFAULT FALSE,
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""" execute(f"""
CREATE TABLE lateral_contribution_data_adists{ext}( CREATE TABLE lateral_contribution_data_adists{ext}(
{cls.create_db_add_pamhyr_id()}, {cls.create_db_add_pamhyr_id()},
@ -80,181 +108,6 @@ class Data(SQLSubModel):
return True return True
@classmethod
def _db_update_to_0_2_0(cls, execute, data):
table = "lateral_contribution_data_adists"
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, 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_lca_pid(execute, data)
@classmethod
def _db_update_to_0_2_0_set_lca_pid(cls, execute, data):
pid_lca = data["id2pid"]["lateral_contribution_adists"]
els = execute(
"SELECT pamhyr_id, lca " +
"FROM lateral_contribution_data_adists"
)
for row in els:
it = iter(row)
pid = next(it)
lca_id = next(it)
if lca_id == -1:
continue
execute(
f"UPDATE lateral_contribution_data_adists " +
f"SET lca = {pid_lca[lca_id]} " +
f"WHERE pamhyr_id = {pid}"
)
@classmethod
def _db_load(cls, execute, data=None):
new = []
status = data['status']
scenario = data["scenario"]
loaded = data['loaded_pid']
if scenario is None:
return new
table = execute(
"SELECT pamhyr_id, deleted, data0, data1 " +
"FROM lateral_contribution_data_adists " +
f"WHERE scenario = {scenario.id} " +
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
f"AND lca = '{lca.id}'"
)
if table is not None:
for row in table:
it = iter(row)
pid = next(it)
deleted = (next(it) == 1)
data0 = next(it)
data1 = next(it)
owner_scenario = next(it)
data = cls(
data0, data1,
id=pid, status=status,
owner_scenario=owner_scenario
)
if deleted:
data.set_as_deleted()
loaded.add(pid)
new.append(data)
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
lca = data["lca"]
execute(
"INSERT INTO " +
"lateral_contribution_adists(pamhyr_id, deleted," +
"data0, data1, lca, scenario) " +
"VALUES (" +
f"{self.id}, {self._db_format(self.is_deleted())}, " +
f"{self._data[0]}, {self._data[1]}, " +
f"{lca.id}, {self._status.scenario_id}" +
")"
)
return True
def __getitem__(self, key):
return self._types[key](self._data[key])
def __setitem__(self, key, value):
self._data[key] = self._types[key](value)
class LateralContributionAdisTS(SQLSubModel):
_sub_classes = [Data]
def __init__(self, id: int = -1, pollutant: int = -1,
name: str = "", status=None,
owner_scenario=-1):
super(LateralContributionAdisTS, self).__init__(
id=id, status=status,
owner_scenario=owner_scenario
)
self._status = status
self._pollutant = pollutant
self._reach = None
self._begin_rk = 0.0
self._end_rk = 0.0
self._data = []
self._header = ["time", "rate"]
self._types = [self.time_convert, float]
@classmethod
def _db_create(cls, execute, ext=""):
execute(f"""
CREATE TABLE lateral_contribution_adists{ext}(
{cls.create_db_add_pamhyr_id()},
deleted BOOLEAN NOT NULL DEFAULT FALSE,
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)
)
""")
if ext != "":
return True
return cls._create_submodel(execute)
@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
if major == "0" and int(minor) < 2:
if not created:
cls._db_update_to_0_2_0(execute, data)
if not created:
return cls._update_submodel(execute, version, data)
return True
@classmethod @classmethod
def _db_update_to_0_2_0(cls, execute, data): def _db_update_to_0_2_0(cls, execute, data):
table = "lateral_contribution_adists" table = "lateral_contribution_adists"
@ -263,7 +116,7 @@ class LateralContributionAdisTS(SQLSubModel):
cls.update_db_add_pamhyr_id(execute, table, data) cls.update_db_add_pamhyr_id(execute, table, data)
Scenario.update_db_add_scenario(execute, table) Scenario.update_db_add_scenario(execute, table)
cls._db_create(execute, ext="_tmp") cls._db_create_lca(execute, ext="_tmp")
execute( execute(
f"INSERT INTO {table}_tmp " + f"INSERT INTO {table}_tmp " +
@ -300,6 +153,48 @@ class LateralContributionAdisTS(SQLSubModel):
f"WHERE pamhyr_id = {pid}" f"WHERE pamhyr_id = {pid}"
) )
@classmethod
def _db_update_to_0_2_0_data(cls, execute, data):
table = "lateral_contribution_data_adists"
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_ica_pid(execute, data)
@classmethod
def _db_update_to_0_2_0_set_lca_pid(cls, execute, data):
pid_lca = data["id2pid"]["lateral_contribution_adists"]
els = execute(
"SELECT pamhyr_id, lca " +
"FROM lateral_contribution_data_adists"
)
for row in els:
it = iter(row)
pid = next(it)
lca_id = next(it)
if lca_id == -1:
continue
execute(
f"UPDATE lateral_contribution_data_adists " +
f"SET lca = {pid_lca[lca_id]} " +
f"WHERE pamhyr_id = {pid}"
)
@classmethod @classmethod
def _db_load(cls, execute, data=None): def _db_load(cls, execute, data=None):
new = [] new = []
@ -343,8 +238,20 @@ class LateralContributionAdisTS(SQLSubModel):
lca.begin_rk = brk lca.begin_rk = brk
lca.end_rk = erk lca.end_rk = erk
data["lca"] = lca values = execute(
lca._data = Data._db_load(execute, data=data) "SELECT data0, data1 " +
"FROM lateral_contribution_data_adists " +
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 = lca._types[0](v[1])
data1 = lca._types[1](v[2])
# Replace data at pos ind
lca._data.append((data0, data1))
loaded.add(pid) loaded.add(pid)
new.append(lca) new.append(lca)
@ -382,25 +289,21 @@ class LateralContributionAdisTS(SQLSubModel):
")" ")"
) )
ind = 0
for d in self._data: for d in self._data:
data["ind"] = ind data0 = self._db_format(str(d[0]))
data1 = self._db_format(str(d[1]))
d._db_save(execute, data) sql = (
"INSERT INTO " +
ind += 1 "lateral_contribution_data_adists(data0, data1, lca) " +
f"VALUES ('{data0}', {data1}, {self.id})"
)
execute(sql)
return True return True
def __len__(self): def __len__(self):
return len( return len(self._data)
list(
filter(
lambda el: not el.is_deleted(),
self._data
)
)
)
@classmethod @classmethod
def time_convert(cls, data): def time_convert(cls, data):

View File

@ -335,10 +335,7 @@ class Pollutants(SQLSubModel):
if not created: if not created:
cls._db_update_to_0_2_0(execute, data) cls._db_update_to_0_2_0(execute, data)
if not created: return cls._update_submodel(execute, version, data)
return cls._update_submodel(execute, version, data)
return True
@classmethod @classmethod
def _db_update_to_0_2_0(cls, execute, data): def _db_update_to_0_2_0(cls, execute, data):
@ -375,6 +372,7 @@ class Pollutants(SQLSubModel):
"SELECT pamhyr_id, deleted, name FROM pollutants " + "SELECT pamhyr_id, deleted, name FROM pollutants " +
f"WHERE scenario = {scenario.id} " + f"WHERE scenario = {scenario.id} " +
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))})" f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))})"
) )
if table is not None: if table is not None:

View File

@ -171,9 +171,6 @@ class Layer(SQLSubModel):
f"SELECT pamhyr_id, sl FROM {table}" f"SELECT pamhyr_id, sl FROM {table}"
) )
if els is None:
return True
for row in els: for row in els:
it = iter(row) it = iter(row)
pid = next(it) pid = next(it)

View File

@ -303,9 +303,6 @@ class SQLSubModel(PamhyrID):
f"SELECT pamhyr_id, reach FROM {table}" f"SELECT pamhyr_id, reach FROM {table}"
) )
if els is None:
return True
for row in els: for row in els:
it = iter(row) it = iter(row)
pid = next(it) pid = next(it)
@ -320,8 +317,6 @@ class SQLSubModel(PamhyrID):
f"WHERE pamhyr_id = {pid}" f"WHERE pamhyr_id = {pid}"
) )
return True
@classmethod @classmethod
def _db_update_to_0_1_1_assoc_section_from_rk( def _db_update_to_0_1_1_assoc_section_from_rk(
cls, execute, table, cls, execute, table,

View File

@ -64,9 +64,6 @@ class PamhyrID(object):
id2pid = cls.update_db_add_pamhyr_id_init_id2pid(table, data) id2pid = cls.update_db_add_pamhyr_id_init_id2pid(table, data)
rows = execute(f"SELECT id FROM {table}") rows = execute(f"SELECT id FROM {table}")
if rows is None:
return True
for row in rows: for row in rows:
id = row[0] id = row[0]
pid = cls.get_new_pamhyr_id(-1) pid = cls.get_new_pamhyr_id(-1)

View File

@ -89,12 +89,6 @@ class StudyScenarioTestCase(unittest.TestCase):
self.assertEqual(study.name, "Enlargement") self.assertEqual(study.name, "Enlargement")
self.assertEqual(study.status.scenario_id, 0) self.assertEqual(study.status.scenario_id, 0)
def test_open_study_2(self):
study = Study.open("../tests_cases/MassZero/TestMultibiefs.pamhyr")
self.assertNotEqual(study, None)
self.assertEqual(study.name, "TestMultibiefs")
self.assertEqual(study.status.scenario_id, 0)
def test_save_open_study(self): def test_save_open_study(self):
study = Study.new("foo", "bar") study = Study.new("foo", "bar")
new = study.new_scenario_from_current() new = study.new_scenario_from_current()