put compare solvers in results window

compare_results
Theophile Terraz 2025-01-10 16:54:02 +01:00
parent 8d9a196059
commit 41d1fb9d59
11 changed files with 224 additions and 99 deletions

View File

@ -81,7 +81,7 @@ from View.RunSolver.Window import (
SolverLogWindow, SolverLogWindow,
CompareSolversWindow CompareSolversWindow
) )
from View.Results.Window import ResultsWindow, CompareResultsWindow from View.Results.Window import ResultsWindow # , CompareResultsWindow
from View.RunSolver.WindowAdisTS import ( from View.RunSolver.WindowAdisTS import (
SelectSolverWindowAdisTS, SelectSolverWindowAdisTS,
SolverLogWindowAdisTS SolverLogWindowAdisTS
@ -1437,7 +1437,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
data=[ data=[
self._study, self._study,
None, # No config None, # No config
solver,
results results
] ]
): ):
@ -1445,8 +1444,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
res = ResultsWindow( res = ResultsWindow(
study=self._study, study=self._study,
solver=solver, results=[results],
results=results,
parent=self parent=self
) )
res.show() res.show()
@ -1586,20 +1584,34 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
data=[ data=[
self._study, self._study,
None, # No config None, # No config
results._solver, results[0]
results
] ]
): ):
w = self.get_sub_window(
ResultsWindow,
data=[
self._study,
None, # No config
results[0]
])
#w.add_result(result[1], run.solver2)
return return
res = CompareResultsWindow( res = ResultsWindow(
study=self._study, study=self._study,
solver=results._solver,
results=results, results=results,
parent=self parent=self
) )
res.show() res.show()
#res = CompareResultsWindow(
#study=self._study,
#solver=results._solver,
#results=results,
#parent=self
#)
#res.show()
def diff_results(self, solver1, solver2): def diff_results(self, solver1, solver2):
if solver1 is None: if solver1 is None:
@ -1637,6 +1649,8 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
# TODO message # TODO message
return None return None
return [result1, result2]
result3 = Results(self._study, solver3) result3 = Results(self._study, solver3)
result3.set("nb_reach", result1.get("nb_reach")) result3.set("nb_reach", result1.get("nb_reach"))
result3.set("nb_profile", result1.get("nb_profile")) result3.set("nb_profile", result1.get("nb_profile"))

View File

