Compare commits

..

2 Commits

Author SHA1 Message Date
Pierre-Antoine a525d8a2b0 Adists: Scenario: Minor fix. 2025-08-13 16:23:46 +02:00
Pierre-Antoine d7fcf62e12 Adists: Scenario: Some minor fix. 2025-08-13 15:03:25 +02:00
14 changed files with 45 additions and 40 deletions

View File

@ -95,7 +95,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
if int(release) < 7:
cls._db_create(execute)
if major == "0" and int(minor) < 2:
elif major == "0" and int(minor) < 2:
cls._db_update_to_0_2_0(execute, data)
return True
@ -149,7 +149,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
new = []
table = execute(
"SELECT id, pollutant, type, node " +
"SELECT pamhyr_id, pollutant, type, node " +
"FROM boundary_condition_adists"
)

View File

@ -72,7 +72,7 @@ class D90AdisTS(SQLSubModel):
if int(release) < 6:
cls._db_create(execute)
if major == "0" and int(minor) < 2:
elif major == "0" and int(minor) < 2:
cls._db_update_to_0_2_0(execute, data)
return True
@ -101,7 +101,7 @@ class D90AdisTS(SQLSubModel):
new = []
table = execute(
"SELECT id, name, d90, enabled " +
"SELECT pamhyr_id, name, d90, enabled " +
"FROM d90_adists"
)
@ -129,7 +129,7 @@ class D90AdisTS(SQLSubModel):
return new
def _db_save(self, execute, data=None):
execute(f"DELETE FROM d90_adists WHERE id = {self.id}")
execute(f"DELETE FROM d90_adists WHERE pamhyr_id = {self.id}")
d90 = -1.
if self.d90 is not None:
@ -138,7 +138,7 @@ class D90AdisTS(SQLSubModel):
sql = (
"INSERT INTO " +
"d90_adists(" +
"id, name, d90, enabled" +
"pamhyr_id, name, d90, enabled" +
") " +
"VALUES (" +
f"{self.id}, '{self._db_format(self._name)}', " +

View File

@ -78,7 +78,7 @@ class DIFAdisTS(SQLSubModel):
if int(release) < 6:
cls._db_create(execute)
if major == "0" and int(minor) < 2:
elif major == "0" and int(minor) < 2:
cls._db_update_to_0_2_0(execute, data)
return True
@ -107,7 +107,7 @@ class DIFAdisTS(SQLSubModel):
new = []
table = execute(
"SELECT id, name, method, dif, b, c, enabled " +
"SELECT pamhyr_id, name, method, dif, b, c, enabled " +
"FROM dif_adists"
)

View File

@ -82,7 +82,7 @@ class InitialConditionsAdisTS(SQLSubModel):
if int(release) < 6:
cls._db_create(execute)
if major == "0" and int(minor) < 2:
elif major == "0" and int(minor) < 2:
cls._db_update_to_0_2_0(execute, data)
return True
@ -99,8 +99,10 @@ class InitialConditionsAdisTS(SQLSubModel):
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) " +
"(pamhyr_id, pollutant, name, concentration, " +
"eg, em, ed, scenario) " +
"SELECT pamhyr_id, pollutant, name, concentration, " +
"eg, em, ed, scenario) " +
f"FROM {table}"
)
@ -114,8 +116,8 @@ class InitialConditionsAdisTS(SQLSubModel):
new = []
table = execute(
"SELECT id, pollutant, name, concentration, eg, em, ed, " +
"enabled " +
"SELECT pamhyr_id, pollutant, name, concentration, eg, em, ed, " +
"enabled, scenario " +
"FROM initial_conditions_adists"
)
@ -176,7 +178,7 @@ class InitialConditionsAdisTS(SQLSubModel):
sql = (
"INSERT INTO " +
"initial_conditions_adists(" +
"id, pollutant, name, concentration, " +
"pamhyr_id, pollutant, name, concentration, " +
"eg, em, ed, enabled" +
") " +
"VALUES (" +

View File

@ -97,7 +97,7 @@ class LateralContributionAdisTS(SQLSubModel):
if int(release) < 7:
cls._db_create(execute)
if major == "0" and int(minor) < 2:
elif major == "0" and int(minor) < 2:
cls._db_update_to_0_2_0(execute, data)
return True
@ -153,8 +153,11 @@ class LateralContributionAdisTS(SQLSubModel):
scenario = data["scenario"]
loaded = data['loaded_pid']
if scenario is None:
return new
table = execute(
"SELECT id, pollutant, edge, begin_rk, end_rk " +
"SELECT pamhyr_id, pollutant, reach, begin_rk, end_rk " +
"FROM lateral_contribution_adists " +
f"WHERE scenario = {scenario.id} " +
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
@ -173,8 +176,8 @@ class LateralContributionAdisTS(SQLSubModel):
lca.end_rk = row[4]
values = execute(
"SELECT data0," +
" data1 FROM lateral_contribution_data_adists " +
"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}'"
@ -201,12 +204,12 @@ class LateralContributionAdisTS(SQLSubModel):
execute(
f"DELETE FROM lateral_contribution_adists " +
f" WHERE id = {self.id} " +
f"WHERE pamhyr_id = {self.id} " +
f"AND scenario = {self._status.scenario_id}"
)
execute(
f"DELETE FROM lateral_contribution_data_adists " +
f" WHERE lc = {self.id} " +
f"WHERE lca = {self.id} " +
f"AND scenario = {self._status.scenario_id}"
)
@ -228,7 +231,7 @@ class LateralContributionAdisTS(SQLSubModel):
sql = (
"INSERT INTO " +
"lateral_contribution_data_adists(data0, data1, lc) " +
"lateral_contribution_data_adists(data0, data1, lca) " +
f"VALUES ('{data0}', {data1}, {self.id})"
)
execute(sql)

View File

@ -100,7 +100,7 @@ class OutputRKAdists(SQLSubModel):
if int(release) < 7:
cls._db_create(execute)
if major == "0" and int(minor) <= 2:
elif major == "0" and int(minor) <= 2:
if int(release) <= 0:
cls._db_update_to_0_2_0(execute, data)
@ -137,7 +137,7 @@ class OutputRKAdists(SQLSubModel):
status = data["status"]
table = execute(
"SELECT id, reach, rk, title " +
"SELECT pamhyr_id, reach, rk, title " +
f"FROM OutputRKAdists"
)
@ -164,7 +164,7 @@ class OutputRKAdists(SQLSubModel):
sql = (
"INSERT INTO " +
"OutputRKAdists(id, reach, rk, title) " +
"OutputRKAdists(pamhyr_id, reach, rk, title) " +
"VALUES (" +
f"{self.id}, {self._reach}, {self._rk}, " +
f"'{self._db_format(self._title)}'" +

View File

@ -40,7 +40,7 @@ class OutputRKAdistsList(PamhyrModelList):
# Delete previous data
execute(
"DELETE FROM OutputRKAdists " +
f"AND scenario = {self._status.scenario_id}"
f"WHERE scenario = {self._status.scenario_id}"
)
for sl in self._lst:

View File

@ -100,7 +100,7 @@ class RiverNode(Node):
def _db_update(cls, execute, version, data=None):
major, minor, release = version.strip().split(".")
if major == minor == "0":
if major == "0" and int(minor) < 2:
cls._db_update_to_0_2_0(execute, data=data)
if major == "0" and minor == "1":

View File

@ -277,10 +277,10 @@ class Study(SQLModel):
"INSERT INTO info VALUES ('study_release', '0')"
)
if major == "0" and int(minor) <= 1:
if major == "0" and int(minor) <= 2:
self._add_into_info_if_not_exists('current_scenario', '0')
if major == "0" and int(minor) < 1:
if major == "0" and int(minor) < 2:
# Need to temporary disable the sqlite foreign keys
# checking to update db dans change the table id fk to
# table pamhyr_id fk
@ -290,7 +290,7 @@ class Study(SQLModel):
ok = self._update_submodel(version[0], data={})
if major == "0" and int(minor) < 1:
if major == "0" and int(minor) < 2:
# Reactivate foreign keys checking
self.execute(
"PRAGMA foreign_keys = ON;"