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

Model, Stricklers: Add SQL export for stricklers.

Showing with 114 additions and 15 deletions
+114 -15
......@@ -32,8 +32,7 @@ class PointXYZ(Point, SQLSubModel):
)
""")
cls._create_submodel(execute)
return True
return cls._create_submodel(execute)
@classmethod
def _sql_update(cls, execute, version):
......
......@@ -33,13 +33,11 @@ class Reach(SQLSubModel):
@classmethod
def _sql_create(cls, execute):
cls._create_submodel(execute)
return True
return cls._create_submodel(execute)
@classmethod
def _sql_update(cls, execute, version):
cls._update_submodel(execute, version)
return None
return cls._update_submodel(execute, version)
@classmethod
def _sql_load(cls, execute, data = None):
......
......@@ -183,7 +183,7 @@ class River(Graph, SQLSubModel):
BoundaryConditionList,
LateralContributionList,
# InitialConditionsDict,
# StricklersList,
StricklersList,
# SolverParametersList,
]
......@@ -236,6 +236,10 @@ class River(Graph, SQLSubModel):
execute,
data
)
new._stricklers = StricklersList._sql_load(
execute,
data
)
return new
......@@ -243,6 +247,7 @@ class River(Graph, SQLSubModel):
objs = (self._nodes + self._edges)
objs.append(self._boundary_condition)
objs.append(self._lateral_contribution)
objs.append(self._stricklers)
self._save_submodel(execute, objs, data)
return True
......
......@@ -2,17 +2,83 @@
from tools import trace, timer
class Stricklers(object):
def __init__(self, status = None):
from Model.DB import SQLSubModel
class Stricklers(SQLSubModel):
def __init__(self, name:str = "",
comment:str = "",
minor:float = 35.0,
medium:float = 15.0,
status = None):
super(Stricklers, self).__init__()
self._status = status
self._name = ""
self._comment = ""
self._name = name
self._comment = comment
self._minor = minor
self._medium = medium
@classmethod
def _sql_create(cls, execute):
execute("""
CREATE TABLE stricklers(
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
name TEXT,
comment TEXT,
minor REAL NOT NULL,
medium REAL NOT NULL
)
""")
return cls._create_submodel(execute)
@classmethod
def _sql_update(cls, execute, version):
return cls._update_submodel(execute, version)
@classmethod
def _sql_load(cls, execute, data = None):
stricklers = []
status = data["status"]
table = execute(
"SELECT name, comment, minor, medium " +
"FROM stricklers"
)
for row in table:
name = row[0]
comment = row[1]
minor = row[2]
medium = row[3]
new = cls(
name = name,
comment = comment,
minor = minor, medium = medium,
status = status
)
stricklers.append(new)
return stricklers
def _sql_save(self, execute, data = None):
sql = (
"INSERT INTO " +
"stricklers(name, comment, minor, medium) "+
"VALUES (" +
f"'{self._sql_format(self.name)}', " +
f"'{self._sql_format(self.comment)}', " +
f"{float(self.minor)}, {float(self.medium)}" +
")"
)
execute(sql)
self._minor = 35
self._medium = 15
return True
def __str__(self):
if self._name != "":
......
......@@ -2,10 +2,15 @@
from tools import trace, timer
from Model.DB import SQLSubModel
from Model.Saved import SavedStatus
from Model.Stricklers.Stricklers import Stricklers
class StricklersList(object):
class StricklersList(SQLSubModel):
_sub_classes = [
Stricklers,
]
def __init__(self, status = None):
if status is None:
status = SavedStatus()
......@@ -13,6 +18,32 @@ class StricklersList(object):
self._stricks = []
@classmethod
def _sql_create(cls, execute):
return cls._create_submodel(execute)
@classmethod
def _sql_update(cls, execute, version):
return cls._update_submodel(execute, version)
@classmethod
def _sql_load(cls, execute, data = None):
new = cls(status = data["status"])
new._stricks = Stricklers._sql_load(
execute,
data = data
)
return new
def _sql_save(self, execute, data = None):
if len(self._stricks) != 0:
execute("DELETE FROM stricklers")
objs = self._stricks
return self._save_submodel(execute, objs, data)
def __len__(self):
return len(self._stricks)
......
......@@ -233,7 +233,7 @@ class SQL(object):
@timer
def execute(self, cmd, fetch_one = True, commit = False):
#print(f"[SQL] {cmd}")
print(f"[SQL] {cmd}")
res = self._cur.execute(cmd)
if commit:
......
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