mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
28c23ee580 | ||
|
|
71c5aec876 | ||
|
|
3ce9e094e7 |
No files matched your search
@@ -72,8 +72,7 @@ class Friction(SQLSubModel):
|
||||
major, minor, release = version.strip().split(".")
|
||||
if major == minor == "0":
|
||||
if int(release) < 11:
|
||||
execute("ALTER TABLE friction " +
|
||||
"RENAME COLUMN begin_kp TO begin_rk")
|
||||
execute("ALTER TABLE friction RENAME COLUMN begin_kp TO begin_rk")
|
||||
execute("ALTER TABLE friction RENAME COLUMN end_kp TO end_rk")
|
||||
|
||||
return True
|
||||
|
||||
@@ -147,6 +147,7 @@ class Data(SQLSubModel):
|
||||
reach=self._reach,
|
||||
status=self._status,
|
||||
)
|
||||
|
||||
return new
|
||||
|
||||
@property
|
||||
@@ -374,39 +375,25 @@ class InitialConditions(SQLSubModel):
|
||||
key=lambda p: p.rk
|
||||
)
|
||||
|
||||
def generate_growing_constante_height(self, height: float,
|
||||
compute_discharge: bool):
|
||||
def generate_growing_constante_height(self, height: float):
|
||||
self._data = []
|
||||
|
||||
profiles = self._reach.reach.profiles.copy()
|
||||
self._sort_by_z_and_rk(profiles)
|
||||
|
||||
previous_elevation = -99999.99
|
||||
|
||||
data_discharge = {}
|
||||
if not compute_discharge:
|
||||
if len(self._data) == 0:
|
||||
for profile in profiles:
|
||||
data_discharge[profile.rk] = 0.0
|
||||
else:
|
||||
for data in self._data:
|
||||
data_discharge[data["rk"]] = data["discharge"]
|
||||
|
||||
incline = self._reach.reach.get_incline_median_mean()
|
||||
logger.debug(f"incline = {incline}")
|
||||
self._data = []
|
||||
|
||||
previous_elevation = -99999.99
|
||||
for profile in profiles:
|
||||
width = profile.width_approximation()
|
||||
strickler = 25
|
||||
|
||||
if not compute_discharge:
|
||||
discharge = data_discharge[profile.rk]
|
||||
else:
|
||||
discharge = (
|
||||
((width * 0.8)
|
||||
* strickler
|
||||
* (height ** (5/3))
|
||||
* (abs(incline) ** (0.5)))
|
||||
)
|
||||
discharge = (
|
||||
((width * 0.8)
|
||||
* strickler
|
||||
* (height ** (5/3))
|
||||
* (abs(incline) ** (0.5)))
|
||||
)
|
||||
|
||||
elevation = max(
|
||||
profile.z_min() + height,
|
||||
@@ -421,44 +408,38 @@ class InitialConditions(SQLSubModel):
|
||||
new = Data(reach=self._reach, status=self._status)
|
||||
new["rk"] = profile.rk
|
||||
new["discharge"] = discharge
|
||||
|
||||
new["elevation"] = elevation
|
||||
|
||||
previous_elevation = elevation
|
||||
self._data.append(new)
|
||||
previous_elevation = elevation
|
||||
|
||||
self._generate_resort_data(profiles)
|
||||
|
||||
def generate_discharge(self, discharge: float, compute_height: bool):
|
||||
def generate_discharge(self, discharge: float):
|
||||
self._data = []
|
||||
|
||||
self._generate_height_estimation_from_discharge(
|
||||
discharge
|
||||
)
|
||||
|
||||
def _generate_height_estimation_from_discharge(self, discharge: float):
|
||||
profiles = self._reach.reach.profiles.copy()
|
||||
self._sort_by_z_and_rk(profiles)
|
||||
|
||||
previous_elevation = -99999.99
|
||||
|
||||
data_height = {}
|
||||
if not compute_height:
|
||||
if len(self._data) == 0:
|
||||
for profile in profiles:
|
||||
data_height[profile.rk] = 0.0
|
||||
else:
|
||||
for data in self._data:
|
||||
data_height[data["rk"]] = data["height"]
|
||||
|
||||
incline = self._reach.reach.get_incline_median_mean()
|
||||
logger.debug(f"incline = {incline}")
|
||||
self._data = []
|
||||
|
||||
for profile in profiles:
|
||||
width = profile.width_approximation()
|
||||
strickler = 25
|
||||
|
||||
if not compute_height:
|
||||
height = data_height[profile.rk]
|
||||
else:
|
||||
height = (
|
||||
discharge
|
||||
/
|
||||
((width * 0.8) * strickler * (abs(incline) ** (0.5)))
|
||||
) ** (0.6)
|
||||
height = (
|
||||
discharge
|
||||
/
|
||||
((width * 0.8) * strickler * (abs(incline) ** (0.5)))
|
||||
) ** (0.6)
|
||||
|
||||
elevation = max(
|
||||
profile.z_min() + height,
|
||||
|
||||
+3
-3
@@ -230,16 +230,16 @@ class Study(SQLModel):
|
||||
)
|
||||
self.execute(
|
||||
"INSERT INTO info VALUES ('date', " +
|
||||
f"'{timestamp(self._date)}')"
|
||||
f"'{self._date.timestamp()}')"
|
||||
)
|
||||
|
||||
self.execute(
|
||||
"INSERT INTO info VALUES ('creation_date', " +
|
||||
f"'{timestamp(self.creation_date)}')"
|
||||
f"'{self.creation_date.timestamp()}')"
|
||||
)
|
||||
self.execute(
|
||||
"INSERT INTO info VALUES ('last_save_date', " +
|
||||
f"'{timestamp(self.last_save_date)}')"
|
||||
f"'{self.last_save_date.timestamp()}')"
|
||||
)
|
||||
|
||||
self._create_submodel()
|
||||
|
||||
@@ -61,7 +61,7 @@ class GeometryTranslate(MainTranslate):
|
||||
|
||||
self._sub_dict["table_headers"] = {
|
||||
"name": self._dict["name"],
|
||||
"rk": self._dict["unit_rk"],
|
||||
"rk": self._dict["unit_rk_short"],
|
||||
"poins": _translate("Geometry", "Points"),
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ from PyQt5.QtCore import (
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QDialogButtonBox, QComboBox, QUndoStack, QShortcut,
|
||||
QDoubleSpinBox, QCheckBox,
|
||||
QDoubleSpinBox,
|
||||
)
|
||||
|
||||
|
||||
@@ -45,11 +45,9 @@ class DischargeDialog(PamhyrDialog):
|
||||
)
|
||||
|
||||
self.value = None
|
||||
self.option = None
|
||||
|
||||
def accept(self):
|
||||
self.value = self.find(QDoubleSpinBox, "doubleSpinBox").value()
|
||||
self.option = self.find(QCheckBox, "checkBox").isChecked()
|
||||
super().accept()
|
||||
|
||||
def reject(self):
|
||||
|
||||
@@ -28,7 +28,7 @@ from PyQt5.QtCore import (
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QDialogButtonBox, QComboBox, QUndoStack, QShortcut,
|
||||
QDoubleSpinBox, QCheckBox,
|
||||
QDoubleSpinBox,
|
||||
)
|
||||
|
||||
|
||||
@@ -45,11 +45,9 @@ class HeightDialog(PamhyrDialog):
|
||||
)
|
||||
|
||||
self.value = None
|
||||
self.option = None
|
||||
|
||||
def accept(self):
|
||||
self.value = self.find(QDoubleSpinBox, "doubleSpinBox").value()
|
||||
self.option = self.find(QCheckBox, "checkBox").isChecked()
|
||||
super().accept()
|
||||
|
||||
def reject(self):
|
||||
|
||||
@@ -289,10 +289,10 @@ class InitialConditionTableModel(PamhyrTableModel):
|
||||
self._undo.redo()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def generate(self, generator, param, option):
|
||||
def generate(self, generator, param):
|
||||
self._undo.push(
|
||||
GenerateCommand(
|
||||
self._lst, generator, param, option
|
||||
self._lst, generator, param
|
||||
)
|
||||
)
|
||||
self.layoutChanged.emit()
|
||||
@@ -174,12 +174,11 @@ class DuplicateCommand(QUndoCommand):
|
||||
|
||||
|
||||
class GenerateCommand(QUndoCommand):
|
||||
def __init__(self, ics, generator, param, option):
|
||||
def __init__(self, ics, generator, param):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._ics = ics
|
||||
self._param = param
|
||||
self._option = option
|
||||
self._copy = self._ics.data
|
||||
self._generator = generator
|
||||
|
||||
@@ -188,8 +187,6 @@ class GenerateCommand(QUndoCommand):
|
||||
|
||||
def redo(self):
|
||||
if self._generator == "growing":
|
||||
self._ics.generate_growing_constante_height(self._param,
|
||||
self._option)
|
||||
self._ics.generate_growing_constante_height(self._param)
|
||||
elif self._generator == "discharge":
|
||||
self._ics.generate_discharge(self._param,
|
||||
self._option)
|
||||
self._ics.generate_discharge(self._param)
|
||||
@@ -349,14 +349,12 @@ class InitialConditionsWindow(PamhyrWindow):
|
||||
dlg = HeightDialog(trad=self._trad, parent=self)
|
||||
if dlg.exec():
|
||||
value = dlg.value
|
||||
compute_discharge = dlg.option
|
||||
self._table.generate("growing", value, compute_discharge)
|
||||
self._table.generate("growing", value)
|
||||
self._update()
|
||||
|
||||
def generate_discharge(self):
|
||||
dlg = DischargeDialog(trad=self._trad, parent=self)
|
||||
if dlg.exec():
|
||||
value = dlg.value
|
||||
compute_height = dlg.option
|
||||
self._table.generate("discharge", value, compute_height)
|
||||
self._table.generate("discharge", value)
|
||||
self._update()
|
||||
@@ -73,10 +73,7 @@ class NodeItem(QGraphicsItem):
|
||||
|
||||
def shape(self):
|
||||
path = QPainterPath()
|
||||
if self.graph.graph._reservoir.get_assoc_to_node(self.node) is None:
|
||||
path.addEllipse(-10, -10, 20, 20)
|
||||
else:
|
||||
path.addRect(-10, -10, 20, 20)
|
||||
path.addEllipse(-10, -10, 20, 20)
|
||||
return path
|
||||
|
||||
@timer
|
||||
@@ -98,10 +95,7 @@ class NodeItem(QGraphicsItem):
|
||||
color = Qt.green
|
||||
|
||||
painter.setBrush(QBrush(color))
|
||||
if self.graph.graph._reservoir.get_assoc_to_node(self.node) is None:
|
||||
painter.drawEllipse(-10, -10, 20, 20)
|
||||
else:
|
||||
painter.drawRect(-10, -10, 20, 20)
|
||||
painter.drawEllipse(-10, -10, 20, 20)
|
||||
|
||||
def itemChange(self, change, value):
|
||||
if change == QGraphicsItem.ItemPositionHasChanged:
|
||||
@@ -616,15 +610,11 @@ class GraphWidget(QGraphicsView):
|
||||
|
||||
def add_node_reservoir(self, node):
|
||||
self.parent.add_node_reservoir(node)
|
||||
self.display_update()
|
||||
|
||||
def del_node_reservoir(self, node):
|
||||
self.parent.del_node_reservoir(node)
|
||||
self.changeNode.emit(self.sender())
|
||||
self.display_update()
|
||||
|
||||
def edit_node_reservoir(self, node):
|
||||
self.changeNode.emit(self.sender())
|
||||
self.parent.edit_node_reservoir(node)
|
||||
|
||||
def enable_edge(self, edge, prev):
|
||||
@@ -1009,20 +999,12 @@ class GraphWidget(QGraphicsView):
|
||||
items = self.items(event.pos())
|
||||
|
||||
# Select current menu
|
||||
while len(items) > 0:
|
||||
if type(items[0]) in [NodeItem, EdgeItem]:
|
||||
break
|
||||
else:
|
||||
items = items[1:]
|
||||
|
||||
if len(items) == 0:
|
||||
m_type = DefaultMenu
|
||||
elif type(items[0]) is NodeItem:
|
||||
m_type = NodeMenu
|
||||
elif type(items[0]) is EdgeItem:
|
||||
m_type = EdgeMenu
|
||||
else:
|
||||
m_type = DefaultMenu
|
||||
|
||||
# Create and exec menu
|
||||
m = m_type(
|
||||
@@ -1030,4 +1012,3 @@ class GraphWidget(QGraphicsView):
|
||||
graph=self.graph, trad=self._trad, parent=self
|
||||
)
|
||||
m.run()
|
||||
self.clicked = False
|
||||
@@ -54,12 +54,10 @@ class NetworkTranslate(MainTranslate):
|
||||
self._sub_dict["table_headers_node"] = {
|
||||
"name": self._dict['name'],
|
||||
"type": self._dict['type'],
|
||||
"id": _translate("Network", "Index"),
|
||||
}
|
||||
|
||||
self._sub_dict["table_headers_edge"] = {
|
||||
"name": self._dict['name'],
|
||||
"node1": _translate("Network", "Source node"),
|
||||
"node2": _translate("Network", "Destination node"),
|
||||
"id": _translate("Network", "Index"),
|
||||
}
|
||||
@@ -65,6 +65,7 @@ class PlotXY(PamhyrPlot):
|
||||
self._table = parent.find(QTableView, f"tableView_profile")
|
||||
|
||||
def onpick(self, event):
|
||||
print(event.mouseevent.button.value)
|
||||
if event.mouseevent.inaxes != self.canvas.axes:
|
||||
return
|
||||
if event.mouseevent.button.value != 1:
|
||||
|
||||
@@ -271,9 +271,9 @@ class ResultsWindow(PamhyrWindow):
|
||||
table = self.find(QTableView, f"tableView_reach")
|
||||
indexes = table.selectedIndexes()
|
||||
if len(indexes) == 0:
|
||||
reach = self._study.river.enable_edges()[0]
|
||||
reach = self._study.river.edges()[0]
|
||||
else:
|
||||
reach = self._study.river.enable_edges()[indexes[0].row()]
|
||||
reach = self._study.river.edges()[indexes[0].row()]
|
||||
|
||||
# Profile
|
||||
table = self.find(QTableView, f"tableView_profile")
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
|
||||
import logging
|
||||
|
||||
from tools import timestamp
|
||||
|
||||
from PyQt5.QtCore import (
|
||||
Qt, QRect, QTime, QDateTime, pyqtSlot,
|
||||
)
|
||||
@@ -57,8 +55,8 @@ class PamhyrExTimeDelegate(QItemDelegate):
|
||||
if self._mode == "time":
|
||||
model.setData(index, int(time.total_seconds()))
|
||||
else:
|
||||
logger.debug(str(timestamp(time)))
|
||||
model.setData(index, int(timestamp(time)))
|
||||
logger.debug(str(time.timestamp()))
|
||||
model.setData(index, int(time.timestamp()))
|
||||
editor.close()
|
||||
editor.deleteLater()
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ class UnitTranslate(CommonWordTranslate):
|
||||
super(UnitTranslate, self).__init__()
|
||||
|
||||
self._dict["unit_rk"] = _translate("Unit", "River Kilometric (m)")
|
||||
self._dict["unit_rk_short"] = _translate("Unit", "RK (m)")
|
||||
self._dict["unit_width"] = _translate("Unit", "Width (m)")
|
||||
self._dict["unit_height"] = _translate("Unit", "Height (m)")
|
||||
self._dict["unit_diameter"] = _translate("Unit", "Diameter (m)")
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>284</width>
|
||||
<height>107</height>
|
||||
<height>80</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -17,16 +17,6 @@
|
||||
<locale language="English" country="Europe"/>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="2" column="0">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
@@ -49,12 +39,12 @@
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="checkBox">
|
||||
<property name="text">
|
||||
<string>Generate height</string>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -17,16 +17,6 @@
|
||||
<locale language="English" country="Europe"/>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="2" column="0">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
@@ -39,19 +29,19 @@
|
||||
<item>
|
||||
<widget class="QDoubleSpinBox" name="doubleSpinBox">
|
||||
<property name="maximum">
|
||||
<double>1000000.000000000000000</double>
|
||||
<double>999999.998999999952503</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="checkBox">
|
||||
<property name="text">
|
||||
<string>Generate discharge</string>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>2</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab_liquid">
|
||||
<attribute name="title">
|
||||
|
||||
@@ -145,7 +145,7 @@
|
||||
<item row="0" column="0">
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>2</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab_4">
|
||||
<attribute name="title">
|
||||
|
||||
+1
-1
@@ -237,7 +237,7 @@ def timestamp(dt: datetime):
|
||||
|
||||
def date_iso_to_timestamp(date: str):
|
||||
if type(date) is str:
|
||||
return timestamp(datetime.fromisoformat(date))
|
||||
return datetime.fromisoformat(date).timestamp()
|
||||
else:
|
||||
return datetime.isoformat(date)
|
||||
|
||||
|
||||
Reference in new issue
Block a user