HS: Add to scenarios.

This commit is contained in:
Pierre-Antoine Rouby committed 2024-08-28 16:04:19 +02:00
1 parent 9ec21d815d
commit 60ee889794
10 files changed
+296 -165

No files matched your search

+26 -10
View File
@@ -26,10 +26,11 @@ class BHSValue(SQLSubModel):
def __init__(self, id: int = -1, name: str = "",
type=float, value=0.0,
status=None):
super(BHSValue, self).__init__(id)
self._status = status
status=None, owner_scenario=-1):
super(BHSValue, self).__init__(
id=id, status=status,
owner_scenario=owner_scenario
)
self._name = name
self._type = type
@@ -132,12 +133,20 @@ class BHSValue(SQLSubModel):
@classmethod
def _db_load(cls, execute, data=None):
new = []
status = data["status"]
scenario = data["scenario"]
loaded = data['loaded_pid']
bhs_id = data["bhs_id"]
if scenario is None:
return []
table = execute(
"SELECT pamhyr_id, name, type, value " +
"SELECT pamhyr_id, name, type, value, scenario " +
"FROM hydraulic_structures_basic_value " +
f"WHERE bhs = '{bhs_id}'"
f"WHERE bhs = '{bhs_id}' " +
f"AND scenario = {scenario.id} " +
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))})"
)
for row in table:
@@ -147,14 +156,20 @@ class BHSValue(SQLSubModel):
name = next(it)
type = cls._str_to_type(next(it))
value = next(it)
owner_scenario = next(it)
val = cls(
id=pid, name=name,
type=type, value=value,
status=data['status']
status=status, owner_scenario=owner_scenario
)
new.append(val)
loaded.add(pid)
data["scenario"] = scenario.parent
new += cls._db_load(execute, data)
data["scenario"] = scenario
return new
@@ -164,13 +179,14 @@ class BHSValue(SQLSubModel):
execute(
"INSERT INTO " +
"hydraulic_structures_basic_value" +
"(pamhyr_id, name, type, value, bhs) " +
"(pamhyr_id, name, type, value, bhs, scenario) " +
"VALUES (" +
f"{self._pamhyr_id}, " +
f"'{self._db_format(self._name)}', " +
f"'{self._db_format(self._type_to_str(self._type))}', " +
f"'{self._db_format(self._value)}', " +
f"{bhs_id}" +
f"{bhs_id}, " +
f"{self._status.scenario_id}"
")"
)
@@ -191,4 +207,4 @@ class BHSValue(SQLSubModel):
@value.setter
def value(self, value):
self._value = self._type(value)
self._status.modified()
self.modified()