Adists: Fix missing and update outputrk for scenario.

scenarios
Pierre-Antoine 2025-08-14 16:32:22 +02:00
parent 31af83ba02
commit 468405d4ea
4 changed files with 41 additions and 15 deletions

View File

@ -152,6 +152,9 @@ class BoundaryConditionAdisTS(SQLSubModel):
scenario = data["scenario"]
loaded = data['loaded_pid']
if scenario is None:
return new
table = execute(
"SELECT pamhyr_id, pollutant, type, node, scenario " +
"FROM boundary_condition_adists " +

View File

@ -102,6 +102,9 @@ class D90AdisTS(SQLSubModel):
scenario = data["scenario"]
loaded = data['loaded_pid']
if scenario is None:
return new
table = execute(
"SELECT pamhyr_id, name, d90, enabled, scenario " +
"FROM d90_adists " +

View File

@ -109,6 +109,9 @@ class DIFAdisTS(SQLSubModel):
scenario = data["scenario"]
loaded = data['loaded_pid']
if scenario is None:
return new
table = execute(
"SELECT pamhyr_id, name, method, dif, b, c, enabled, scenario " +
"FROM dif_adists " +

View File

@ -43,8 +43,6 @@ class OutputRKAdists(SQLSubModel):
owner_scenario=owner_scenario
)
self._status = status
self._reach = reach
self._rk = rk
self._title = str(title)
@ -131,48 +129,67 @@ class OutputRKAdists(SQLSubModel):
@classmethod
def _db_load(cls, execute, data=None):
new = []
status = data['status']
scenario = data["scenario"]
loaded = data['loaded_pid']
# reach = data["reach"]
# profile = data["profile"]
status = data["status"]
if scenario is None:
return new
table = execute(
"SELECT pamhyr_id, reach, rk, title " +
"SELECT pamhyr_id, reach, rk, title, scenario " +
f"FROM OutputRKAdists"
)
if table is not None:
for row in table:
id = row[0]
id_reach = row[1]
id_rk = row[2]
title = row[3]
it = iter(row)
pid = next(it)
id_reach = next(it)
id_rk = next(it)
title = next(it)
owner_scenario = next(it)
new_output = cls(
id=id, reach=id_reach,
id=pid, reach=id_reach,
rk=id_rk, title=title,
status=status
status=status,
owner_scenario=owner_scenario,
)
loaded.add(pid)
new.append(new_output)
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 OutputRKAdists WHERE id = {self.id}")
execute(
"DELETE FROM OutputRKAdists " +
f"WHERE pamhyr_id = {self.id} " +
f"AND scenario = {self._status.scenario_id} "
)
sql = (
execute(
"INSERT INTO " +
"OutputRKAdists(pamhyr_id, reach, rk, title) " +
"OutputRKAdists(pamhyr_id, reach, rk, title, scenario) " +
"VALUES (" +
f"{self.id}, {self._reach}, {self._rk}, " +
f"'{self._db_format(self._title)}'" +
f"{self._status.scenario_id}" +
")"
)
execute(sql)
return True
@property