mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
HS: Use section ID instead of RK.
This commit is contained in:
1 parent
6225f8940e
commit
7f87d22249
7 files changed
+176
-60
No files matched your search
@@ -46,8 +46,8 @@ class HydraulicStructure(SQLSubModel):
|
||||
self._status = status
|
||||
|
||||
self._name = name
|
||||
self._input_rk = None
|
||||
self._output_rk = None
|
||||
self._input_section = None
|
||||
self._output_section = None
|
||||
self._input_reach = None
|
||||
self._output_reach = None
|
||||
self._enabled = True
|
||||
@@ -60,14 +60,18 @@ class HydraulicStructure(SQLSubModel):
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
name TEXT NOT NULL,
|
||||
enabled BOOLEAN NOT NULL,
|
||||
input_rk REAL NOT NULL,
|
||||
output_rk REAL NOT NULL,
|
||||
input_reach INTEGER,
|
||||
output_reach INTEGER,
|
||||
input_section INTEGER,
|
||||
output_section INTEGER,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
FOREIGN KEY(input_reach) REFERENCES river_reach(pamhyr_id),
|
||||
FOREIGN KEY(output_reach) REFERENCES river_reach(pamhyr_id),
|
||||
FOREIGN KEY(input_section)
|
||||
REFERENCES geometry_profileXYZ(pamhyr_id),
|
||||
FOREIGN KEY(output_section)
|
||||
REFERENCES geometry_profileXYZ(pamhyr_id),
|
||||
PRIMARY KEY(pamhyr_id, scenario)
|
||||
)
|
||||
""")
|
||||
@@ -98,13 +102,38 @@ class HydraulicStructure(SQLSubModel):
|
||||
|
||||
cls._db_update_to_0_1_0(execute, data)
|
||||
|
||||
if major == "0" and minor == "1":
|
||||
if int(release) < 1:
|
||||
cls._db_update_to_0_1_1(execute, data)
|
||||
|
||||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_1(cls, execute, data,
|
||||
origin_version="0.1.0"):
|
||||
for v in ["input", "output"]:
|
||||
execute(
|
||||
"ALTER TABLE hydraulic_structures " +
|
||||
f"ADD COLUMN {v}_section INTEGER"
|
||||
)
|
||||
|
||||
cls._db_update_to_0_1_1_assoc_section_from_rk(
|
||||
execute, "hydraulic_structures",
|
||||
reach_column=f"{v}_reach",
|
||||
rk_column=f"{v}_rk",
|
||||
section_column=f"{v}_section",
|
||||
origin_version=origin_version
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0(cls, execute, data):
|
||||
table = "hydraulic_structures"
|
||||
reachs = data['id2pid']['river_reach']
|
||||
|
||||
cls._db_update_to_0_1_1(
|
||||
execute, data,
|
||||
origin_version="0.0.*"
|
||||
)
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
@@ -112,9 +141,9 @@ class HydraulicStructure(SQLSubModel):
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table}_tmp " +
|
||||
"(pamhyr_id, name, enabled, input_rk, output_rk, " +
|
||||
"(pamhyr_id, name, enabled, input_section, output_section, " +
|
||||
"input_reach, output_reach, scenario) " +
|
||||
"SELECT pamhyr_id, name, enabled, input_rk, output_rk, " +
|
||||
"SELECT pamhyr_id, name, enabled, input_section, output_section, " +
|
||||
"input_reach, output_reach, scenario " +
|
||||
f"FROM {table}"
|
||||
)
|
||||
@@ -155,7 +184,7 @@ class HydraulicStructure(SQLSubModel):
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, name, enabled, " +
|
||||
"input_rk, output_rk, " +
|
||||
"input_section, output_section, " +
|
||||
"input_reach, output_reach " +
|
||||
"FROM hydraulic_structures"
|
||||
)
|
||||
@@ -166,29 +195,44 @@ class HydraulicStructure(SQLSubModel):
|
||||
hs_id = next(it)
|
||||
name = next(it)
|
||||
enabled = (next(it) == 1)
|
||||
input_rk = next(it)
|
||||
output_rk = next(it)
|
||||
input_section_id = next(it)
|
||||
input_section_id = (
|
||||
-1 if input_section_id is None else input_section_id
|
||||
)
|
||||
output_section_id = next(it)
|
||||
output_section_id = (
|
||||
-1 if output_section_id is None else output_section_id
|
||||
)
|
||||
input_reach_id = next(it)
|
||||
output_reach_id = next(it)
|
||||
|
||||
hs = cls(
|
||||
id=hs_id,
|
||||
name=name,
|
||||
status=data['status']
|
||||
id=hs_id, name=name, status=data['status']
|
||||
)
|
||||
|
||||
hs.enabled = enabled
|
||||
hs.input_rk = input_rk if input_rk != -1 else None
|
||||
hs.output_rk = output_rk if output_rk != -1 else None
|
||||
|
||||
hs.input_reach, hs.output_reach = reduce(
|
||||
lambda acc, n: (
|
||||
n if n.id == input_reach_id else acc[0],
|
||||
n if n.id == output_reach_id else acc[1]
|
||||
n if n.pamhyr_id == input_reach_id else acc[0],
|
||||
n if n.pamhyr_id == output_reach_id else acc[1]
|
||||
),
|
||||
data["edges"],
|
||||
[None, None]
|
||||
)
|
||||
sections = []
|
||||
if hs.input_reach is not None:
|
||||
sections += hs.input_reach.reach.profiles
|
||||
if hs.output_reach is not None:
|
||||
sections += hs.output_reach.reach.profiles
|
||||
|
||||
hs.input_section, hs.output_section = reduce(
|
||||
lambda acc, s: (
|
||||
s if s.pamhyr_id == input_section_id else acc[0],
|
||||
s if s.pamhyr_id == output_section_id else acc[1]
|
||||
),
|
||||
sections,
|
||||
[None, None]
|
||||
)
|
||||
|
||||
data['hs_id'] = hs_id
|
||||
hs._data = BasicHS._db_load(execute, data)
|
||||
@@ -211,24 +255,24 @@ class HydraulicStructure(SQLSubModel):
|
||||
if self._output_reach is not None:
|
||||
output_reach_id = self._output_reach.pamhyr_id
|
||||
|
||||
input_rk = -1
|
||||
if self.input_rk is not None:
|
||||
input_rk = self.input_rk
|
||||
input_section = 'NULL'
|
||||
if self.input_section is not None:
|
||||
input_section = self.input_section.pamhyr_id
|
||||
|
||||
output_rk = -1
|
||||
if self.output_rk is not None:
|
||||
output_rk = self.output_rk
|
||||
output_section = 'NULL'
|
||||
if self.output_section is not None:
|
||||
output_section = self.output_section.pamhyr_id
|
||||
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
"hydraulic_structures(" +
|
||||
" pamhyr_id, name, enabled, input_rk, output_rk, " +
|
||||
" pamhyr_id, name, enabled, input_section, output_section, " +
|
||||
" input_reach, output_reach" +
|
||||
") " +
|
||||
"VALUES (" +
|
||||
f"{self.pamhyr_id}, '{self._db_format(self._name)}', " +
|
||||
f"{self._db_format(self.enabled)}, " +
|
||||
f"{input_rk}, {output_rk}, " +
|
||||
f"{input_section}, {output_section}, " +
|
||||
f"{input_reach_id}, {output_reach_id}" +
|
||||
")"
|
||||
)
|
||||
@@ -261,23 +305,32 @@ class HydraulicStructure(SQLSubModel):
|
||||
|
||||
@property
|
||||
def input_rk(self):
|
||||
return self._input_rk
|
||||
|
||||
@input_rk.setter
|
||||
def input_rk(self, input_rk):
|
||||
if input_rk is not None:
|
||||
input_rk = float(input_rk)
|
||||
|
||||
self._input_rk = input_rk
|
||||
self._status.modified()
|
||||
if self._input_section is None:
|
||||
return None
|
||||
return self._input_section.rk
|
||||
|
||||
@property
|
||||
def output_rk(self):
|
||||
return self._output_rk
|
||||
if self._output_section is None:
|
||||
return None
|
||||
return self._output_section.rk
|
||||
|
||||
@output_rk.setter
|
||||
def output_rk(self, output_rk):
|
||||
self._output_rk = output_rk
|
||||
@property
|
||||
def input_section(self):
|
||||
return self._input_section
|
||||
|
||||
@input_section.setter
|
||||
def input_section(self, input_section):
|
||||
self._input_section = input_section
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def output_section(self):
|
||||
return self._output_section
|
||||
|
||||
@output_section.setter
|
||||
def output_section(self, output_section):
|
||||
self._output_section = output_section
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
|
||||
Reference in new issue
Block a user