@ -49,7 +49,7 @@ unit = {
class CustomPlot(PamhyrPlot): class CustomPlot(PamhyrPlot):
def __init__(self, x, y, envelop, reach, profile, timestamp, def __init__(self, x, y, envelop, reach, profile, timestamp,
data=None, canvas=None, trad=None, data=None, canvas=None, trad=None, res_id=0,
toolbar=None, parent=None): toolbar=None, parent=None):
super(CustomPlot, self).__init__( super(CustomPlot, self).__init__(
canvas=canvas, canvas=canvas,
@ -65,6 +65,7 @@ class CustomPlot(PamhyrPlot):
self._reach = reach self._reach = reach
self._profile = profile self._profile = profile
self._timestamp = timestamp self._timestamp = timestamp
self._current_res_id = res_id
logger.debug( logger.debug(
"Create custom plot for: " + "Create custom plot for: " +
@ -130,7 +131,7 @@ class CustomPlot(PamhyrPlot):
""" """
Get SL list for profile p at initial time (initial data) Get SL list for profile p at initial time (initial data)
""" """
t0 = min(list(self.data.get("timestamps"))) t0 = min(list(self.data[self._current_res_id].get("timestamps")))
return map( return map(
lambda p: p.get_ts_key(t0, "sl")[0], lambda p: p.get_ts_key(t0, "sl")[0],
reach.profiles reach.profiles
@ -146,7 +147,7 @@ class CustomPlot(PamhyrPlot):
) )
def get_ts_zmin(self, profile): def get_ts_zmin(self, profile):
results = self.data results = self.data[self._current_res_id]
nt = len(list(results.get("timestamps"))) nt = len(list(results.get("timestamps")))
reach = results.river.reach(self._reach) reach = results.river.reach(self._reach)
berdrock = self.sl_compute_bedrock(reach) berdrock = self.sl_compute_bedrock(reach)
@ -167,7 +168,7 @@ class CustomPlot(PamhyrPlot):
return ts_z_min return ts_z_min
def _draw_rk(self): def _draw_rk(self):
results = self.data results = self.data[self._current_res_id]
reach = results.river.reach(self._reach) reach = results.river.reach(self._reach)
rk = reach.geometry.get_rk() rk = reach.geometry.get_rk()
if reach.has_sediment(): if reach.has_sediment():
@ -485,7 +486,7 @@ class CustomPlot(PamhyrPlot):
self.canvas.axes.legend(lns, labs, loc="best") self.canvas.axes.legend(lns, labs, loc="best")
def _redraw_rk(self): def _redraw_rk(self):
results = self.data results = self.data[self._current_res_id]
reach = results.river.reach(self._reach) reach = results.river.reach(self._reach)
rk = reach.geometry.get_rk() rk = reach.geometry.get_rk()
z_min = reach.geometry.get_z_min() z_min = reach.geometry.get_z_min()
@ -623,7 +624,7 @@ class CustomPlot(PamhyrPlot):
self.canvas.axes.set_xticks(ticks=fx, labels=xt, rotation=45) self.canvas.axes.set_xticks(ticks=fx, labels=xt, rotation=45)
def _draw_time(self): def _draw_time(self):
results = self.data results = self.data[self._current_res_id]
reach = results.river.reach(self._reach) reach = results.river.reach(self._reach)
profile = reach.profile(self._profile) profile = reach.profile(self._profile)
@ -774,7 +775,7 @@ class CustomPlot(PamhyrPlot):
def _redraw_time(self): def _redraw_time(self):
results = self.data results = self.data[self._current_res_id]
reach = results.river.reach(self._reach) reach = results.river.reach(self._reach)
profile = reach.profile(self._profile) profile = reach.profile(self._profile)
ts = list(results.get("timestamps")) ts = list(results.get("timestamps"))
@ -895,7 +896,7 @@ class CustomPlot(PamhyrPlot):
elif self._x == "time": elif self._x == "time":
self._draw_time() self._draw_time()
if self._x == "rk": if self._x == "rk":
reach = self.data.river.reach(self._reach) reach = self.data[self._current_res_id].river.reach(self._reach)
profile = reach.profile(self._profile) profile = reach.profile(self._profile)
x = profile.rk x = profile.rk
elif self._x == "time": elif self._x == "time":
@ -935,6 +936,10 @@ class CustomPlot(PamhyrPlot):
else: else:
self.draw_current() self.draw_current()
def set_result(self, res_id):
self._current_res_id = res_id
self.draw()
def set_timestamp(self, timestamp): def set_timestamp(self, timestamp):
self._timestamp = timestamp self._timestamp = timestamp
@ -945,7 +950,7 @@ class CustomPlot(PamhyrPlot):
def draw_current(self): def draw_current(self):
if self._x == "rk": if self._x == "rk":
reach = self.data.river.reach(self._reach) reach = self.data[self._current_res_id].river.reach(self._reach)
profile = reach.profile(self._profile) profile = reach.profile(self._profile)
x = profile.rk x = profile.rk
elif self._x == "time": elif self._x == "time":

View File

@ -29,7 +29,7 @@ _translate = QCoreApplication.translate
class PlotAC(PamhyrPlot): class PlotAC(PamhyrPlot):
def __init__(self, canvas=None, trad=None, toolbar=None, def __init__(self, canvas=None, trad=None, toolbar=None,
results=None, reach_id=0, profile_id=0, results=None, reach_id=0, profile_id=0, res_id=0,
parent=None): parent=None):
super(PlotAC, self).__init__( super(PlotAC, self).__init__(
canvas=canvas, canvas=canvas,
@ -39,9 +39,10 @@ class PlotAC(PamhyrPlot):
parent=parent parent=parent
) )
self._current_timestamp = max(results.get("timestamps")) self._current_timestamp = max(results[res_id].get("timestamps"))
self._current_reach_id = reach_id self._current_reach_id = reach_id
self._current_profile_id = profile_id self._current_profile_id = profile_id
self._current_res_id = res_id
self.label_x = self._trad['x'] self.label_x = self._trad['x']
self.label_y = self._trad["unit_elevation"] self.label_y = self._trad["unit_elevation"]
@ -62,7 +63,7 @@ class PlotAC(PamhyrPlot):
@results.setter @results.setter
def results(self, results): def results(self, results):
self.data = results self.data = results
self._current_timestamp = max(results.get("timestamps")) self._current_timestamp = max(results[self._current_res_id].get("timestamps"))
@timer @timer
def draw(self, highlight=None): def draw(self, highlight=None):
@ -71,7 +72,11 @@ class PlotAC(PamhyrPlot):
if self.results is None: if self.results is None:
return return
reach = self.results.river.reach(self._current_reach_id) if self.results[self._current_res_id] is None:
return
results = self.results[self._current_res_id]
reach = results.river.reach(self._current_reach_id)
profile = reach.profile(self._current_profile_id) profile = reach.profile(self._current_profile_id)
self.draw_profile(reach, profile) self.draw_profile(reach, profile)
@ -137,10 +142,14 @@ class PlotAC(PamhyrPlot):
self._current_profile_id = profile_id self._current_profile_id = profile_id
self.update() self.update()
def set_result(self, res_id):
self._current_result_id = res_id
self.update()
def set_timestamp(self, timestamp): def set_timestamp(self, timestamp):
self._current_timestamp = timestamp self._current_timestamp = timestamp
reach = self.results.river.reach(self._current_reach_id) reach = self.results[self._current_res_id].river.reach(self._current_reach_id)
profile = reach.profile(self._current_profile_id) profile = reach.profile(self._current_profile_id)
x = profile.geometry.get_station() x = profile.geometry.get_station()
z = profile.geometry.z() z = profile.geometry.z()
@ -152,7 +161,7 @@ class PlotAC(PamhyrPlot):
if not self._init: if not self._init:
self.draw() self.draw()
reach = self.results.river.reach(self._current_reach_id) reach = self.results[self._current_res_id].river.reach(self._current_reach_id)
profile = reach.profile(self._current_profile_id) profile = reach.profile(self._current_profile_id)
x = profile.geometry.get_station() x = profile.geometry.get_station()
z = profile.geometry.z() z = profile.geometry.z()

View File

@ -35,7 +35,7 @@ logger = logging.getLogger()
class PlotH(PamhyrPlot): class PlotH(PamhyrPlot):
def __init__(self, canvas=None, trad=None, toolbar=None, def __init__(self, canvas=None, trad=None, toolbar=None,
results=None, reach_id=0, profile_id=0, results=None, reach_id=0, profile_id=0, res_id=0,
parent=None): parent=None):
super(PlotH, self).__init__( super(PlotH, self).__init__(
canvas=canvas, canvas=canvas,
@ -47,9 +47,10 @@ class PlotH(PamhyrPlot):
self._mode = "time" self._mode = "time"
self._current_timestamp = max(results.get("timestamps")) self._current_timestamp = max(results[res_id].get("timestamps"))
self._current_reach_id = reach_id self._current_reach_id = reach_id
self._current_profile_id = profile_id self._current_profile_id = profile_id
self._current_res_id = res_id
self.label_x = self._trad["unit_time_s"] self.label_x = self._trad["unit_time_s"]
self.label_y = self._trad["unit_discharge"] self.label_y = self._trad["unit_discharge"]
@ -70,7 +71,7 @@ class PlotH(PamhyrPlot):
@results.setter @results.setter
def results(self, results): def results(self, results):
self.data = results self.data = results
self._current_timestamp = max(results.get("timestamps")) self._current_timestamp = max(results[self._current_res_id].get("timestamps"))
@timer @timer
def draw(self, highlight=None): def draw(self, highlight=None):
@ -79,7 +80,11 @@ class PlotH(PamhyrPlot):
if self.results is None: if self.results is None:
return return
reach = self.results.river.reach(self._current_reach_id) if self.results[self._current_res_id] is None:
return
results = self.results[self._current_res_id]
reach = results.river.reach(self._current_reach_id)
profile = reach.profile(self._current_profile_id) profile = reach.profile(self._current_profile_id)
if reach.geometry.number_profiles == 0: if reach.geometry.number_profiles == 0:
@ -99,7 +104,7 @@ class PlotH(PamhyrPlot):
self._init = True self._init = True
def draw_data(self, reach, profile): def draw_data(self, reach, profile):
self.ts = list(self.results.get("timestamps")) self.ts = list(self.results[self._current_res_id].get("timestamps"))
self.ts.sort() self.ts.sort()
x = self.ts x = self.ts
@ -123,7 +128,7 @@ class PlotH(PamhyrPlot):
) )
def draw_max(self, reach): def draw_max(self, reach):
self.ts = list(self.results.get("timestamps")) self.ts = list(self.results[self._current_res_id].get("timestamps"))
self.ts.sort() self.ts.sort()
x = self.ts x = self.ts
@ -152,6 +157,10 @@ class PlotH(PamhyrPlot):
self._current_profile_id = profile_id self._current_profile_id = profile_id
self.update() self.update()
def set_result(self, res_id):
self._current_result_id = res_id
self.update()
def set_timestamp(self, timestamp): def set_timestamp(self, timestamp):
self._current_timestamp = timestamp self._current_timestamp = timestamp
self.update_current() self.update_current()
@ -165,7 +174,8 @@ class PlotH(PamhyrPlot):
self.update_idle() self.update_idle()
def update_data(self): def update_data(self):
reach = self.results.river.reach(self._current_reach_id) results = self.results[self._current_res_id]
reach = results.river.reach(self._current_reach_id)
profile = reach.profile(self._current_profile_id) profile = reach.profile(self._current_profile_id)
x = self.ts x = self.ts

View File

@ -32,7 +32,7 @@ logger = logging.getLogger()
class PlotRKC(PamhyrPlot): class PlotRKC(PamhyrPlot):
def __init__(self, canvas=None, trad=None, toolbar=None, def __init__(self, canvas=None, trad=None, toolbar=None,
results=None, reach_id=0, profile_id=0, results=None, reach_id=0, profile_id=0, res_id=0,
parent=None): parent=None):
super(PlotRKC, self).__init__( super(PlotRKC, self).__init__(
canvas=canvas, canvas=canvas,
@ -42,10 +42,12 @@ class PlotRKC(PamhyrPlot):
parent=parent parent=parent
) )
self._timestamps = results.get("timestamps") self._timestamps = results[res_id].get("timestamps")
self._current_timestamp = max(results[res_id].get("timestamps"))
self._current_timestamp = max(self._timestamps) self._current_timestamp = max(self._timestamps)
self._current_reach_id = reach_id self._current_reach_id = reach_id
self._current_profile_id = profile_id self._current_profile_id = profile_id
self._current_res_id = res_id
self.label_x = self._trad["unit_rk"] self.label_x = self._trad["unit_rk"]
self.label_y = self._trad["unit_elevation"] self.label_y = self._trad["unit_elevation"]
@ -63,7 +65,7 @@ class PlotRKC(PamhyrPlot):
@results.setter @results.setter
def results(self, results): def results(self, results):
self.data = results self.data = results
self._current_timestamp = max(results.get("timestamps")) self._current_timestamp = max(results[self._current_res_id].get("timestamps"))
@timer @timer
def draw(self, highlight=None): def draw(self, highlight=None):
@ -72,7 +74,11 @@ class PlotRKC(PamhyrPlot):
if self.results is None: if self.results is None:
return return
reach = self.results.river.reach(self._current_reach_id) if self.results[self._current_res_id] is None:
return
results = self.results[self._current_res_id]
reach = results.river.reach(self._current_reach_id)
self.draw_bottom(reach) self.draw_bottom(reach)
self.draw_water_elevation(reach) self.draw_water_elevation(reach)
@ -111,7 +117,7 @@ class PlotRKC(PamhyrPlot):
lambda hs: hs._input_reach.reach is reach.geometry, lambda hs: hs._input_reach.reach is reach.geometry,
filter( filter(
lambda hs: hs._input_reach is not None, lambda hs: hs._input_reach is not None,
self.results.study.river.hydraulic_structures.lst self.results[self._current_res_id].study.river.hydraulic_structures.lst
) )
) )
@ -312,6 +318,10 @@ class PlotRKC(PamhyrPlot):
self._current_profile_id = profile_id self._current_profile_id = profile_id
self.update_current() self.update_current()
def set_result(self, res_id):
self._current_result_id = res_id
self.update()
def set_timestamp(self, timestamp): def set_timestamp(self, timestamp):
self._current_timestamp = timestamp self._current_timestamp = timestamp
self.update() self.update()
@ -320,7 +330,8 @@ class PlotRKC(PamhyrPlot):
if not self._init: if not self._init:
self.draw() self.draw()
reach = self.results.river.reach(self._current_reach_id) results = self.results[self._current_res_id]
reach = results.river.reach(self._current_reach_id)
if reach.has_sediment(): if reach.has_sediment():
self.update_bottom_with_bedload() self.update_bottom_with_bedload()
@ -329,7 +340,8 @@ class PlotRKC(PamhyrPlot):
self.update_idle() self.update_idle()
def update_water_elevation(self): def update_water_elevation(self):
reach = self.results.river.reach(self._current_reach_id) results = self.results[self._current_res_id]
reach = results.river.reach(self._current_reach_id)
rk = reach.geometry.get_rk() rk = reach.geometry.get_rk()
z_min = reach.geometry.get_z_min() z_min = reach.geometry.get_z_min()
@ -354,7 +366,8 @@ class PlotRKC(PamhyrPlot):
) )
def update_current(self): def update_current(self):
reach = self.results.river.reach(self._current_reach_id) results = self.results[self._current_res_id]
reach = results.river.reach(self._current_reach_id)
rk = reach.geometry.get_rk() rk = reach.geometry.get_rk()
z_min = reach.geometry.get_z_min() z_min = reach.geometry.get_z_min()
z_max = reach.geometry.get_z_max() z_max = reach.geometry.get_z_max()
@ -367,7 +380,8 @@ class PlotRKC(PamhyrPlot):
self.canvas.figure.canvas.draw_idle() self.canvas.figure.canvas.draw_idle()
def update_bottom_with_bedload(self): def update_bottom_with_bedload(self):
reach = self.results.river.reach(self._current_reach_id) results = self.results[self._current_res_id]
reach = results.river.reach(self._current_reach_id)
rk = reach.geometry.get_rk() rk = reach.geometry.get_rk()
z = self.sl_compute_current_z(reach) z = self.sl_compute_current_z(reach)

View File

@ -38,7 +38,7 @@ logger = logging.getLogger()
class PlotXY(PamhyrPlot): class PlotXY(PamhyrPlot):
def __init__(self, canvas=None, trad=None, toolbar=None, def __init__(self, canvas=None, trad=None, toolbar=None,
results=None, reach_id=0, profile_id=0, results=None, reach_id=0, profile_id=0, res_id=0,
display_current=True, parent=None): display_current=True, parent=None):
super(PlotXY, self).__init__( super(PlotXY, self).__init__(
canvas=canvas, canvas=canvas,
@ -52,10 +52,11 @@ class PlotXY(PamhyrPlot):
self.line_gl = [] self.line_gl = []
self.overflow = [] self.overflow = []
self._timestamps = results.get("timestamps") self._timestamps = results[res_id].get("timestamps")
self._current_timestamp = max(self._timestamps) self._current_timestamp = max(self._timestamps)
self._current_reach_id = reach_id self._current_reach_id = reach_id
self._current_profile_id = profile_id self._current_profile_id = profile_id
self._current_res_id = res_id
self.label_x = _translate("Results", "X (m)") self.label_x = _translate("Results", "X (m)")
self.label_y = _translate("Results", "Y (m)") self.label_y = _translate("Results", "Y (m)")
@ -136,7 +137,7 @@ class PlotXY(PamhyrPlot):
@results.setter @results.setter
def results(self, results): def results(self, results):
self.data = results self.data = results
self._current_timestamp = max(results.get("timestamps")) self._current_timestamp = max(results[self._current_res_id].get("timestamps"))
@timer @timer
def draw(self, highlight=None): def draw(self, highlight=None):
@ -145,8 +146,12 @@ class PlotXY(PamhyrPlot):
if self.results is None: if self.results is None:
return return
reach = self.results.river.reach(self._current_reach_id) if self.results[self._current_res_id] is None:
reaches = self.results.river.reachs return
results = self.results[self._current_res_id]
reach = results.river.reach(self._current_reach_id)
reaches = results.river.reachs
self.draw_profiles(reach, reaches) self.draw_profiles(reach, reaches)
self.draw_water_elevation(reach) self.draw_water_elevation(reach)
@ -272,7 +277,8 @@ class PlotXY(PamhyrPlot):
) )
def draw_water_elevation(self, reach): def draw_water_elevation(self, reach):
reach = self.results.river.reach(self._current_reach_id) results = self.results[self._current_res_id]
reach = results.river.reach(self._current_reach_id)
poly_l_x, poly_l_y, poly_r_x, poly_r_y = [], [], [], [] poly_l_x, poly_l_y, poly_r_x, poly_r_y = [], [], [], []
for profile in reach.profiles: for profile in reach.profiles:
@ -308,6 +314,11 @@ class PlotXY(PamhyrPlot):
self.update_profile() self.update_profile()
self.update_idle() self.update_idle()
def set_result(self, res_id):
self._current_result_id = res_id
self.update_profile()
self.update_idle()
def set_timestamp(self, timestamp): def set_timestamp(self, timestamp):
self._current_timestamp = timestamp self._current_timestamp = timestamp
self.update() self.update()
@ -322,7 +333,8 @@ class PlotXY(PamhyrPlot):
self.update_idle() self.update_idle()
def update_profile(self): def update_profile(self):
reach = self.results.river.reach(self._current_reach_id) results = self.results[self._current_res_id]
reach = results.river.reach(self._current_reach_id)
profile = reach.profile(self._current_profile_id) profile = reach.profile(self._current_profile_id)
self.plot_selected.set_data( self.plot_selected.set_data(
@ -331,7 +343,8 @@ class PlotXY(PamhyrPlot):
) )
def update_water_elevation(self): def update_water_elevation(self):
reach = self.results.river.reach(self._current_reach_id) results = self.results[self._current_res_id]
reach = results.river.reach(self._current_reach_id)
poly_l_x, poly_l_y, poly_r_x, poly_r_y = [], [], [], [] poly_l_x, poly_l_y, poly_r_x, poly_r_y = [], [], [], []
for profile in reach.profiles: for profile in reach.profiles:
@ -358,7 +371,8 @@ class PlotXY(PamhyrPlot):
self.water_fill[0].set_xy(poly) self.water_fill[0].set_xy(poly)
def update_water_elevation_overflow(self): def update_water_elevation_overflow(self):
reach = self.results.river.reach(self._current_reach_id) results = self.results[self._current_res_id]
reach = results.river.reach(self._current_reach_id)
profile = reach.profile(self._current_profile_id) profile = reach.profile(self._current_profile_id)
overflow = [] overflow = []

View File

@ -46,17 +46,15 @@ _translate = QCoreApplication.translate
class TableModel(PamhyrTableModel): class TableModel(PamhyrTableModel):
def _setup_lst(self): def _setup_lst(self):
_river = self._data.river _river = self._data[0].river
print("data: ", self._data)
print("river: ", _river)
print("reaches: ", _river.reachs)
if self._opt_data == "reach": if self._opt_data == "reach":
self._lst = _river.reachs self._lst = _river.reachs
print("optreach: ", self._lst)
elif self._opt_data == "profile": elif self._opt_data == "profile":
self._lst = _river.reach(0).profiles self._lst = _river.reach(0).profiles
elif self._opt_data == "raw_data": elif self._opt_data == "raw_data":
self._lst = _river.reach(0).profiles self._lst = _river.reach(0).profiles
elif self._opt_data == "solver":
self._lst = self._parent._solvers
def __init__(self, **kwargs): def __init__(self, **kwargs):
self._timestamp = 0.0 self._timestamp = 0.0
@ -80,6 +78,10 @@ class TableModel(PamhyrTableModel):
elif self._headers[column] == "rk": elif self._headers[column] == "rk":
v = self._lst[row].rk v = self._lst[row].rk
return f"{v:.4f}" return f"{v:.4f}"
elif self._opt_data == "solver":
if self._headers[column] == "solver":
v = self._lst[row].name
return str(v)
elif self._opt_data == "raw_data": elif self._opt_data == "raw_data":
p = self._lst[row] p = self._lst[row]
if self._headers[column] == "name": if self._headers[column] == "name":
@ -139,12 +141,14 @@ class TableModel(PamhyrTableModel):
return QVariant() return QVariant()
def update(self, reach): def update(self, reach):
_river = self._data.river _river = self._data[0].river
if self._opt_data == "reach": if self._opt_data == "reach":
self._lst = _river.reachs self._lst = _river.reachs
elif self._opt_data == "profile" or self._opt_data == "raw_data": elif self._opt_data == "profile" or self._opt_data == "raw_data":
self._lst = _river.reach(reach).profiles self._lst = _river.reach(reach).profiles
elif self._opt_data == "solver":
self._lst = self._parent._solvers
self.layoutChanged.emit() self.layoutChanged.emit()

View File

@ -85,17 +85,18 @@ class ResultsWindow(PamhyrWindow):
) )
def __init__(self, study=None, config=None, def __init__(self, study=None, config=None,
solver=None, results=None, results=None, parent=None, trad=None):
parent=None, trad=None): self._solvers = [r._solver for r in results]
self._solver = solver
self._results = results self._results = results
self._current_results = 0
print("solver: " + results[0]._solver.name)
if trad is None: if trad is None:
trad = ResultsTranslate() trad = ResultsTranslate()
name = ( name = (
trad[self._pamhyr_name] + " - " trad[self._pamhyr_name] + " - "
+ study.name + " - " + study.name + " - "
+ self._solver.name + self._solvers[self._current_results].name
) )
super(ResultsWindow, self).__init__( super(ResultsWindow, self).__init__(
@ -106,13 +107,12 @@ class ResultsWindow(PamhyrWindow):
parent=parent parent=parent
) )
self._hash_data.append(self._solver)
self._hash_data.append(self._results) self._hash_data.append(self._results)
self._additional_plot = {} self._additional_plot = {}
try: try:
self._timestamps = sorted(list(self._results.get("timestamps"))) self._timestamps = sorted(list(self._results[self._current_results].get("timestamps")))
self.setup_slider() self.setup_slider()
self.setup_table() self.setup_table()
@ -125,20 +125,24 @@ class ResultsWindow(PamhyrWindow):
def setup_table(self): def setup_table(self):
self._table = {} self._table = {}
for t in ["reach", "profile", "raw_data"]: for t in ["reach", "profile", "raw_data", "solver"]:
table = self.find(QTableView, f"tableView_{t}") table = self.find(QTableView, f"tableView_{t}")
self._table[t] = TableModel( self._table[t] = TableModel(
table_view=table, table_view=table,
table_headers=self._trad.get_dict(f"table_headers_{t}"), table_headers=self._trad.get_dict(f"table_headers_{t}"),
data=self._results, data=self._results,
undo=self._undo_stack, undo=self._undo_stack,
opt_data=t opt_data=t,
parent=self
) )
self._table[t]._timestamp = self._timestamps[ self._table[t]._timestamp = self._timestamps[
self._slider_time.value()] self._slider_time.value()]
if len(self._results) <= 1:
table = self.find(QTableView, f"tableView_solver")
table.hide()
def setup_slider(self): def setup_slider(self):
default_reach = self._results.river.reach(0) default_reach = self._results[self._current_results].river.reach(0)
self._slider_time = self.find(QSlider, f"horizontalSlider_time") self._slider_time = self.find(QSlider, f"horizontalSlider_time")
self._slider_time.setMaximum(len(self._timestamps) - 1) self._slider_time.setMaximum(len(self._timestamps) - 1)
@ -185,6 +189,7 @@ class ResultsWindow(PamhyrWindow):
results=self._results, results=self._results,
reach_id=0, reach_id=0,
profile_id=0, profile_id=0,
res_id=self._current_results,
trad=self._trad, trad=self._trad,
toolbar=self.toolbar, toolbar=self.toolbar,
display_current=True, display_current=True,
@ -209,6 +214,7 @@ class ResultsWindow(PamhyrWindow):
results=self._results, results=self._results,
reach_id=0, reach_id=0,
profile_id=0, profile_id=0,
res_id=self._current_results,
trad=self._trad, trad=self._trad,
toolbar=self.toolbar_2 toolbar=self.toolbar_2
) )
@ -231,6 +237,7 @@ class ResultsWindow(PamhyrWindow):
results=self._results, results=self._results,
reach_id=0, reach_id=0,
profile_id=0, profile_id=0,
res_id=self._current_results,
trad=self._trad, trad=self._trad,
toolbar=self.toolbar_3 toolbar=self.toolbar_3
) )
@ -254,6 +261,7 @@ class ResultsWindow(PamhyrWindow):
results=self._results, results=self._results,
reach_id=0, reach_id=0,
profile_id=0, profile_id=0,
res_id=self._current_results,
trad=self._trad, trad=self._trad,
toolbar=self.toolbar_4 toolbar=self.toolbar_4
) )
@ -328,9 +336,10 @@ class ResultsWindow(PamhyrWindow):
"reach": self._set_current_reach, "reach": self._set_current_reach,
"profile": self._set_current_profile, "profile": self._set_current_profile,
"raw_data": self._set_current_profile_raw_data, "raw_data": self._set_current_profile_raw_data,
"solver": self._set_current_results,
} }
for t in ["reach", "profile", "raw_data"]: for t in ["reach", "profile", "raw_data", "solver"]:
table = self.find(QTableView, f"tableView_{t}") table = self.find(QTableView, f"tableView_{t}")
table.selectionModel()\ table.selectionModel()\
@ -378,7 +387,28 @@ class ResultsWindow(PamhyrWindow):
) )
table.scrollTo(index) table.scrollTo(index)
def update(self, reach_id=None, profile_id=None, timestamp=None): def update_table_selection_solver(self, ind):
table = self.find(QTableView, f"tableView_solver")
selectionModel = table.selectionModel()
index = table.model().index(ind, 0)
selectionModel.select(
index,
QItemSelectionModel.Rows |
QItemSelectionModel.ClearAndSelect |
QItemSelectionModel.Select
)
table.scrollTo(index)
self._table["profile"].update(ind)
self._table["raw_data"].update(ind)
def update(self,
reach_id=None,
profile_id=None,
solver_id=None,
timestamp=None):
if reach_id is not None: if reach_id is not None:
self.plot_xy.set_reach(reach_id) self.plot_xy.set_reach(reach_id)
self.plot_ac.set_reach(reach_id) self.plot_ac.set_reach(reach_id)
@ -402,6 +432,15 @@ class ResultsWindow(PamhyrWindow):
self.update_table_selection_profile(profile_id) self.update_table_selection_profile(profile_id)
if solver_id is not None:
self.plot_xy.set_result(solver_id)
self.plot_ac.set_result(solver_id)
self.plot_rkc.set_result(solver_id)
self.plot_h.set_result(solver_id)
for plot in self._additional_plot:
self._additional_plot[plot].set_result(solver_id)
if timestamp is not None: if timestamp is not None:
self.plot_xy.set_timestamp(timestamp) self.plot_xy.set_timestamp(timestamp)
self.plot_ac.set_timestamp(timestamp) self.plot_ac.set_timestamp(timestamp)
@ -462,6 +501,14 @@ class ResultsWindow(PamhyrWindow):
ind = indexes[0].row() ind = indexes[0].row()
self.update(profile_id=ind) self.update(profile_id=ind)
def _set_current_results(self):
table = self.find(QTableView, f"tableView_solver")
indexes = table.selectedIndexes()
if len(indexes) == 0:
return
self.update(solver_id=indexes[0].row())
def _set_current_timestamp(self): def _set_current_timestamp(self):
timestamp = self._timestamps[self._slider_time.value()] timestamp = self._timestamps[self._slider_time.value()]
self.update(timestamp=timestamp) self.update(timestamp=timestamp)
@ -861,36 +908,36 @@ class ResultsWindow(PamhyrWindow):
return my_dict return my_dict
class CompareResultsWindow(ResultsWindow): #class CompareResultsWindow(ResultsWindow):
_pamhyr_ui = "Results" #_pamhyr_ui = "CompareResults"
_pamhyr_name = "Results" #_pamhyr_name = "CompareResults"
def _path_file(self, filename): #def _path_file(self, filename):
return os.path.abspath( #return os.path.abspath(
os.path.join( #os.path.join(
os.path.dirname(__file__), #os.path.dirname(__file__),
"..", "ui", "ressources", filename #"..", "ui", "ressources", filename
) #)
) #)
def __init__(self, study=None, config=None, #def __init__(self, study=None, config=None,
solver=None, results=None, #solver=None, results=None,
parent=None): #parent=None):
self._solver = solver #self._solvers[0] = solver
self._results = results #self._results = results
trad = CompareResultsTranslate() #trad = CompareResultsTranslate()
name = ( #name = (
trad[self._pamhyr_name] + " - " #trad[self._pamhyr_name] + " - "
+ study.name + " - " #+ study.name + " - "
+ self._solver.name #+ self._solvers[0].name
) #)
super(CompareResultsWindow, self).__init__( #super(CompareResultsWindow, self).__init__(
study=study, #study=study,
config=config, #config=config,
solver=solver, #solver=solver,
results=results, #results=results,
parent=parent, #parent=parent,
trad=trad #trad=trad
) #)

