Commit b87977a2 authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

SL: Save sl fk in database for point and profile.

Showing with 64 additions and 14 deletions
+64 -14
......@@ -37,6 +37,17 @@ class PointXYZ(Point, SQLSubModel):
@classmethod
def _sql_update(cls, 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
@classmethod
......@@ -47,7 +58,7 @@ class PointXYZ(Point, SQLSubModel):
profile = data["profile"]
table = execute(
"SELECT ind, name, x, y, z " +
"SELECT ind, name, x, y, z, sl " +
"FROM geometry_pointXYZ " +
f"WHERE profile = {profile.id}"
)
......@@ -63,6 +74,7 @@ class PointXYZ(Point, SQLSubModel):
x = row[2]
y = row[3]
z = row[4]
sl = row[5]
new = cls(
name = name,
......@@ -71,6 +83,16 @@ class PointXYZ(Point, SQLSubModel):
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
return points
......@@ -79,13 +101,15 @@ class PointXYZ(Point, SQLSubModel):
profile = data["profile"]
ind = data["ind"]
sl = self._sl.id if self._sl is not None else -1
sql = (
"INSERT OR REPLACE INTO " +
"geometry_pointXYZ(ind, name, x, y, z, profile) "+
"geometry_pointXYZ(ind, name, x, y, z, profile, sl) "+
"VALUES (" +
f"{ind}, '{self._sql_format(self._name)}', " +
f"{self.x}, {self.y}, {self.z}, " +
f"{profile.id}" +
f"{profile.id}, {sl}" +
")"
)
execute(sql)
......
......@@ -133,7 +133,7 @@ class Profile(object):
return self._sl
@sl.setter
def sl(self, value: str):
def sl(self, value):
self._sl = value
self._status.modified()
......
......@@ -68,6 +68,17 @@ class ProfileXYZ(Profile, SQLSubModel):
@classmethod
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)
@classmethod
......@@ -77,7 +88,7 @@ class ProfileXYZ(Profile, SQLSubModel):
reach = data["reach"]
table = execute(
"SELECT id, ind, name, kp, num, code1, code2 " +
"SELECT id, ind, name, kp, num, code1, code2, sl " +
"FROM geometry_profileXYZ " +
f"WHERE reach = {reach}"
)
......@@ -93,6 +104,7 @@ class ProfileXYZ(Profile, SQLSubModel):
num = row[5]
code1 = row[5]
code2 = row[6]
sl = row[7]
new = cls(
id=id, num = num,
......@@ -102,6 +114,16 @@ class ProfileXYZ(Profile, SQLSubModel):
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
new._points = PointXYZ._sql_load(execute, data)
......@@ -113,13 +135,15 @@ class ProfileXYZ(Profile, SQLSubModel):
ok = True
ind = data["ind"]
sl = self._sl.id if self._sl is not None else -1
sql = (
"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 (" +
f"{self.id}, {ind}, '{self._sql_format(self._name)}', " +
f"{self.reach.id}, {self.kp}, {self.num}, " +
f"{self.code1}, {self.code1}" +
f"{self.code1}, {self.code1}, {sl}" +
")"
)
execute(sql)
......
......@@ -233,6 +233,14 @@ class River(Graph, SQLSubModel):
)
data["stricklers"] = new._stricklers
# Initial conditions
new._sediment_layers = SedimentLayerList._sql_load(
execute,
data
)
data["sediment_layers_list"] = new._sediment_layers
# Network
new._nodes = RiverNode._sql_load(
execute,
......@@ -263,12 +271,6 @@ class River(Graph, SQLSubModel):
data
)
# Initial conditions
new._sediment_layers = SedimentLayerList._sql_load(
execute,
data
)
# Parameters
new._parameters = SolverParametersList._sql_load(
execute,
......
......@@ -24,7 +24,7 @@ class Study(SQLModel):
def __init__(self, filename = None, init_new = True):
# Metadata
self._version = "0.0.1"
self._version = "0.0.2"
self.creation_date = datetime.now()
self.last_modification_date = datetime.now()
self.last_save_date = datetime.now()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment