mirror of https://gitlab.com/pamhyr/pamhyr2
IC: Use section ID instead of RK.
parent
7f87d22249
commit
4023ae73ba
|
|
@ -108,23 +108,6 @@ class HydraulicStructure(SQLSubModel):
|
|||
|
||||
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"
|
||||
|
|
@ -178,6 +161,23 @@ class HydraulicStructure(SQLSubModel):
|
|||
f"WHERE pamhyr_id = {pid}"
|
||||
)
|
||||
|
||||
@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_load(cls, execute, data=None):
|
||||
new = []
|
||||
|
|
|
|||
|
|
@ -29,9 +29,10 @@ logger = logging.getLogger()
|
|||
|
||||
|
||||
class Data(SQLSubModel):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
comment: str = "", reach=None,
|
||||
rk: float = 0.0, discharge: float = 0.0,
|
||||
def __init__(self, id: int = -1,
|
||||
name: str = "", comment: str = "",
|
||||
reach=None, section=None,
|
||||
discharge: float = 0.0,
|
||||
height: float = 0.0,
|
||||
status=None):
|
||||
super(Data, self).__init__(id)
|
||||
|
|
@ -43,13 +44,13 @@ class Data(SQLSubModel):
|
|||
self._name = name
|
||||
self._comment = comment
|
||||
|
||||
self._rk = rk
|
||||
self._section = section
|
||||
self._discharge = discharge
|
||||
self._speed = 0.0
|
||||
self._elevation = 0.0
|
||||
self._height = height
|
||||
|
||||
if self._rk != 0.0:
|
||||
if self._section is not None:
|
||||
self._update_from_rk()
|
||||
if self._height != 0.0:
|
||||
self._update_from_height()
|
||||
|
|
@ -65,7 +66,7 @@ class Data(SQLSubModel):
|
|||
name TEXT NOT NULL,
|
||||
comment TEXT NOT NULL,
|
||||
reach INTEGER,
|
||||
rk REAL NOT NULL,
|
||||
section INTEGER,
|
||||
discharge REAL NOT NULL,
|
||||
height REAL NOT NULL,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
|
|
@ -88,6 +89,10 @@ class Data(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
|
||||
|
|
@ -95,6 +100,10 @@ class Data(SQLSubModel):
|
|||
table = "initial_conditions"
|
||||
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)
|
||||
|
||||
|
|
@ -102,9 +111,9 @@ class Data(SQLSubModel):
|
|||
|
||||
execute(
|
||||
f"INSERT INTO {table}_tmp " +
|
||||
"(pamhyr_id, ind, name, comment, reach, rk, " +
|
||||
"(pamhyr_id, ind, name, comment, reach, section, " +
|
||||
"discharge, height, scenario) " +
|
||||
"SELECT pamhyr_id, ind, name, comment, reach, rk, " +
|
||||
"SELECT pamhyr_id, ind, name, comment, reach, section, " +
|
||||
"discharge, height, scenario " +
|
||||
f"FROM {table}"
|
||||
)
|
||||
|
|
@ -114,11 +123,25 @@ class Data(SQLSubModel):
|
|||
|
||||
cls._db_update_to_0_1_0_set_reach_pid(execute, table, reachs)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_1(cls, execute, data,
|
||||
origin_version="0.1.0"):
|
||||
execute(
|
||||
"ALTER TABLE initial_conditions " +
|
||||
f"ADD COLUMN section INTEGER"
|
||||
)
|
||||
|
||||
cls._db_update_to_0_1_1_assoc_section_from_rk(
|
||||
execute, "initial_conditions",
|
||||
origin_version=origin_version
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
id = data["reach"].pamhyr_id
|
||||
reach = data["reach"]
|
||||
id = reach.pamhyr_id
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, ind, name, comment, rk, discharge, height " +
|
||||
"SELECT pamhyr_id, ind, name, comment, section, discharge, height " +
|
||||
"FROM initial_conditions " +
|
||||
f"WHERE reach = {id} " +
|
||||
"ORDER BY ind ASC"
|
||||
|
|
@ -133,17 +156,25 @@ class Data(SQLSubModel):
|
|||
ind = next(it)
|
||||
name = next(it)
|
||||
comment = next(it)
|
||||
rk = next(it)
|
||||
section_id = next(it)
|
||||
discharge = next(it)
|
||||
height = next(it)
|
||||
|
||||
section = reduce(
|
||||
lambda acc, s: (
|
||||
s if s.pamhyr_id == section_id else acc
|
||||
),
|
||||
reach.reach.profiles,
|
||||
None
|
||||
)
|
||||
|
||||
d = cls(
|
||||
id=pid,
|
||||
reach=data["reach"],
|
||||
status=data["status"],
|
||||
name=name,
|
||||
comment=comment,
|
||||
rk=rk,
|
||||
section=section,
|
||||
discharge=discharge,
|
||||
height=height,
|
||||
)
|
||||
|
|
@ -157,13 +188,13 @@ class Data(SQLSubModel):
|
|||
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
"initial_conditions(pamhyr_id, ind, name, comment, rk, " +
|
||||
"initial_conditions(pamhyr_id, ind, name, comment, section, " +
|
||||
"discharge, height, reach) " +
|
||||
"VALUES (" +
|
||||
f"{self.pamhyr_id}, " +
|
||||
f"{ind}, '{self._db_format(self.name)}', " +
|
||||
f"'{self._db_format(self._comment)}', " +
|
||||
f"{self._rk}, {self._discharge}, {self._height}, " +
|
||||
f"{self._section.id}, {self._discharge}, {self._height}, " +
|
||||
f"{self._reach.id}" +
|
||||
")"
|
||||
)
|
||||
|
|
@ -174,7 +205,7 @@ class Data(SQLSubModel):
|
|||
new = Data(
|
||||
name=self.name,
|
||||
comment=self._comment,
|
||||
rk=self._rk,
|
||||
section=self._section,
|
||||
discharge=self._discharge,
|
||||
height=self._height,
|
||||
reach=self._reach,
|
||||
|
|
@ -194,7 +225,7 @@ class Data(SQLSubModel):
|
|||
elif key == "comment":
|
||||
val = self._comment
|
||||
elif key == "rk":
|
||||
val = self._rk
|
||||
val = self._section
|
||||
elif key == "speed":
|
||||
val = self._speed
|
||||
elif key == "discharge":
|
||||
|
|
@ -207,9 +238,9 @@ class Data(SQLSubModel):
|
|||
return val
|
||||
|
||||
def _update_get_min(self):
|
||||
profile = self._reach.reach.get_profiles_from_rk(self._rk)
|
||||
if len(profile) > 0:
|
||||
min = profile[0].z_min()
|
||||
profile = self._section
|
||||
if profile is not None:
|
||||
min = profile.z_min()
|
||||
else:
|
||||
min = 0.0
|
||||
|
||||
|
|
@ -237,7 +268,7 @@ class Data(SQLSubModel):
|
|||
elif key == "comment":
|
||||
self._comment = str(value)
|
||||
elif key == "rk":
|
||||
self._rk = float(value)
|
||||
self._section = value
|
||||
self._update_from_rk()
|
||||
elif key == "speed":
|
||||
# Not supposed to be modified
|
||||
|
|
@ -384,7 +415,12 @@ class InitialConditions(SQLSubModel):
|
|||
)
|
||||
|
||||
def get_rk(self):
|
||||
return self._data_get("rk")
|
||||
return list(
|
||||
map(
|
||||
lambda d: d["rk"].rk,
|
||||
self._data
|
||||
)
|
||||
)
|
||||
|
||||
def get_elevation(self):
|
||||
return self._data_get("elevation")
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
import logging
|
||||
import traceback
|
||||
from tools import trace, timer
|
||||
from functools import reduce
|
||||
|
||||
from PyQt5.QtCore import (
|
||||
Qt, QVariant, QAbstractTableModel,
|
||||
|
|
@ -58,8 +59,8 @@ class ComboBoxDelegate(QItemDelegate):
|
|||
self.editor.addItems(
|
||||
list(
|
||||
map(
|
||||
str,
|
||||
self._reach.get_rk()
|
||||
lambda p: p.display_name(),
|
||||
self._reach.profiles
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
@ -73,7 +74,13 @@ class ComboBoxDelegate(QItemDelegate):
|
|||
|
||||
def setModelData(self, editor, model, index):
|
||||
text = str(editor.currentText())
|
||||
model.setData(index, text)
|
||||
val = reduce(
|
||||
lambda acc, p: p if text == p.display_name() else acc,
|
||||
self._reach.profiles,
|
||||
None
|
||||
)
|
||||
|
||||
model.setData(index, val)
|
||||
editor.close()
|
||||
editor.deleteLater()
|
||||
|
||||
|
|
@ -104,14 +111,15 @@ class InitialConditionTableModel(PamhyrTableModel):
|
|||
row = index.row()
|
||||
column = index.column()
|
||||
|
||||
if self._headers[column] is "speed":
|
||||
if self._headers[column] is "rk":
|
||||
v = self._lst.get(row)[self._headers[column]]
|
||||
return v.display_name()
|
||||
elif self._headers[column] is "speed":
|
||||
z = self._lst.get(row)["elevation"]
|
||||
q = self._lst.get(row)["discharge"]
|
||||
profile = self._reach.reach.get_profiles_from_rk(
|
||||
self._lst.get(row)["rk"]
|
||||
)
|
||||
profile = self._lst.get(row)["rk"]
|
||||
if len(profile) >= 1:
|
||||
speed = profile[0].speed(q, z)
|
||||
speed = profile.speed(q, z)
|
||||
return f"{speed:.4f}"
|
||||
|
||||
return ""
|
||||
|
|
|
|||
|
|
@ -40,6 +40,9 @@ class SetCommand(QUndoCommand):
|
|||
if column == "name" or column == "comment":
|
||||
_type = str
|
||||
|
||||
if column == "rk":
|
||||
_type = lambda x: x
|
||||
|
||||
self._new = _type(new_value)
|
||||
|
||||
def undo(self):
|
||||
|
|
|
|||
Loading…
Reference in New Issue