View File

@ -60,10 +60,14 @@ class ResultsTranslate(MainTranslate):
} }
self._sub_dict["table_headers_profile"] = { self._sub_dict["table_headers_profile"] = {
"name": self._dict["name"], "name": _translate("Results", "Profile name"),
"rk": self._dict["unit_rk"], "rk": self._dict["unit_rk"],
} }
self._sub_dict["table_headers_solver"] = {
"solver": _translate("Results", "Solver"),
}
self._sub_dict["table_headers_pollutants"] = { self._sub_dict["table_headers_pollutants"] = {
"name": _translate("Results", "Pollutant name"), "name": _translate("Results", "Pollutant name"),
} }

View File

@ -41,6 +41,13 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="horizontalLayoutWidget">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QTableView" name="tableView_solver"/>
</item>
</layout>
</widget>
</widget> </widget>
<widget class="QWidget" name="layoutWidget"> <widget class="QWidget" name="layoutWidget">
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">

View File

@ -46,9 +46,6 @@
<item> <item>
<widget class="QTableView" name="tableView_pollutants"/> <widget class="QTableView" name="tableView_pollutants"/>
</item> </item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_tot_left"/>
</item>
</layout> </layout>
</widget> </widget>
</widget> </widget>
@ -457,7 +454,7 @@
<resources/> <resources/>
<connections/> <connections/>
<buttongroups> <buttongroups>
<buttongroup name="buttonGroup"/>
<buttongroup name="buttonGroup_2"/> <buttongroup name="buttonGroup_2"/>
<buttongroup name="buttonGroup"/>
</buttongroups> </buttongroups>
</ui> </ui>