mirror of https://gitlab.com/pamhyr/pamhyr2
refactoring: refactor Results.
parent
ba087f12a5
commit
2ff4f63d23
|
|
@ -671,7 +671,7 @@ method to draw the plot from scratch, the second to update the plot if
|
|||
data has changed.
|
||||
|
||||
#+begin_src python :python python3 :results output :noweb yes
|
||||
from View.Plot.APlot import APlot
|
||||
from View.Tools.PamhyrPlot import PamhyrPlot
|
||||
|
||||
class MyPlot(APlot):
|
||||
def __init__(self, canvas=None, data=None, toolbar=None):
|
||||
|
|
|
|||
|
|
@ -43,6 +43,10 @@ class Results(object):
|
|||
def river(self):
|
||||
return self._river
|
||||
|
||||
@property
|
||||
def study(self):
|
||||
return self._study
|
||||
|
||||
def set(self, key, value):
|
||||
self._meta_data[key] = value
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@ class Profile(object):
|
|||
self._profile = profile # Source profile in the study
|
||||
self._data = {} # Dict of dict {<ts>: {<key>: <value>, ...}, ...}
|
||||
|
||||
def __len__(self):
|
||||
return len(self._data)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._profile.name
|
||||
|
|
@ -66,6 +69,9 @@ class Reach(object):
|
|||
)
|
||||
)
|
||||
|
||||
def __len__(self):
|
||||
return len(self._profiles)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._reach.name
|
||||
|
|
@ -91,6 +97,9 @@ class River(object):
|
|||
# Dict with timestamps as key
|
||||
self._reachs = []
|
||||
|
||||
def __len__(self):
|
||||
return len(self._reachs)
|
||||
|
||||
@property
|
||||
def reachs(self):
|
||||
return self._reachs.copy()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
# Translate.py -- Pamhyr
|
||||
# Copyright (C) 2023 INRAE
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from PyQt5.QtCore import QCoreApplication
|
||||
|
||||
from View.Tools.PamhyrTranslate import PamhyrTranslate
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
class CheckListTranslate(PamhyrTranslate):
|
||||
def __init__(self):
|
||||
super(CheckListTranslate, self).__init__()
|
||||
|
||||
self._sub_dict["table_headers"] = {
|
||||
"name": _translate("CheckList", "Name"),
|
||||
"status": _translate("CheckList", "Status"),
|
||||
}
|
||||
|
|
@ -55,7 +55,7 @@ from View.SedimentLayers.Reach.Window import ReachSedimentLayersWindow
|
|||
from View.SolverParameters.Window import SolverParametersWindow
|
||||
from View.RunSolver.Window import SelectSolverWindow, SolverLogWindow
|
||||
from View.CheckList.Window import CheckListWindow
|
||||
# from View.Results.Window import ResultsWindow
|
||||
from View.Results.Window import ResultsWindow
|
||||
from View.Debug.Window import ReplWindow
|
||||
|
||||
from Model.Study import Study
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from tools import timer
|
||||
from View.Plot.APlot import APlot
|
||||
from View.Tools.PamhyrPlot import PamhyrPlot
|
||||
|
||||
from PyQt5.QtCore import (
|
||||
QCoreApplication
|
||||
|
|
@ -25,14 +25,16 @@ from PyQt5.QtCore import (
|
|||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
class PlotAC(APlot):
|
||||
def __init__(self, canvas=None, results=None,
|
||||
reach_id=0, profile_id=0,
|
||||
toolbar=None):
|
||||
class PlotAC(PamhyrPlot):
|
||||
def __init__(self, canvas=None, trad=None, toolbar=None,
|
||||
results=None, reach_id=0, profile_id=0,
|
||||
parent=None):
|
||||
super(PlotAC, self).__init__(
|
||||
canvas=canvas,
|
||||
data=results,
|
||||
toolbar=toolbar
|
||||
canvas = canvas,
|
||||
trad = trad,
|
||||
data = results,
|
||||
toolbar = toolbar,
|
||||
parent = parent
|
||||
)
|
||||
|
||||
self._current_timestamp = max(results.get("timestamps"))
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ from functools import reduce
|
|||
from datetime import datetime
|
||||
|
||||
from tools import timer, trace
|
||||
from View.Plot.APlot import APlot
|
||||
from View.Tools.PamhyrPlot import PamhyrPlot
|
||||
|
||||
from PyQt5.QtCore import (
|
||||
QCoreApplication
|
||||
|
|
@ -32,14 +32,16 @@ _translate = QCoreApplication.translate
|
|||
|
||||
logger = logging.getLogger()
|
||||
|
||||
class PlotH(APlot):
|
||||
def __init__(self, canvas=None, results=None,
|
||||
reach_id=0, profile_id=0,
|
||||
toolbar=None):
|
||||
class PlotH(PamhyrPlot):
|
||||
def __init__(self, canvas=None, trad=None, toolbar=None,
|
||||
results=None, reach_id=0, profile_id=0,
|
||||
parent=None):
|
||||
super(PlotH, self).__init__(
|
||||
canvas=canvas,
|
||||
data=results,
|
||||
toolbar=toolbar
|
||||
canvas = canvas,
|
||||
trad = trad,
|
||||
data = results,
|
||||
toolbar = toolbar,
|
||||
parent = parent
|
||||
)
|
||||
|
||||
self._mode = "time"
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from tools import timer
|
||||
from View.Plot.APlot import APlot
|
||||
from View.Tools.PamhyrPlot import PamhyrPlot
|
||||
|
||||
from PyQt5.QtCore import (
|
||||
QCoreApplication
|
||||
|
|
@ -25,14 +25,16 @@ from PyQt5.QtCore import (
|
|||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
class PlotKPC(APlot):
|
||||
def __init__(self, canvas=None, results=None,
|
||||
reach_id=0, profile_id=0,
|
||||
toolbar=None):
|
||||
class PlotKPC(PamhyrPlot):
|
||||
def __init__(self, canvas=None, trad=None, toolbar=None,
|
||||
results=None, reach_id=0, profile_id=0,
|
||||
parent=None):
|
||||
super(PlotKPC, self).__init__(
|
||||
canvas=canvas,
|
||||
data=results,
|
||||
toolbar=toolbar
|
||||
canvas = canvas,
|
||||
trad = trad,
|
||||
data = results,
|
||||
toolbar = toolbar,
|
||||
parent = parent
|
||||
)
|
||||
|
||||
self._current_timestamp = max(results.get("timestamps"))
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import logging
|
|||
from functools import reduce
|
||||
|
||||
from tools import timer
|
||||
from View.Plot.APlot import APlot
|
||||
from View.Tools.PamhyrPlot import PamhyrPlot
|
||||
|
||||
from PyQt5.QtCore import (
|
||||
QCoreApplication
|
||||
|
|
@ -15,14 +15,16 @@ _translate = QCoreApplication.translate
|
|||
|
||||
logger = logging.getLogger()
|
||||
|
||||
class PlotSedProfile(APlot):
|
||||
def __init__(self, canvas=None, study=None, results=None,
|
||||
reach_id=0, profile_id=0,
|
||||
toolbar=None):
|
||||
class PlotSedProfile(PamhyrPlot):
|
||||
def __init__(self, canvas=None, trad=None, toolbar=None,
|
||||
results=None, reach_id=0, profile_id=0,
|
||||
parent=None):
|
||||
super(PlotSedProfile, self).__init__(
|
||||
canvas=canvas,
|
||||
data=study,
|
||||
toolbar=toolbar
|
||||
canvas = canvas,
|
||||
trad = trad,
|
||||
data = results,
|
||||
toolbar = toolbar,
|
||||
parent = parent
|
||||
)
|
||||
|
||||
self._results = results
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import logging
|
|||
from functools import reduce
|
||||
|
||||
from tools import timer
|
||||
from View.Plot.APlot import APlot
|
||||
from View.Tools.PamhyrPlot import PamhyrPlot
|
||||
|
||||
from PyQt5.QtCore import (
|
||||
QCoreApplication
|
||||
|
|
@ -15,14 +15,16 @@ _translate = QCoreApplication.translate
|
|||
|
||||
logger = logging.getLogger()
|
||||
|
||||
class PlotSedReach(APlot):
|
||||
def __init__(self, canvas=None, study=None, results=None,
|
||||
reach_id=0, profile_id=0,
|
||||
toolbar=None):
|
||||
class PlotSedReach(PamhyrPlot):
|
||||
def __init__(self, canvas=None, trad=None, toolbar=None,
|
||||
results=None, reach_id=0, profile_id=0,
|
||||
parent=None):
|
||||
super(PlotSedReach, self).__init__(
|
||||
canvas=canvas,
|
||||
data=study,
|
||||
toolbar=toolbar
|
||||
canvas = canvas,
|
||||
trad = trad,
|
||||
data = results,
|
||||
toolbar = toolbar,
|
||||
parent = parent
|
||||
)
|
||||
|
||||
self._results = results
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import logging
|
|||
from functools import reduce
|
||||
|
||||
from tools import timer, trace
|
||||
from View.Plot.APlot import APlot
|
||||
from View.Tools.PamhyrPlot import PamhyrPlot
|
||||
|
||||
from PyQt5.QtCore import (
|
||||
QCoreApplication
|
||||
|
|
@ -31,14 +31,16 @@ _translate = QCoreApplication.translate
|
|||
|
||||
logger = logging.getLogger()
|
||||
|
||||
class PlotXY(APlot):
|
||||
def __init__(self, canvas=None, results=None,
|
||||
reach_id=0, profile_id=0,
|
||||
toolbar=None, display_current=True):
|
||||
class PlotXY(PamhyrPlot):
|
||||
def __init__(self, canvas=None, trad=None, toolbar=None,
|
||||
results=None, reach_id=0, profile_id=0,
|
||||
display_current=True, parent=None):
|
||||
super(PlotXY, self).__init__(
|
||||
canvas=canvas,
|
||||
data=results,
|
||||
toolbar=toolbar
|
||||
canvas = canvas,
|
||||
trad = trad,
|
||||
data = results,
|
||||
toolbar = toolbar,
|
||||
parent = parent
|
||||
)
|
||||
|
||||
self.display_current = display_current
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ from PyQt5.QtWidgets import (
|
|||
QComboBox,
|
||||
)
|
||||
|
||||
from View.Tools.PamhyrTable import PamhyrTableModel
|
||||
from View.Results.translate import *
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
|
@ -41,33 +42,16 @@ logger = logging.getLogger()
|
|||
_translate = QCoreApplication.translate
|
||||
|
||||
|
||||
class TableModel(QAbstractTableModel):
|
||||
def __init__(self, results = None, study = None, mode = None, undo=None):
|
||||
super(QAbstractTableModel, self).__init__()
|
||||
class TableModel(PamhyrTableModel):
|
||||
def _setup_lst(self):
|
||||
_river = self._data.river
|
||||
if self._opt_data == "reach":
|
||||
self._lst = _river.reachs
|
||||
else:
|
||||
self._lst = _river.reach(0).profiles
|
||||
|
||||
self._results = results
|
||||
self._study = study
|
||||
self._mode = mode
|
||||
self._undo_stack = undo
|
||||
|
||||
self._table_headers = table_headers_reach
|
||||
if mode != "reach":
|
||||
self._table_headers = table_headers_profile
|
||||
|
||||
self._headers = list(self._table_headers.keys())
|
||||
|
||||
self._selected = 0
|
||||
self._timestamp = 0
|
||||
|
||||
def rowCount(self, parent=QModelIndex()):
|
||||
if self._mode == "reach":
|
||||
return len(self._results.river.reachs)
|
||||
|
||||
current_reach = self._results.river.reach(self._selected)
|
||||
return len(current_reach.profiles)
|
||||
|
||||
def columnCount(self, parent=QModelIndex()):
|
||||
return len(self._headers)
|
||||
def __init__(self, **kwargs):
|
||||
super(TableModel, self).__init__(**kwargs)
|
||||
|
||||
def data(self, index, role=Qt.DisplayRole):
|
||||
if role != Qt.ItemDataRole.DisplayRole:
|
||||
|
|
@ -76,32 +60,23 @@ class TableModel(QAbstractTableModel):
|
|||
row = index.row()
|
||||
column = index.column()
|
||||
|
||||
if self._mode == "reach":
|
||||
if self._opt_data == "reach":
|
||||
if self._headers[column] == "name":
|
||||
v = self._results.river.reach(row).name
|
||||
v = self._lst[row].name
|
||||
return str(v)
|
||||
else:
|
||||
current_reach = self._results.river.reach(self._selected)
|
||||
if self._headers[column] == "name":
|
||||
v = current_reach.profile(row).name
|
||||
v = self._lst[row].name
|
||||
return str(v)
|
||||
elif self._headers[column] == "kp":
|
||||
v = current_reach.profile(row).kp
|
||||
v = self._lst[row].kp
|
||||
return f"{v:.4f}"
|
||||
|
||||
return QVariant()
|
||||
|
||||
def headerData(self, section, orientation, role=Qt.DisplayRole):
|
||||
if role == Qt.ItemDataRole.DisplayRole and orientation == Qt.Orientation.Horizontal:
|
||||
return self._table_headers[self._headers[section]]
|
||||
|
||||
return QVariant()
|
||||
|
||||
def index(self, row, column, parent=QModelIndex()):
|
||||
if not self.hasIndex(row, column, parent):
|
||||
return QModelIndex()
|
||||
|
||||
return self.createIndex(row, column, QModelIndex())
|
||||
|
||||
def flags(self, index):
|
||||
return Qt.ItemIsEnabled | Qt.ItemIsSelectable
|
||||
def update(self, reach):
|
||||
_river = self._data.river
|
||||
if self._opt_data == "reach":
|
||||
self._lst = _river.reachs
|
||||
else:
|
||||
self._lst = _river.reach(reach).profiles
|
||||
|
|
|
|||
|
|
@ -41,8 +41,8 @@ from PyQt5.QtWidgets import (
|
|||
QSlider, QLabel,
|
||||
)
|
||||
|
||||
from View.Plot.MplCanvas import MplCanvas
|
||||
from View.Plot.PamhyrToolbar import PamhyrPlotToolbar
|
||||
from View.Tools.Plot.PamhyrCanvas import MplCanvas
|
||||
from View.Tools.Plot.PamhyrToolbar import PamhyrPlotToolbar
|
||||
|
||||
from View.Results.PlotXY import PlotXY
|
||||
from View.Results.PlotAC import PlotAC
|
||||
|
|
@ -52,10 +52,7 @@ from View.Results.PlotSedReach import PlotSedReach
|
|||
from View.Results.PlotSedProfile import PlotSedProfile
|
||||
|
||||
from View.Results.Table import TableModel
|
||||
from View.Results.translate import (
|
||||
table_headers_reach, table_headers_profile,
|
||||
retranslate,
|
||||
)
|
||||
from View.Results.translate import ResultsTranslate
|
||||
from View.Stricklers.Window import StricklersWindow
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
|
@ -85,42 +82,27 @@ class ResultsWindow(PamhyrWindow):
|
|||
title = name,
|
||||
study = study,
|
||||
config = config,
|
||||
trad = ResultsTranslate(),
|
||||
parent=parent
|
||||
)
|
||||
|
||||
self.setup_table()
|
||||
self.setup_graph()
|
||||
self.setup_plot()
|
||||
self.setup_slider()
|
||||
self.setup_statusbar()
|
||||
self.setup_connections()
|
||||
|
||||
self.ui.setWindowTitle(self._title)
|
||||
|
||||
def setup_title(self, title):
|
||||
self._title = (
|
||||
title + " - "
|
||||
+ self._study.name + " - "
|
||||
+ self._solver.name + " - "
|
||||
+ self._results.date
|
||||
)
|
||||
|
||||
def setup_table(self):
|
||||
retranslate()
|
||||
self._table = {}
|
||||
|
||||
for t in ["reach", "profile"]:
|
||||
table = self.find(QTableView, f"tableView_{t}")
|
||||
self._table[t] = TableModel(
|
||||
results = self._results,
|
||||
study = self._study,
|
||||
mode = t,
|
||||
table_view = table,
|
||||
table_headers = self._trad.get_dict(f"table_headers_{t}"),
|
||||
data = self._results,
|
||||
undo = self._undo_stack,
|
||||
opt_data = t
|
||||
)
|
||||
table.setModel(self._table[t])
|
||||
|
||||
table.setSelectionBehavior(QAbstractItemView.SelectRows)
|
||||
table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
||||
table.setAlternatingRowColors(True)
|
||||
|
||||
def setup_slider(self):
|
||||
self._slider_profile = self.find(QSlider, f"verticalSlider_profile")
|
||||
|
|
@ -132,7 +114,7 @@ class ResultsWindow(PamhyrWindow):
|
|||
self._slider_time.setMaximum(len(self._timestamps) - 1)
|
||||
self._slider_time.setValue(len(self._timestamps) - 1)
|
||||
|
||||
def setup_graph(self):
|
||||
def setup_plot(self):
|
||||
self.canvas = MplCanvas(width=5, height=4, dpi=100)
|
||||
self.canvas.setObjectName("canvas")
|
||||
self.toolbar = PamhyrPlotToolbar(
|
||||
|
|
@ -219,7 +201,6 @@ class ResultsWindow(PamhyrWindow):
|
|||
self.plot_sed_reach = PlotSedReach(
|
||||
canvas = self.canvas_5,
|
||||
results = self._results,
|
||||
study = self._study,
|
||||
reach_id = 0,
|
||||
profile_id = 0,
|
||||
toolbar = self.toolbar_5
|
||||
|
|
@ -239,7 +220,6 @@ class ResultsWindow(PamhyrWindow):
|
|||
self.plot_sed_profile = PlotSedProfile(
|
||||
canvas = self.canvas_6,
|
||||
results = self._results,
|
||||
study = self._study,
|
||||
reach_id = 0,
|
||||
profile_id = 0,
|
||||
toolbar = self.toolbar_6
|
||||
|
|
|
|||
|
|
@ -18,19 +18,19 @@
|
|||
|
||||
from PyQt5.QtCore import QCoreApplication
|
||||
|
||||
from View.Tools.PamhyrTranslate import PamhyrTranslate
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
table_headers_reach = {
|
||||
"name": _translate("Results", "Reach name"),
|
||||
}
|
||||
class ResultsTranslate(PamhyrTranslate):
|
||||
def __init__(self):
|
||||
super(ResultsTranslate, self).__init__()
|
||||
|
||||
table_headers_profile = {
|
||||
"name": _translate("Results", "Name"),
|
||||
"kp": _translate("Results", "KP (m)"),
|
||||
}
|
||||
self._sub_dict["table_headers_reach"] = {
|
||||
"name": _translate("Results", "Reach name"),
|
||||
}
|
||||
|
||||
def retranslate():
|
||||
table_headers_reach["name"] = _translate("Results", "Reach name")
|
||||
|
||||
table_headers_profile["name"] = _translate("Results", "Name")
|
||||
table_headers_profile["kp"] = _translate("Results", "KP (m)")
|
||||
self._sub_dict["table_headers_profile"] = {
|
||||
"name": _translate("Results", "Name"),
|
||||
"kp": _translate("Results", "KP (m)"),
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue