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