mirror of https://gitlab.com/pamhyr/pamhyr2
SL: Save sl fk in database for point and profile.
parent
c5402ebb55
commit
b87977a2d8
|
|
@ -37,6 +37,17 @@ class PointXYZ(Point, SQLSubModel):
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_update(cls, execute, version):
|
def _sql_update(cls, execute, version):
|
||||||
cls._update_submodel(execute, version)
|
cls._update_submodel(execute, version)
|
||||||
|
|
||||||
|
major, minor, release = version.strip().split(".")
|
||||||
|
if major == minor == "0":
|
||||||
|
if int(release) < 2:
|
||||||
|
execute(
|
||||||
|
"""
|
||||||
|
ALTER TABLE geometry_pointXYZ
|
||||||
|
ADD COLUMN sl INTEGER
|
||||||
|
REFERENCES sedimentary_layer(id)
|
||||||
|
"""
|
||||||
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
@ -47,7 +58,7 @@ class PointXYZ(Point, SQLSubModel):
|
||||||
profile = data["profile"]
|
profile = data["profile"]
|
||||||
|
|
||||||
table = execute(
|
table = execute(
|
||||||
"SELECT ind, name, x, y, z " +
|
"SELECT ind, name, x, y, z, sl " +
|
||||||
"FROM geometry_pointXYZ " +
|
"FROM geometry_pointXYZ " +
|
||||||
f"WHERE profile = {profile.id}"
|
f"WHERE profile = {profile.id}"
|
||||||
)
|
)
|
||||||
|
|
@ -63,6 +74,7 @@ class PointXYZ(Point, SQLSubModel):
|
||||||
x = row[2]
|
x = row[2]
|
||||||
y = row[3]
|
y = row[3]
|
||||||
z = row[4]
|
z = row[4]
|
||||||
|
sl = row[5]
|
||||||
|
|
||||||
new = cls(
|
new = cls(
|
||||||
name = name,
|
name = name,
|
||||||
|
|
@ -71,6 +83,16 @@ class PointXYZ(Point, SQLSubModel):
|
||||||
status = status
|
status = status
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if sl == -1 or sl == None:
|
||||||
|
new._sl = None
|
||||||
|
else:
|
||||||
|
new._sl = next(
|
||||||
|
filter(
|
||||||
|
lambda s: s.id == sl,
|
||||||
|
data["sediment_layers_list"].sediment_layers
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
points[ind] = new
|
points[ind] = new
|
||||||
|
|
||||||
return points
|
return points
|
||||||
|
|
@ -79,13 +101,15 @@ class PointXYZ(Point, SQLSubModel):
|
||||||
profile = data["profile"]
|
profile = data["profile"]
|
||||||
ind = data["ind"]
|
ind = data["ind"]
|
||||||
|
|
||||||
|
sl = self._sl.id if self._sl is not None else -1
|
||||||
|
|
||||||
sql = (
|
sql = (
|
||||||
"INSERT OR REPLACE INTO " +
|
"INSERT OR REPLACE INTO " +
|
||||||
"geometry_pointXYZ(ind, name, x, y, z, profile) "+
|
"geometry_pointXYZ(ind, name, x, y, z, profile, sl) "+
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{ind}, '{self._sql_format(self._name)}', " +
|
f"{ind}, '{self._sql_format(self._name)}', " +
|
||||||
f"{self.x}, {self.y}, {self.z}, " +
|
f"{self.x}, {self.y}, {self.z}, " +
|
||||||
f"{profile.id}" +
|
f"{profile.id}, {sl}" +
|
||||||
")"
|
")"
|
||||||
)
|
)
|
||||||
execute(sql)
|
execute(sql)
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ class Profile(object):
|
||||||
return self._sl
|
return self._sl
|
||||||
|
|
||||||
@sl.setter
|
@sl.setter
|
||||||
def sl(self, value: str):
|
def sl(self, value):
|
||||||
self._sl = value
|
self._sl = value
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,17 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_update(cls, execute, version):
|
def _sql_update(cls, execute, version):
|
||||||
|
major, minor, release = version.strip().split(".")
|
||||||
|
if major == minor == "0":
|
||||||
|
if int(release) < 2:
|
||||||
|
execute(
|
||||||
|
"""
|
||||||
|
ALTER TABLE geometry_profileXYZ
|
||||||
|
ADD COLUMN sl INTEGER
|
||||||
|
REFERENCES sedimentary_layer(id)
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
return cls._update_submodel(execute, version)
|
return cls._update_submodel(execute, version)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
@ -77,7 +88,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||||
reach = data["reach"]
|
reach = data["reach"]
|
||||||
|
|
||||||
table = execute(
|
table = execute(
|
||||||
"SELECT id, ind, name, kp, num, code1, code2 " +
|
"SELECT id, ind, name, kp, num, code1, code2, sl " +
|
||||||
"FROM geometry_profileXYZ " +
|
"FROM geometry_profileXYZ " +
|
||||||
f"WHERE reach = {reach}"
|
f"WHERE reach = {reach}"
|
||||||
)
|
)
|
||||||
|
|
@ -93,6 +104,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||||
num = row[5]
|
num = row[5]
|
||||||
code1 = row[5]
|
code1 = row[5]
|
||||||
code2 = row[6]
|
code2 = row[6]
|
||||||
|
sl = row[7]
|
||||||
|
|
||||||
new = cls(
|
new = cls(
|
||||||
id=id, num = num,
|
id=id, num = num,
|
||||||
|
|
@ -102,6 +114,16 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||||
status = status
|
status = status
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if sl == -1 or sl == None:
|
||||||
|
new._sl = None
|
||||||
|
else:
|
||||||
|
new._sl = next(
|
||||||
|
filter(
|
||||||
|
lambda s: s.id == sl,
|
||||||
|
data["sediment_layers_list"].sediment_layers
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
data["profile"] = new
|
data["profile"] = new
|
||||||
new._points = PointXYZ._sql_load(execute, data)
|
new._points = PointXYZ._sql_load(execute, data)
|
||||||
|
|
||||||
|
|
@ -113,13 +135,15 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||||
ok = True
|
ok = True
|
||||||
ind = data["ind"]
|
ind = data["ind"]
|
||||||
|
|
||||||
|
sl = self._sl.id if self._sl is not None else -1
|
||||||
|
|
||||||
sql = (
|
sql = (
|
||||||
"INSERT OR REPLACE INTO " +
|
"INSERT OR REPLACE INTO " +
|
||||||
"geometry_profileXYZ(id, ind, name, reach, kp, num, code1, code2) "+
|
"geometry_profileXYZ(id, ind, name, reach, kp, num, code1, code2, sl) "+
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{self.id}, {ind}, '{self._sql_format(self._name)}', " +
|
f"{self.id}, {ind}, '{self._sql_format(self._name)}', " +
|
||||||
f"{self.reach.id}, {self.kp}, {self.num}, " +
|
f"{self.reach.id}, {self.kp}, {self.num}, " +
|
||||||
f"{self.code1}, {self.code1}" +
|
f"{self.code1}, {self.code1}, {sl}" +
|
||||||
")"
|
")"
|
||||||
)
|
)
|
||||||
execute(sql)
|
execute(sql)
|
||||||
|
|
|
||||||
|
|
@ -233,6 +233,14 @@ class River(Graph, SQLSubModel):
|
||||||
)
|
)
|
||||||
data["stricklers"] = new._stricklers
|
data["stricklers"] = new._stricklers
|
||||||
|
|
||||||
|
|
||||||
|
# Initial conditions
|
||||||
|
new._sediment_layers = SedimentLayerList._sql_load(
|
||||||
|
execute,
|
||||||
|
data
|
||||||
|
)
|
||||||
|
data["sediment_layers_list"] = new._sediment_layers
|
||||||
|
|
||||||
# Network
|
# Network
|
||||||
new._nodes = RiverNode._sql_load(
|
new._nodes = RiverNode._sql_load(
|
||||||
execute,
|
execute,
|
||||||
|
|
@ -263,12 +271,6 @@ class River(Graph, SQLSubModel):
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
|
|
||||||
# Initial conditions
|
|
||||||
new._sediment_layers = SedimentLayerList._sql_load(
|
|
||||||
execute,
|
|
||||||
data
|
|
||||||
)
|
|
||||||
|
|
||||||
# Parameters
|
# Parameters
|
||||||
new._parameters = SolverParametersList._sql_load(
|
new._parameters = SolverParametersList._sql_load(
|
||||||
execute,
|
execute,
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ class Study(SQLModel):
|
||||||
|
|
||||||
def __init__(self, filename = None, init_new = True):
|
def __init__(self, filename = None, init_new = True):
|
||||||
# Metadata
|
# Metadata
|
||||||
self._version = "0.0.1"
|
self._version = "0.0.2"
|
||||||
self.creation_date = datetime.now()
|
self.creation_date = datetime.now()
|
||||||
self.last_modification_date = datetime.now()
|
self.last_modification_date = datetime.now()
|
||||||
self.last_save_date = datetime.now()
|
self.last_save_date = datetime.now()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue