Results: Continue db load method.

scenarios
Pierre-Antoine 2025-09-23 09:57:37 +02:00
parent 3a3c4d9d73
commit f0ccf1f4f7
1 changed files with 30 additions and 11 deletions

View File

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