From f0ccf1f4f7e8ba9d457b4d3af02ac32f02d0c941 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Tue, 23 Sep 2025 09:57:37 +0200 Subject: [PATCH] Results: Continue db load method. --- src/Model/Results/River/River.py | 41 +++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/src/Model/Results/River/River.py b/src/Model/Results/River/River.py index 7f89a7af..138b1af6 100644 --- a/src/Model/Results/River/River.py +++ b/src/Model/Results/River/River.py @@ -113,19 +113,22 @@ class Profile(SQLSubModel): @classmethod def _db_load(cls, execute, data=None): new = [] + status = data['status'] study = data['study'] - status = data['status'] + reach = data['reach'] + profile = data['profile'] scenario = data["scenario"] loaded = data['loaded_pid'] timestamps = data['timestamps'] values = execute( "SELECT pamhyr_id, result, key, " + - "reach, section, len_data, data, scenario " + + "len_data, data, scenario " + "FROM results_data " + f"WHERE scenario = {scenario.id} " + - f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))})" + f"AND reach = {reach.pamhyr_id} " + + f"AND section = {profile.pamhyr_id}" ) for v in values: @@ -134,16 +137,11 @@ class Profile(SQLSubModel): pid = next(it) result = next(it) key = next(it) - reach = next(it) - section = next(it) len_data = next(it) data = next(it) owner_scenario = next(it) - new_data = cls( - id=pid, status=status, - owner_scenario=owner_scenario - ) + new_data = cls(profile, study) sf = ">" + ''.join(itertools.repeat("f", len_data)) values = struct.unpack(sf, data) @@ -234,7 +232,19 @@ class Reach(SQLSubModel): @classmethod def _db_load(cls, execute, data=None): - return cls._db_load(execute, data) + reach = data["reach"] + + new_reach = cls( + data["reach"], data["study"] + ) + + for profile in reach.profiles: + data["profile"] = profile + new_reach._profiles.append( + Profile._db_load(execute, data) + ) + + return new_reach def _db_save(self, execute, data=None): for profile in self._profiles: @@ -293,7 +303,16 @@ class River(SQLSubModel): @classmethod def _db_load(cls, execute, data=None): - return cls._db_load(execute, data) + study = data["study"] + new_river = cls(study) + + for reach in study.river.reachs(): + data["reach"] = reach.reach + new_river._reachs.append( + Reach._db_load(execute, data) + ) + + return new_river def _db_save(self, execute, data=None): for reach in self._reachs: