Compare commits

..

No commits in common. "fc7d732e0af0ca8a3bddf6e3586bc932cdac5f2d" and "e0cee0fbef4048e276ec1245a16345d9a3b24ab3" have entirely different histories.

4 changed files with 23 additions and 36 deletions

View File

@ -175,7 +175,7 @@ class PointXYZ(Point):
return new return new
table = execute( table = execute(
"SELECT pamhyr_id, ind, deleted, " + "SELECT pamhyr_id, deleted, " +
"name, x, y, z, sl, scenario " + "name, x, y, z, sl, scenario " +
"FROM geometry_pointXYZ " + "FROM geometry_pointXYZ " +
f"WHERE profile = {profile.pamhyr_id} " + f"WHERE profile = {profile.pamhyr_id} " +
@ -188,7 +188,6 @@ class PointXYZ(Point):
it = iter(row) it = iter(row)
pid = next(it) pid = next(it)
ind = next(it)
deleted = (next(it) == 1) deleted = (next(it) == 1)
name = next(it) name = next(it)
x = next(it) x = next(it)
@ -219,7 +218,7 @@ class PointXYZ(Point):
) )
loaded.add(pid) loaded.add(pid)
new.append((ind, point)) new.append(point)
data["scenario"] = scenario.parent data["scenario"] = scenario.parent
new += cls._db_load(execute, data) new += cls._db_load(execute, data)

View File

@ -276,21 +276,8 @@ class ProfileXYZ(Profile, SQLSubModel):
None None
) )
loaded_save = data['loaded_pid']
data['loaded_pid'] = set()
data["profile"] = profile data["profile"] = profile
profile._points = PointXYZ._db_load(execute, data.copy())
profile._points = list(
map(
lambda ip: ip[1],
sorted(
PointXYZ._db_load(execute, data.copy()),
key=lambda ip: ip[0]
)
)
)
data['loaded_pid'] = loaded_save
loaded.add(pid) loaded.add(pid)
new.append(profile) new.append(profile)

View File

@ -83,11 +83,6 @@ class Reach(SQLSubModel):
return new return new
def _db_save(self, execute, data=None): def _db_save(self, execute, data=None):
if not self.must_be_saved():
return True
ok = True
execute( execute(
"DELETE FROM geometry_profileXYZ " + "DELETE FROM geometry_profileXYZ " +
f"WHERE reach = {self.pamhyr_id} " + f"WHERE reach = {self.pamhyr_id} " +
@ -97,10 +92,10 @@ class Reach(SQLSubModel):
ind = 0 ind = 0
for profile in self._profiles: for profile in self._profiles:
data["ind"] = ind data["ind"] = ind
ok &= profile._db_save(execute, data) profile._db_save(execute, data)
ind += 1 ind += 1
return ok return True
def profile(self, i): def profile(self, i):
"""Returns profile at index i """Returns profile at index i
@ -174,7 +169,7 @@ class Reach(SQLSubModel):
""" """
profile = ProfileXYZ(reach=self, status=self._status) profile = ProfileXYZ(reach=self, status=self._status)
self._profiles.insert(index, profile) self.profiles.insert(index, profile)
self.modified() self.modified()
@ -192,7 +187,7 @@ class Reach(SQLSubModel):
if profile in self._profiles: if profile in self._profiles:
self.undelete([profile]) self.undelete([profile])
else: else:
self._profiles.insert(index, profile) self.profiles.insert(index, profile)
self.modified() self.modified()
@ -210,7 +205,7 @@ class Reach(SQLSubModel):
lambda p: p[1].set_as_deleted(), lambda p: p[1].set_as_deleted(),
filter( filter(
lambda e: e[0] in indexes, lambda e: e[0] in indexes,
enumerate(self._profiles) enumerate(self.profiles)
) )
) )
) )
@ -242,14 +237,13 @@ class Reach(SQLSubModel):
def purge(self): def purge(self):
for el in self._profiles: for el in self._profiles:
el.set_as_deleted() el.set_as_deleted()
self.modified() self.modified()
def move_up_profile(self, index: int): def move_up_profile(self, index: int):
if index < len(self.profiles): if index < len(self.profiles):
next = index - 1 next = index - 1
p = self._profiles p = self.profiles
p[index], p[next] = p[next], p[index] p[index], p[next] = p[next], p[index]
self.modified() self.modified()
@ -257,7 +251,7 @@ class Reach(SQLSubModel):
if index >= 0: if index >= 0:
prev = index + 1 prev = index + 1
p = self._profiles p = self.profiles
p[index], p[prev] = p[prev], p[index] p[index], p[prev] = p[prev], p[index]
self.modified() self.modified()
@ -528,8 +522,8 @@ class Reach(SQLSubModel):
@timer @timer
def sort(self, is_reversed: bool = False): def sort(self, is_reversed: bool = False):
self._profiles = sorted( self.profiles = sorted(
self._profiles, self.profiles,
key=lambda profile: profile.rk, key=lambda profile: profile.rk,
reverse=is_reversed reverse=is_reversed
) )
@ -540,11 +534,11 @@ class Reach(SQLSubModel):
if len(self.profiles) != len(indexes): if len(self.profiles) != len(indexes):
logger.critical("Indexes list do not correspond to profile list") logger.critical("Indexes list do not correspond to profile list")
self._profiles = list( self.profiles = list(
map( map(
lambda x: x[1], lambda x: x[1],
sorted( sorted(
enumerate(self._profiles), enumerate(self.profiles),
key=lambda x: indexes[x[0]] key=lambda x: indexes[x[0]]
) )
) )
@ -605,7 +599,7 @@ class Reach(SQLSubModel):
profiles.append(prof) profiles.append(prof)
self._profiles = profiles + self._profiles self.profiles = profiles + self.profiles
self._recompute_rk() self._recompute_rk()
return profiles return profiles
@ -653,7 +647,7 @@ class Reach(SQLSubModel):
logger.error(e) logger.error(e)
e.alert() e.alert()
finally: finally:
self._profiles = self._profiles + imported_profiles self.profiles = imported_profiles + self.profiles
return imported_profiles return imported_profiles

View File

@ -489,6 +489,8 @@ class InitialConditions(SQLSubModel):
def generate_growing_constant_depth(self, height: float, def generate_growing_constant_depth(self, height: float,
compute_discharge: bool): compute_discharge: bool):
profiles = self._reach.reach.profiles.copy() profiles = self._reach.reach.profiles.copy()
profiles.reverse()
previous_elevation = -99999.99 previous_elevation = -99999.99
data_discharge = {} data_discharge = {}
@ -548,10 +550,13 @@ class InitialConditions(SQLSubModel):
previous_elevation = elevation previous_elevation = elevation
self._data.append(new) self._data.append(new)
self._data.reverse()
def generate_discharge(self, discharge: float, compute_height: bool): def generate_discharge(self, discharge: float, compute_height: bool):
profiles = self._reach.reach.profiles.copy() profiles = self._reach.reach.profiles.copy()
if profiles is None: if profiles is None:
return None return None
profiles.reverse()
previous_elevation = -99999.99 previous_elevation = -99999.99
@ -609,6 +614,8 @@ class InitialConditions(SQLSubModel):
previous_elevation = elevation previous_elevation = elevation
self._data.append(new) self._data.append(new)
self._data.reverse()
def generate_height(self, def generate_height(self,
elevation1: float, elevation1: float,
elevation2: float, elevation2: float,