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
|
return new
|
||||||
|
|
||||||
table = execute(
|
table = execute(
|
||||||
"SELECT pamhyr_id, deleted, " +
|
"SELECT pamhyr_id, ind, 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,6 +188,7 @@ 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)
|
||||||
|
|
@ -218,7 +219,7 @@ class PointXYZ(Point):
|
||||||
)
|
)
|
||||||
|
|
||||||
loaded.add(pid)
|
loaded.add(pid)
|
||||||
new.append(point)
|
new.append((ind, point))
|
||||||
|
|
||||||
data["scenario"] = scenario.parent
|
data["scenario"] = scenario.parent
|
||||||
new += cls._db_load(execute, data)
|
new += cls._db_load(execute, data)
|
||||||
|
|
|
||||||
|
|
@ -276,8 +276,21 @@ 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)
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,11 @@ 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} " +
|
||||||
|
|
@ -92,10 +97,10 @@ class Reach(SQLSubModel):
|
||||||
ind = 0
|
ind = 0
|
||||||
for profile in self._profiles:
|
for profile in self._profiles:
|
||||||
data["ind"] = ind
|
data["ind"] = ind
|
||||||
profile._db_save(execute, data)
|
ok &= profile._db_save(execute, data)
|
||||||
ind += 1
|
ind += 1
|
||||||
|
|
||||||
return True
|
return ok
|
||||||
|
|
||||||
def profile(self, i):
|
def profile(self, i):
|
||||||
"""Returns profile at index i
|
"""Returns profile at index i
|
||||||
|
|
@ -169,7 +174,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()
|
||||||
|
|
||||||
|
|
@ -187,7 +192,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()
|
||||||
|
|
||||||
|
|
@ -205,7 +210,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)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
@ -237,13 +242,14 @@ 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()
|
||||||
|
|
||||||
|
|
@ -251,7 +257,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()
|
||||||
|
|
||||||
|
|
@ -522,8 +528,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
|
||||||
)
|
)
|
||||||
|
|
@ -534,11 +540,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]]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
@ -599,7 +605,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
|
||||||
|
|
@ -647,7 +653,7 @@ class Reach(SQLSubModel):
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
e.alert()
|
e.alert()
|
||||||
finally:
|
finally:
|
||||||
self.profiles = imported_profiles + self.profiles
|
self._profiles = self._profiles + imported_profiles
|
||||||
|
|
||||||
return imported_profiles
|
return imported_profiles
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -489,8 +489,6 @@ 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 = {}
|
||||||
|
|
@ -550,13 +548,10 @@ 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
|
||||||
|
|
||||||
|
|
@ -614,8 +609,6 @@ 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,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue