Results: Fix db save results open and display.

scenarios
Pierre-Antoine 2025-09-25 10:58:29 +02:00
parent 9375827949
commit dbcdace348
5 changed files with 31 additions and 9 deletions

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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
)

View File

@ -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"