mirror of https://gitlab.com/pamhyr/pamhyr2
Compare commits
4 Commits
e0cee0fbef
...
fc7d732e0a
| Author | SHA1 | Date |
|---|---|---|
|
|
fc7d732e0a | |
|
|
cc5d86328b | |
|
|
e3cbe3cf1f | |
|
|
9482aaf523 |
|
|
@ -175,7 +175,7 @@ class PointXYZ(Point):
|
|||
return new
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, deleted, " +
|
||||
"SELECT pamhyr_id, ind, deleted, " +
|
||||
"name, x, y, z, sl, scenario " +
|
||||
"FROM geometry_pointXYZ " +
|
||||
f"WHERE profile = {profile.pamhyr_id} " +
|
||||
|
|
@ -188,6 +188,7 @@ class PointXYZ(Point):
|
|||
it = iter(row)
|
||||
|
||||
pid = next(it)
|
||||
ind = next(it)
|
||||
deleted = (next(it) == 1)
|
||||
name = next(it)
|
||||
x = next(it)
|
||||
|
|
@ -218,7 +219,7 @@ class PointXYZ(Point):
|
|||
)
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(point)
|
||||
new.append((ind, point))
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
new += cls._db_load(execute, data)
|
||||
|
|
|
|||
|
|
@ -276,8 +276,21 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||
None
|
||||
)
|
||||
|
||||
loaded_save = data['loaded_pid']
|
||||
data['loaded_pid'] = set()
|
||||
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)
|
||||
new.append(profile)
|
||||
|
|
|
|||
|
|
@ -83,6 +83,11 @@ class Reach(SQLSubModel):
|
|||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
ok = True
|
||||
|
||||
execute(
|
||||
"DELETE FROM geometry_profileXYZ " +
|
||||
f"WHERE reach = {self.pamhyr_id} " +
|
||||
|
|
@ -92,10 +97,10 @@ class Reach(SQLSubModel):
|
|||
ind = 0
|
||||
for profile in self._profiles:
|
||||
data["ind"] = ind
|
||||
profile._db_save(execute, data)
|
||||
ok &= profile._db_save(execute, data)
|
||||
ind += 1
|
||||
|
||||
return True
|
||||
return ok
|
||||
|
||||
def profile(self, i):
|
||||
"""Returns profile at index i
|
||||
|
|
@ -169,7 +174,7 @@ class Reach(SQLSubModel):
|
|||
"""
|
||||
profile = ProfileXYZ(reach=self, status=self._status)
|
||||
|
||||
self.profiles.insert(index, profile)
|
||||
self._profiles.insert(index, profile)
|
||||
|
||||
self.modified()
|
||||
|
||||
|
|
@ -187,7 +192,7 @@ class Reach(SQLSubModel):
|
|||
if profile in self._profiles:
|
||||
self.undelete([profile])
|
||||
else:
|
||||
self.profiles.insert(index, profile)
|
||||
self._profiles.insert(index, profile)
|
||||
|
||||
self.modified()
|
||||
|
||||
|
|
@ -205,7 +210,7 @@ class Reach(SQLSubModel):
|
|||
lambda p: p[1].set_as_deleted(),
|
||||
filter(
|
||||
lambda e: e[0] in indexes,
|
||||
enumerate(self.profiles)
|
||||
enumerate(self._profiles)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
@ -237,13 +242,14 @@ class Reach(SQLSubModel):
|
|||
def purge(self):
|
||||
for el in self._profiles:
|
||||
el.set_as_deleted()
|
||||
|
||||
self.modified()
|
||||
|
||||
def move_up_profile(self, index: int):
|
||||
if index < len(self.profiles):
|
||||
next = index - 1
|
||||
|
||||
p = self.profiles
|
||||
p = self._profiles
|
||||
p[index], p[next] = p[next], p[index]
|
||||
self.modified()
|
||||
|
||||
|
|
@ -251,7 +257,7 @@ class Reach(SQLSubModel):
|
|||
if index >= 0:
|
||||
prev = index + 1
|
||||
|
||||
p = self.profiles
|
||||
p = self._profiles
|
||||
p[index], p[prev] = p[prev], p[index]
|
||||
self.modified()
|
||||
|
||||
|
|
@ -522,8 +528,8 @@ class Reach(SQLSubModel):
|
|||
|
||||
@timer
|
||||
def sort(self, is_reversed: bool = False):
|
||||
self.profiles = sorted(
|
||||
self.profiles,
|
||||
self._profiles = sorted(
|
||||
self._profiles,
|
||||
key=lambda profile: profile.rk,
|
||||
reverse=is_reversed
|
||||
)
|
||||
|
|
@ -534,11 +540,11 @@ class Reach(SQLSubModel):
|
|||
if len(self.profiles) != len(indexes):
|
||||
logger.critical("Indexes list do not correspond to profile list")
|
||||
|
||||
self.profiles = list(
|
||||
self._profiles = list(
|
||||
map(
|
||||
lambda x: x[1],
|
||||
sorted(
|
||||
enumerate(self.profiles),
|
||||
enumerate(self._profiles),
|
||||
key=lambda x: indexes[x[0]]
|
||||
)
|
||||
)
|
||||
|
|
@ -599,7 +605,7 @@ class Reach(SQLSubModel):
|
|||
|
||||
profiles.append(prof)
|
||||
|
||||
self.profiles = profiles + self.profiles
|
||||
self._profiles = profiles + self._profiles
|
||||
self._recompute_rk()
|
||||
|
||||
return profiles
|
||||
|
|
@ -647,7 +653,7 @@ class Reach(SQLSubModel):
|
|||
logger.error(e)
|
||||
e.alert()
|
||||
finally:
|
||||
self.profiles = imported_profiles + self.profiles
|
||||
self._profiles = self._profiles + imported_profiles
|
||||
|
||||
return imported_profiles
|
||||
|
||||
|
|
|
|||
|
|
@ -489,8 +489,6 @@ class InitialConditions(SQLSubModel):
|
|||
def generate_growing_constant_depth(self, height: float,
|
||||
compute_discharge: bool):
|
||||
profiles = self._reach.reach.profiles.copy()
|
||||
profiles.reverse()
|
||||
|
||||
previous_elevation = -99999.99
|
||||
|
||||
data_discharge = {}
|
||||
|
|
@ -550,13 +548,10 @@ class InitialConditions(SQLSubModel):
|
|||
previous_elevation = elevation
|
||||
self._data.append(new)
|
||||
|
||||
self._data.reverse()
|
||||
|
||||
def generate_discharge(self, discharge: float, compute_height: bool):
|
||||
profiles = self._reach.reach.profiles.copy()
|
||||
if profiles is None:
|
||||
return None
|
||||
profiles.reverse()
|
||||
|
||||
previous_elevation = -99999.99
|
||||
|
||||
|
|
@ -614,8 +609,6 @@ class InitialConditions(SQLSubModel):
|
|||
previous_elevation = elevation
|
||||
self._data.append(new)
|
||||
|
||||
self._data.reverse()
|
||||
|
||||
def generate_height(self,
|
||||
elevation1: float,
|
||||
elevation2: float,
|
||||
|
|
|
|||
Loading…
Reference in New Issue