diff --git a/src/Model/Results/River/River.py b/src/Model/Results/River/River.py index 129a632e..204e0048 100644 --- a/src/Model/Results/River/River.py +++ b/src/Model/Results/River/River.py @@ -111,7 +111,7 @@ class Profile(SQLSubModel): @classmethod def _db_load(cls, execute, data=None): - new = [] + new = {} status = data['status'] study = data['study'] @@ -140,18 +140,27 @@ class Profile(SQLSubModel): data = next(it) owner_scenario = next(it) - new_data = cls(profile, study) + if profile not in new: + new_data = cls(profile, study) + new[profile] = new_data + else: + new_data = new[profile] sf = ">" + ''.join(itertools.repeat("f", len_data)) values = struct.unpack(sf, data) for timestamp, value in zip(timestamps, values): new_data.set(timestamp, key, value) + if key == "Z": + new_data.update_water_limits(timestamp, value) - loaded.add(pid) - new.append(new_data) + return list(new.values()) - return new + def update_water_limits(self, timestamp, z): + limits = self.geometry.get_water_limits(z) + self.set( + timestamp, "water_limits", limits + ) def get_keys(self): return reduce( @@ -250,10 +259,10 @@ class Reach(SQLSubModel): reach = data["reach"] new_reach = cls( - data["reach"], data["study"] + data["reach"], data["study"], with_init=False ) - for profile in reach.profiles: + for i, profile in enumerate(reach.profiles): data["profile"] = profile new_reach._profiles += Profile._db_load(execute, data) diff --git a/src/Model/Study.py b/src/Model/Study.py index 77972d4c..d1dd8013 100644 --- a/src/Model/Study.py +++ b/src/Model/Study.py @@ -527,3 +527,11 @@ class Study(SQLModel): self.status.set_as_editable() return new + + @property + def results(self): + return self._river._results + + @results.setter + def results(self, results): + self._river._results = results diff --git a/src/View/MainWindow.py b/src/View/MainWindow.py index b0d8a49e..ea122508 100644 --- a/src/View/MainWindow.py +++ b/src/View/MainWindow.py @@ -593,6 +593,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): def set_results(self, solver, results): self._last_solver = solver self._last_results = results + self._study.results = results self.enable_actions("action_menu_results_last", True) @@ -1607,6 +1608,9 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): if self._last_solver is None: return + if self._study is not None and self._study.results is not None: + self._last_results = self._study.results + if self._last_solver._type == "mage8": self.open_solver_results(self._last_solver, self._last_results) diff --git a/src/View/Results/PlotAC.py b/src/View/Results/PlotAC.py index dd676469..895e69ee 100644 --- a/src/View/Results/PlotAC.py +++ b/src/View/Results/PlotAC.py @@ -116,7 +116,7 @@ class PlotAC(PamhyrPlot): self.collection = self.canvas.axes.fill_between( x, z, water_z, - where=z <= water_z, + where=list(map(lambda x: x <= water_z, z)), color=self.color_plot_river_water_zone, alpha=0.7, interpolate=True ) @@ -254,7 +254,7 @@ class PlotAC(PamhyrPlot): self.collection.remove() self.collection = self.canvas.axes.fill_between( x, z, water_z, - where=z <= water_z, + where=list(map(lambda x: x <= water_z, z)), color=self.color_plot_river_water_zone, alpha=0.7, interpolate=True ) diff --git a/src/View/Results/PlotXY.py b/src/View/Results/PlotXY.py index 977ddbec..88f5ebdf 100644 --- a/src/View/Results/PlotXY.py +++ b/src/View/Results/PlotXY.py @@ -286,6 +286,7 @@ class PlotXY(PamhyrPlot): water_z = profile.get_ts_key( self._current_timestamp, "Z" ) + pt_left, pt_right = profile.get_ts_key( self._current_timestamp, "water_limits"