mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
pep8: Some modifications to respect pep8 standard code.
This commit is contained in:
1 parent
8544dd1144
commit
fa2454d079
152 files changed
+1626
-1277
No files matched your search
@@ -25,12 +25,13 @@ from Model.Except import NotImplementedMethodeError
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class BoundaryCondition(SQLSubModel):
|
||||
_sub_classes = []
|
||||
_id_cnt = 0
|
||||
|
||||
def __init__(self, id:int = -1, name:str = "",
|
||||
status = None):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None):
|
||||
super(BoundaryCondition, self).__init__()
|
||||
|
||||
self._status = status
|
||||
@@ -101,7 +102,7 @@ class BoundaryCondition(SQLSubModel):
|
||||
return res
|
||||
|
||||
@classmethod
|
||||
def _sql_load(cls, execute, data = None):
|
||||
def _sql_load(cls, execute, data=None):
|
||||
new = []
|
||||
tab = data["tab"]
|
||||
|
||||
@@ -115,9 +116,9 @@ class BoundaryCondition(SQLSubModel):
|
||||
t = row[2]
|
||||
ctor = cls._get_ctor_from_type(t)
|
||||
bc = ctor(
|
||||
id = row[0],
|
||||
name = row[1],
|
||||
status = data['status']
|
||||
id=row[0],
|
||||
name=row[1],
|
||||
status=data['status']
|
||||
)
|
||||
|
||||
bc.node = None
|
||||
@@ -143,7 +144,7 @@ class BoundaryCondition(SQLSubModel):
|
||||
|
||||
return new
|
||||
|
||||
def _sql_save(self, execute, data = None):
|
||||
def _sql_save(self, execute, data=None):
|
||||
tab = data["tab"]
|
||||
|
||||
execute(f"DELETE FROM boundary_condition WHERE id = {self.id}")
|
||||
@@ -155,7 +156,7 @@ class BoundaryCondition(SQLSubModel):
|
||||
|
||||
sql = (
|
||||
"INSERT INTO " +
|
||||
"boundary_condition(id, name, type, tab, node) "+
|
||||
"boundary_condition(id, name, type, tab, node) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, '{self._sql_format(self._name)}', " +
|
||||
f"'{self._sql_format(self._type)}', '{tab}', {node}" +
|
||||
@@ -170,7 +171,7 @@ class BoundaryCondition(SQLSubModel):
|
||||
|
||||
sql = (
|
||||
"INSERT INTO " +
|
||||
"boundary_condition_data(ind, data0, data1, bc) "+
|
||||
"boundary_condition_data(ind, data0, data1, bc) " +
|
||||
f"VALUES ({ind}, '{data0}', {data1}, {self.id})"
|
||||
)
|
||||
execute(sql)
|
||||
@@ -246,7 +247,7 @@ class BoundaryCondition(SQLSubModel):
|
||||
new_1 = self._default_1
|
||||
|
||||
if len(header) != 0:
|
||||
for i in [0,1]:
|
||||
for i in [0, 1]:
|
||||
for j in range(len(header)):
|
||||
if self._header[i] == header[j]:
|
||||
if i == 0:
|
||||
@@ -259,13 +260,13 @@ class BoundaryCondition(SQLSubModel):
|
||||
|
||||
return (new_0, new_1)
|
||||
|
||||
def add(self, index:int):
|
||||
def add(self, index: int):
|
||||
value = (self._default_0, self._default_1)
|
||||
self._data.insert(index, value)
|
||||
self._status.modified()
|
||||
return value
|
||||
|
||||
def insert(self, index:int, value):
|
||||
def insert(self, index: int, value):
|
||||
self._data.insert(index, value)
|
||||
self._status.modified()
|
||||
|
||||
@@ -306,29 +307,28 @@ class BoundaryCondition(SQLSubModel):
|
||||
l.append(r)
|
||||
return l
|
||||
|
||||
|
||||
def _set_i_c_v(self, index, column, value):
|
||||
v = list(self._data[index])
|
||||
v[column] = self._types[column](value)
|
||||
self._data[index] = tuple(v)
|
||||
self._status.modified()
|
||||
|
||||
def set_i_0(self, index:int, value):
|
||||
def set_i_0(self, index: int, value):
|
||||
self._set_i_c_v(index, 0, value)
|
||||
|
||||
def set_i_1(self, index:int, value):
|
||||
def set_i_1(self, index: int, value):
|
||||
self._set_i_c_v(index, 1, value)
|
||||
|
||||
@timer
|
||||
def convert(self, cls):
|
||||
new = cls(name = self.name, status = self._status)
|
||||
new = cls(name=self.name, status=self._status)
|
||||
new.node = self.node
|
||||
|
||||
for i, _ in enumerate(self.data):
|
||||
new.add(i)
|
||||
|
||||
for i in [0,1]:
|
||||
for j in [0,1]:
|
||||
for i in [0, 1]:
|
||||
for j in [0, 1]:
|
||||
if self._header[i] == new.header[j]:
|
||||
for ind, v in self.data:
|
||||
try:
|
||||
|
||||
@@ -30,6 +30,7 @@ from Model.BoundaryCondition.BoundaryConditionTypes import (
|
||||
Solid,
|
||||
)
|
||||
|
||||
|
||||
class BoundaryConditionList(PamhyrModelListWithTab):
|
||||
_tabs_list = ["liquid", "solid", "suspenssion"]
|
||||
_sub_classes = [
|
||||
@@ -37,8 +38,8 @@ class BoundaryConditionList(PamhyrModelListWithTab):
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def _sql_load(cls, execute, data = None):
|
||||
new = cls(status = data['status'])
|
||||
def _sql_load(cls, execute, data=None):
|
||||
new = cls(status=data['status'])
|
||||
|
||||
if data is None:
|
||||
data = {}
|
||||
@@ -51,7 +52,7 @@ class BoundaryConditionList(PamhyrModelListWithTab):
|
||||
|
||||
return new
|
||||
|
||||
def _sql_save(self, execute, data = None):
|
||||
def _sql_save(self, execute, data=None):
|
||||
execute("DELETE FROM boundary_condition")
|
||||
|
||||
if data is None:
|
||||
@@ -60,7 +61,7 @@ class BoundaryConditionList(PamhyrModelListWithTab):
|
||||
for tab in self._tabs:
|
||||
data["tab"] = tab
|
||||
for bc in self._tabs[tab]:
|
||||
bc._sql_save(execute, data = data)
|
||||
bc._sql_save(execute, data=data)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ from Model.BoundaryCondition.BoundaryCondition import BoundaryCondition
|
||||
|
||||
|
||||
class NotDefined(BoundaryCondition):
|
||||
def __init__(self, id:int = -1, name:str = "", status = None):
|
||||
def __init__(self, id: int = -1, name: str = "", status=None):
|
||||
super(NotDefined, self).__init__(id=id, name=name, status=status)
|
||||
|
||||
self._type = "ND"
|
||||
@@ -32,9 +32,11 @@ class NotDefined(BoundaryCondition):
|
||||
def _default_0(self):
|
||||
return 0.0
|
||||
|
||||
|
||||
class PonctualContribution(BoundaryCondition):
|
||||
def __init__(self, id:int = -1, name:str = "", status = None):
|
||||
super(PonctualContribution, self).__init__(id=id, name=name, status=status)
|
||||
def __init__(self, id: int = -1, name: str = "", status=None):
|
||||
super(PonctualContribution, self).__init__(
|
||||
id=id, name=name, status=status)
|
||||
|
||||
self._type = "PC"
|
||||
self._header = ["time", "discharge"]
|
||||
@@ -44,8 +46,9 @@ class PonctualContribution(BoundaryCondition):
|
||||
def compatibility(cls):
|
||||
return ["liquid"]
|
||||
|
||||
|
||||
class TimeOverZ(BoundaryCondition):
|
||||
def __init__(self, id:int = -1, name:str = "", status = None):
|
||||
def __init__(self, id: int = -1, name: str = "", status=None):
|
||||
super(TimeOverZ, self).__init__(id=id, name=name, status=status)
|
||||
|
||||
self._type = "TZ"
|
||||
@@ -56,9 +59,11 @@ class TimeOverZ(BoundaryCondition):
|
||||
def compatibility(cls):
|
||||
return ["liquid"]
|
||||
|
||||
|
||||
class TimeOverDischarge(BoundaryCondition):
|
||||
def __init__(self, id:int = -1, name:str = "", status = None):
|
||||
super(TimeOverDischarge, self).__init__(id=id, name=name, status=status)
|
||||
def __init__(self, id: int = -1, name: str = "", status=None):
|
||||
super(TimeOverDischarge, self).__init__(
|
||||
id=id, name=name, status=status)
|
||||
|
||||
self._type = "TD"
|
||||
self._header = ["time", "discharge"]
|
||||
@@ -68,8 +73,9 @@ class TimeOverDischarge(BoundaryCondition):
|
||||
def compatibility(cls):
|
||||
return ["liquid"]
|
||||
|
||||
|
||||
class ZOverDischarge(BoundaryCondition):
|
||||
def __init__(self, id:int = -1, name:str = "", status = None):
|
||||
def __init__(self, id: int = -1, name: str = "", status=None):
|
||||
super(ZOverDischarge, self).__init__(id=id, name=name, status=status)
|
||||
|
||||
self._type = "ZD"
|
||||
@@ -86,7 +92,7 @@ class ZOverDischarge(BoundaryCondition):
|
||||
|
||||
|
||||
class Solid(BoundaryCondition):
|
||||
def __init__(self, id:int = -1, name:str = "", status = None):
|
||||
def __init__(self, id: int = -1, name: str = "", status=None):
|
||||
super(Solid, self).__init__(id=id, name=name, status=status)
|
||||
|
||||
self.d50 = 0.002
|
||||
|
||||
+6
-4
@@ -45,8 +45,9 @@ def exception_message_box(exception):
|
||||
# Custom error #
|
||||
################
|
||||
|
||||
|
||||
class ExeceptionWithMessageBox(Exception):
|
||||
def __init__(self, title = "Exeception"):
|
||||
def __init__(self, title="Exeception"):
|
||||
self.title = title
|
||||
|
||||
def header(self):
|
||||
@@ -72,7 +73,7 @@ class ExeceptionWithMessageBox(Exception):
|
||||
class NotImplementedMethodeError(ExeceptionWithMessageBox):
|
||||
def __init__(self, obj, func):
|
||||
super(NotImplementedMethodeError, self).__init__(
|
||||
title = _translate("Exception", "Method not implemented")
|
||||
title=_translate("Exception", "Method not implemented")
|
||||
)
|
||||
|
||||
self.obj = obj
|
||||
@@ -104,10 +105,11 @@ class NotImplementedMethodeError(ExeceptionWithMessageBox):
|
||||
f" '{self.obj.__class__}'"
|
||||
)
|
||||
|
||||
|
||||
class FileFormatError(ExeceptionWithMessageBox):
|
||||
def __init__(self, filename, reason):
|
||||
super(FileFormatError, self).__init__(
|
||||
title = _translate("Exception", "FileFormatError")
|
||||
title=_translate("Exception", "FileFormatError")
|
||||
)
|
||||
|
||||
self.reason = reason
|
||||
@@ -137,7 +139,7 @@ class FileFormatError(ExeceptionWithMessageBox):
|
||||
class ClipboardFormatError(ExeceptionWithMessageBox):
|
||||
def __init__(self, mime=None, header=None, data=None):
|
||||
super(ClipboardFormatError, self).__init__(
|
||||
title = _translate("Exception", "Clipboard format error")
|
||||
title=_translate("Exception", "Clipboard format error")
|
||||
)
|
||||
|
||||
self._mime = mime
|
||||
|
||||
@@ -20,8 +20,9 @@ from tools import trace, timer
|
||||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
|
||||
|
||||
class Friction(SQLSubModel):
|
||||
def __init__(self, name:str = "", status = None):
|
||||
def __init__(self, name: str = "", status=None):
|
||||
super(Friction, self).__init__()
|
||||
|
||||
self._status = status
|
||||
@@ -57,7 +58,7 @@ class Friction(SQLSubModel):
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _sql_load(cls, execute, data = None):
|
||||
def _sql_load(cls, execute, data=None):
|
||||
new = []
|
||||
reach = data["parent"] # Reach object
|
||||
status = data["status"]
|
||||
@@ -78,7 +79,7 @@ class Friction(SQLSubModel):
|
||||
es = next(filter(lambda s: s.id == row[4], stricklers))
|
||||
|
||||
# Create friction
|
||||
sec = cls(status = status)
|
||||
sec = cls(status=status)
|
||||
sec.edge = reach
|
||||
sec.begin_kp = row[1]
|
||||
sec.end_kp = row[2]
|
||||
@@ -87,7 +88,7 @@ class Friction(SQLSubModel):
|
||||
|
||||
yield ind, sec
|
||||
|
||||
def _sql_save(self, execute, data = None):
|
||||
def _sql_save(self, execute, data=None):
|
||||
ind = data["ind"]
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
@@ -119,7 +120,7 @@ class Friction(SQLSubModel):
|
||||
self._edge = edge
|
||||
if (edge is not None and
|
||||
self._begin_kp == 0.0 and
|
||||
self._end_kp == 0.0):
|
||||
self._end_kp == 0.0):
|
||||
self._begin_kp = self._edge.reach.get_kp_min()
|
||||
self._end_kp = self._edge.reach.get_kp_max()
|
||||
self._status.modified()
|
||||
|
||||
@@ -28,6 +28,7 @@ from Model.Friction.Friction import Friction
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class FrictionList(PamhyrModelList):
|
||||
_sub_classes = [
|
||||
Friction
|
||||
@@ -46,8 +47,8 @@ class FrictionList(PamhyrModelList):
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _sql_load(cls, execute, data = None):
|
||||
new = cls(status = data['status'])
|
||||
def _sql_load(cls, execute, data=None):
|
||||
new = cls(status=data['status'])
|
||||
|
||||
new._lst = Friction._sql_load(
|
||||
execute, data
|
||||
@@ -55,7 +56,7 @@ class FrictionList(PamhyrModelList):
|
||||
|
||||
return new
|
||||
|
||||
def _sql_save(self, execute, data = None):
|
||||
def _sql_save(self, execute, data=None):
|
||||
reach = data["reach"]
|
||||
execute(f"DELETE FROM friction WHERE reach = {reach.id}")
|
||||
|
||||
@@ -63,7 +64,7 @@ class FrictionList(PamhyrModelList):
|
||||
ind = 0
|
||||
for friction in self._lst:
|
||||
data["ind"] = ind
|
||||
ok &= friction._sql_save(execute, data = data)
|
||||
ok &= friction._sql_save(execute, data=data)
|
||||
ind += 1
|
||||
|
||||
return ok
|
||||
@@ -76,7 +77,7 @@ class FrictionList(PamhyrModelList):
|
||||
lambda p: p[1],
|
||||
sorted(
|
||||
self._lst,
|
||||
key = lambda p: p[0]
|
||||
key=lambda p: p[0]
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -93,7 +94,7 @@ class FrictionList(PamhyrModelList):
|
||||
return self.lst
|
||||
|
||||
def new(self, index):
|
||||
n = Friction(status = self._status)
|
||||
n = Friction(status=self._status)
|
||||
self._lst.insert(index, n)
|
||||
self._status.modified()
|
||||
return n
|
||||
@@ -18,8 +18,9 @@
|
||||
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
|
||||
|
||||
class Point(object):
|
||||
def __init__(self, name:str = "", profile=None, status = None):
|
||||
def __init__(self, name: str = "", profile=None, status=None):
|
||||
super(Point, self).__init__()
|
||||
|
||||
self._status = status
|
||||
@@ -28,7 +29,6 @@ class Point(object):
|
||||
self._profile = profile
|
||||
self._sl = None
|
||||
|
||||
|
||||
@property
|
||||
def sl(self):
|
||||
if self._sl is None:
|
||||
|
||||
@@ -20,10 +20,11 @@ from math import dist
|
||||
|
||||
from Model.Geometry.Point import Point
|
||||
|
||||
|
||||
class PointAC(Point):
|
||||
def __init__(self, a:float = 0.0, c:float = 0.0,
|
||||
name: str = "", status = None):
|
||||
super(PointXY, self).__init__(name = name, status = status)
|
||||
def __init__(self, a: float = 0.0, c: float = 0.0,
|
||||
name: str = "", status=None):
|
||||
super(PointXY, self).__init__(name=name, status=status)
|
||||
|
||||
self._a = float(a)
|
||||
self._c = float(c)
|
||||
|
||||
@@ -22,12 +22,14 @@ import numpy as np
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
from Model.Geometry.Point import Point
|
||||
|
||||
|
||||
class PointXYZ(Point, SQLSubModel):
|
||||
_sub_classes = []
|
||||
|
||||
def __init__(self, x:float = 0.0, y:float = 0.0, z:float = 0.0,
|
||||
name:str = "", profile = None, status = None):
|
||||
super(PointXYZ, self).__init__(name=name, profile=profile, status=status)
|
||||
def __init__(self, x: float = 0.0, y: float = 0.0, z: float = 0.0,
|
||||
name: str = "", profile=None, status=None):
|
||||
super(PointXYZ, self).__init__(
|
||||
name=name, profile=profile, status=status)
|
||||
|
||||
self._x = float(x)
|
||||
self._y = float(y)
|
||||
@@ -69,7 +71,7 @@ class PointXYZ(Point, SQLSubModel):
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _sql_load(cls, execute, data = None):
|
||||
def _sql_load(cls, execute, data=None):
|
||||
status = data["status"]
|
||||
profile = data["profile"]
|
||||
|
||||
@@ -89,10 +91,10 @@ class PointXYZ(Point, SQLSubModel):
|
||||
sl = row[5]
|
||||
|
||||
new = cls(
|
||||
name = name,
|
||||
x = x, y = y, z = z,
|
||||
profile = profile,
|
||||
status = status
|
||||
name=name,
|
||||
x=x, y=y, z=z,
|
||||
profile=profile,
|
||||
status=status
|
||||
)
|
||||
|
||||
if sl == -1 or sl == None:
|
||||
@@ -107,7 +109,7 @@ class PointXYZ(Point, SQLSubModel):
|
||||
|
||||
yield ind, new
|
||||
|
||||
def _sql_save(self, execute, data = None):
|
||||
def _sql_save(self, execute, data=None):
|
||||
profile = data["profile"]
|
||||
ind = data["ind"]
|
||||
|
||||
@@ -115,7 +117,7 @@ class PointXYZ(Point, SQLSubModel):
|
||||
|
||||
sql = (
|
||||
"INSERT OR REPLACE INTO " +
|
||||
"geometry_pointXYZ(ind, name, x, y, z, profile, sl) "+
|
||||
"geometry_pointXYZ(ind, name, x, y, z, profile, sl) " +
|
||||
"VALUES (" +
|
||||
f"{ind}, '{self._sql_format(self._name)}', " +
|
||||
f"{self.x}, {self.y}, {self.z}, " +
|
||||
@@ -126,7 +128,6 @@ class PointXYZ(Point, SQLSubModel):
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@classmethod
|
||||
def from_data(cls, header, data):
|
||||
point = None
|
||||
@@ -149,7 +150,6 @@ class PointXYZ(Point, SQLSubModel):
|
||||
|
||||
return point
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
return f"({self._x}, {self._y}, {self._z}, {self._name})"
|
||||
|
||||
|
||||
@@ -25,14 +25,15 @@ from Model.Except import NotImplementedMethodeError
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class Profile(object):
|
||||
_id_cnt = 0
|
||||
|
||||
def __init__(self, id:int = -1, num:int = 0,
|
||||
kp:float = 0.0, name:str = "",
|
||||
code1:int = 0, code2:int = 0,
|
||||
_type:str = "", reach = None,
|
||||
status = None):
|
||||
def __init__(self, id: int = -1, num: int = 0,
|
||||
kp: float = 0.0, name: str = "",
|
||||
code1: int = 0, code2: int = 0,
|
||||
_type: str = "", reach=None,
|
||||
status=None):
|
||||
super(Profile, self).__init__()
|
||||
|
||||
self._status = status
|
||||
@@ -71,7 +72,7 @@ class Profile(object):
|
||||
lambda p: p[1],
|
||||
sorted(
|
||||
self._points,
|
||||
key = lambda p: p[0]
|
||||
key=lambda p: p[0]
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -185,7 +186,7 @@ class Profile(object):
|
||||
self._profile_type = value
|
||||
self._status.modified()
|
||||
|
||||
def point(self, i:int):
|
||||
def point(self, i: int):
|
||||
if i < len(self.points):
|
||||
return self.points[i]
|
||||
|
||||
@@ -200,8 +201,7 @@ class Profile(object):
|
||||
return [point for point in self.points
|
||||
if point.point_is_named()]
|
||||
|
||||
|
||||
def insert_point(self, index: int, point:Point):
|
||||
def insert_point(self, index: int, point: Point):
|
||||
"""Insert point at index.
|
||||
|
||||
Args:
|
||||
@@ -214,7 +214,6 @@ class Profile(object):
|
||||
self.points.insert(index, point)
|
||||
self._status.modified()
|
||||
|
||||
|
||||
def delete(self, indexes: int):
|
||||
"""Delete points at index
|
||||
|
||||
@@ -281,11 +280,11 @@ class Profile(object):
|
||||
|
||||
@timer
|
||||
def sort(self, column, is_reversed: bool = False):
|
||||
predicate = lambda p: p.x
|
||||
def predicate(p): return p.x
|
||||
if column == 'y':
|
||||
predicate = lambda p: p.y
|
||||
def predicate(p): return p.y
|
||||
elif column == 'z':
|
||||
predicate = lambda p: p.z
|
||||
def predicate(p): return p.z
|
||||
|
||||
self.points = sorted(
|
||||
self.points,
|
||||
|
||||
@@ -30,6 +30,7 @@ from Model.Geometry.Vector_1d import Vector1d
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class ProfileXYZ(Profile, SQLSubModel):
|
||||
_sub_classes = [
|
||||
PointXYZ,
|
||||
@@ -39,11 +40,11 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
id: int = -1,
|
||||
name: str = "",
|
||||
kp: float = 0.,
|
||||
reach = None,
|
||||
num = 0,
|
||||
reach=None,
|
||||
num=0,
|
||||
nb_point: int = 0,
|
||||
code1: int = 0, code2: int = 0,
|
||||
status = None):
|
||||
status=None):
|
||||
"""ProfileXYZ constructor
|
||||
|
||||
Args:
|
||||
@@ -57,14 +58,14 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
Nothing.
|
||||
"""
|
||||
super(ProfileXYZ, self).__init__(
|
||||
id = id,
|
||||
num = num,
|
||||
name = name,
|
||||
kp = kp,
|
||||
code1 = code1, code2 = code2,
|
||||
_type = "XYZ",
|
||||
reach = reach,
|
||||
status = status,
|
||||
id=id,
|
||||
num=num,
|
||||
name=name,
|
||||
kp=kp,
|
||||
code1=code1, code2=code2,
|
||||
_type="XYZ",
|
||||
reach=reach,
|
||||
status=status,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@@ -103,7 +104,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
return cls._update_submodel(execute, version)
|
||||
|
||||
@classmethod
|
||||
def _sql_load(cls, execute, data = None):
|
||||
def _sql_load(cls, execute, data=None):
|
||||
profiles = []
|
||||
status = data["status"]
|
||||
reach = data["reach"]
|
||||
@@ -128,11 +129,11 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
sl = row[7]
|
||||
|
||||
new = cls(
|
||||
id=id, num = num,
|
||||
name = name, kp = kp,
|
||||
code1 = code1, code2 = code2,
|
||||
reach = data["parent"],
|
||||
status = status
|
||||
id=id, num=num,
|
||||
name=name, kp=kp,
|
||||
code1=code1, code2=code2,
|
||||
reach=data["parent"],
|
||||
status=status
|
||||
)
|
||||
|
||||
if sl == -1 or sl == None:
|
||||
@@ -154,7 +155,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
|
||||
# return profiles
|
||||
|
||||
def _sql_save(self, execute, data = None):
|
||||
def _sql_save(self, execute, data=None):
|
||||
ok = True
|
||||
ind = data["ind"]
|
||||
|
||||
@@ -162,7 +163,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
|
||||
sql = (
|
||||
"INSERT OR REPLACE INTO " +
|
||||
"geometry_profileXYZ(id, ind, name, reach, kp, num, code1, code2, sl) "+
|
||||
"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}, " +
|
||||
@@ -225,7 +226,6 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
|
||||
return point
|
||||
|
||||
|
||||
def x(self):
|
||||
return [point.x for point in self.points]
|
||||
|
||||
@@ -374,9 +374,9 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
constant = 0.0
|
||||
|
||||
if (first_named_point is not None and
|
||||
last_named_point is not None):
|
||||
last_named_point is not None):
|
||||
if (first_named_point != last_named_point and
|
||||
first_named_point.x != last_named_point.x):
|
||||
first_named_point.x != last_named_point.x):
|
||||
vector = Vector1d(first_named_point, last_named_point)
|
||||
normalized_direction_vec = vector.normalized_direction_vector()
|
||||
else:
|
||||
|
||||
@@ -36,6 +36,7 @@ from Model.Except import FileFormatError, exception_message_box
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class Reach(SQLSubModel):
|
||||
_sub_classes = [
|
||||
ProfileXYZ,
|
||||
@@ -59,17 +60,17 @@ class Reach(SQLSubModel):
|
||||
return cls._update_submodel(execute, version)
|
||||
|
||||
@classmethod
|
||||
def _sql_load(cls, execute, data = None):
|
||||
new = cls(status = data["status"], parent = data["parent"])
|
||||
def _sql_load(cls, execute, data=None):
|
||||
new = cls(status=data["status"], parent=data["parent"])
|
||||
|
||||
new._profiles = ProfileXYZ._sql_load(
|
||||
execute,
|
||||
data = data
|
||||
data=data
|
||||
)
|
||||
|
||||
return new
|
||||
|
||||
def _sql_save(self, execute, data = None):
|
||||
def _sql_save(self, execute, data=None):
|
||||
# Delete old data
|
||||
execute(f"DELETE FROM geometry_profileXYZ WHERE reach = {self.id}")
|
||||
# execute(f"DELETE FROM geometry_pointXYZ")
|
||||
@@ -115,7 +116,7 @@ class Reach(SQLSubModel):
|
||||
lambda p: p[1],
|
||||
sorted(
|
||||
self._profiles,
|
||||
key = lambda p: p[0]
|
||||
key=lambda p: p[0]
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -195,7 +196,6 @@ class Reach(SQLSubModel):
|
||||
self._update_profile_numbers()
|
||||
self._status.modified()
|
||||
|
||||
|
||||
def delete(self, indexes):
|
||||
"""Delete some elements in profile list
|
||||
|
||||
@@ -242,7 +242,6 @@ class Reach(SQLSubModel):
|
||||
self._update_profile_numbers()
|
||||
self._status.modified()
|
||||
|
||||
|
||||
def move_up_profile(self, index: int):
|
||||
if index < len(self.profiles):
|
||||
next = index - 1
|
||||
@@ -298,7 +297,6 @@ class Reach(SQLSubModel):
|
||||
def get_kp_max(self):
|
||||
return max(self.get_kp())
|
||||
|
||||
|
||||
# Sediment Layers
|
||||
|
||||
def get_sl(self):
|
||||
@@ -437,7 +435,6 @@ class Reach(SQLSubModel):
|
||||
def get_guidelines_z(self):
|
||||
return self._map_guidelines_points(lambda p: p.z)
|
||||
|
||||
|
||||
# Sort
|
||||
|
||||
@timer
|
||||
@@ -482,7 +479,8 @@ class Reach(SQLSubModel):
|
||||
|
||||
try:
|
||||
list_profile, list_header = self.read_file_st(str(file_path_name))
|
||||
profile_header = ["num", "code1", "code2", "nb_point", "kp", "name"]
|
||||
profile_header = ["num", "code1",
|
||||
"code2", "nb_point", "kp", "name"]
|
||||
|
||||
if list_profile and list_header:
|
||||
for ind, profile in enumerate(list_profile):
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
import numpy as np
|
||||
from Model.Geometry.PointXYZ import PointXYZ
|
||||
|
||||
|
||||
class Vector1d:
|
||||
def __init__(self, a: PointXYZ, b: PointXYZ):
|
||||
self.A = a
|
||||
|
||||
@@ -22,12 +22,13 @@ from functools import reduce
|
||||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
|
||||
|
||||
class Data(SQLSubModel):
|
||||
def __init__(self, name:str = "",
|
||||
comment:str = "", reach = None,
|
||||
kp:float = 0.0, discharge:float = 0.0,
|
||||
height:float = 0.0,
|
||||
status = None):
|
||||
def __init__(self, name: str = "",
|
||||
comment: str = "", reach=None,
|
||||
kp: float = 0.0, discharge: float = 0.0,
|
||||
height: float = 0.0,
|
||||
status=None):
|
||||
super(Data, self).__init__()
|
||||
|
||||
self._status = status
|
||||
@@ -73,7 +74,7 @@ class Data(SQLSubModel):
|
||||
return cls._update_submodel(execute, version)
|
||||
|
||||
@classmethod
|
||||
def _sql_load(cls, execute, data = None):
|
||||
def _sql_load(cls, execute, data=None):
|
||||
id = data["reach"].id
|
||||
table = execute(
|
||||
"SELECT ind, name, comment, kp, discharge, height " +
|
||||
@@ -95,20 +96,20 @@ class Data(SQLSubModel):
|
||||
height = row[5]
|
||||
|
||||
d = cls(
|
||||
reach = data["reach"],
|
||||
status = data["status"],
|
||||
name = name,
|
||||
comment = comment,
|
||||
kp = kp,
|
||||
discharge = discharge,
|
||||
height = height,
|
||||
reach=data["reach"],
|
||||
status=data["status"],
|
||||
name=name,
|
||||
comment=comment,
|
||||
kp=kp,
|
||||
discharge=discharge,
|
||||
height=height,
|
||||
)
|
||||
|
||||
new[ind] = d
|
||||
|
||||
return new
|
||||
|
||||
def _sql_save(self, execute, data = None):
|
||||
def _sql_save(self, execute, data=None):
|
||||
ind = data["ind"]
|
||||
|
||||
execute(
|
||||
@@ -124,16 +125,15 @@ class Data(SQLSubModel):
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def copy(self):
|
||||
new = Data(
|
||||
name = self.name,
|
||||
comment = self._comment,
|
||||
kp = self._kp,
|
||||
discharge = self._discharge,
|
||||
height = self._height,
|
||||
reach = self._reach,
|
||||
status = self._status,
|
||||
name=self.name,
|
||||
comment=self._comment,
|
||||
kp=self._kp,
|
||||
discharge=self._discharge,
|
||||
height=self._height,
|
||||
reach=self._reach,
|
||||
status=self._status,
|
||||
)
|
||||
|
||||
return new
|
||||
@@ -216,7 +216,7 @@ class InitialConditions(SQLSubModel):
|
||||
Data
|
||||
]
|
||||
|
||||
def __init__(self, reach = None, status = None):
|
||||
def __init__(self, reach=None, status=None):
|
||||
super(InitialConditions, self).__init__()
|
||||
|
||||
self._status = status
|
||||
@@ -233,21 +233,21 @@ class InitialConditions(SQLSubModel):
|
||||
return cls._update_submodel(execute, version)
|
||||
|
||||
@classmethod
|
||||
def _sql_load(cls, execute, data = None):
|
||||
def _sql_load(cls, execute, data=None):
|
||||
new = cls(
|
||||
reach = data["reach"],
|
||||
status = data["status"]
|
||||
reach=data["reach"],
|
||||
status=data["status"]
|
||||
)
|
||||
|
||||
new._data = Data._sql_load(
|
||||
execute,
|
||||
data = data
|
||||
data=data
|
||||
)
|
||||
|
||||
if new._data is not None:
|
||||
yield new
|
||||
|
||||
def _sql_save(self, execute, data = None):
|
||||
def _sql_save(self, execute, data=None):
|
||||
ok = True
|
||||
|
||||
ind = 0
|
||||
@@ -286,7 +286,7 @@ class InitialConditions(SQLSubModel):
|
||||
self._status.modified()
|
||||
|
||||
def new(self, index):
|
||||
n = Data(reach = self._reach, status = self._status)
|
||||
n = Data(reach=self._reach, status=self._status)
|
||||
self._data.insert(index, n)
|
||||
self._status.modified()
|
||||
|
||||
@@ -319,7 +319,6 @@ class InitialConditions(SQLSubModel):
|
||||
self._data.sort(reverse=reverse, key=key)
|
||||
self._status.modified()
|
||||
|
||||
|
||||
def _data_get(self, key):
|
||||
return list(
|
||||
map(
|
||||
@@ -339,8 +338,8 @@ class InitialConditions(SQLSubModel):
|
||||
|
||||
def _sort_by_z_and_kp(self, profiles):
|
||||
profiles.sort(
|
||||
reverse = False,
|
||||
key = lambda p: p.kp
|
||||
reverse=False,
|
||||
key=lambda p: p.kp
|
||||
)
|
||||
|
||||
first_z = profiles[0].z()
|
||||
@@ -348,11 +347,11 @@ class InitialConditions(SQLSubModel):
|
||||
|
||||
if first_z > last_z:
|
||||
profiles.sort(
|
||||
reverse = True,
|
||||
key = lambda p: p.kp
|
||||
reverse=True,
|
||||
key=lambda p: p.kp
|
||||
)
|
||||
|
||||
def generate_growing_constante_height(self, height:float):
|
||||
def generate_growing_constante_height(self, height: float):
|
||||
self._data = []
|
||||
|
||||
profiles = self._reach.reach.profiles
|
||||
@@ -360,7 +359,7 @@ class InitialConditions(SQLSubModel):
|
||||
|
||||
prev = None
|
||||
for profile in profiles:
|
||||
new = Data(reach = self._reach, status = self._status)
|
||||
new = Data(reach=self._reach, status=self._status)
|
||||
new["kp"] = profile.kp
|
||||
|
||||
if prev is None:
|
||||
@@ -379,11 +378,11 @@ class InitialConditions(SQLSubModel):
|
||||
is_reverse = True
|
||||
|
||||
self._data.sort(
|
||||
reverse = not is_reverse,
|
||||
key = lambda d: d['kp']
|
||||
reverse=not is_reverse,
|
||||
key=lambda d: d['kp']
|
||||
)
|
||||
|
||||
def generate_discharge(self, discharge:float):
|
||||
def generate_discharge(self, discharge: float):
|
||||
self._new = []
|
||||
|
||||
for d in self._data:
|
||||
|
||||
@@ -23,21 +23,22 @@ from tools import trace, timer
|
||||
from Model.Tools.PamhyrDict import PamhyrModelDict
|
||||
from Model.InitialConditions.InitialConditions import InitialConditions
|
||||
|
||||
|
||||
class InitialConditionsDict(PamhyrModelDict):
|
||||
_sub_classes = [
|
||||
InitialConditions,
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def _sql_load(cls, execute, data = None):
|
||||
new = cls(status = data["status"])
|
||||
def _sql_load(cls, execute, data=None):
|
||||
new = cls(status=data["status"])
|
||||
|
||||
for reach in data["edges"]:
|
||||
data["reach"] = reach
|
||||
|
||||
ic = InitialConditions._sql_load(
|
||||
execute,
|
||||
data = data
|
||||
data=data
|
||||
)
|
||||
|
||||
if ic is not None:
|
||||
@@ -45,7 +46,7 @@ class InitialConditionsDict(PamhyrModelDict):
|
||||
|
||||
return new
|
||||
|
||||
def _sql_save(self, execute, data = None):
|
||||
def _sql_save(self, execute, data=None):
|
||||
ok = True
|
||||
if data is None:
|
||||
data = {}
|
||||
@@ -58,7 +59,6 @@ class InitialConditionsDict(PamhyrModelDict):
|
||||
|
||||
return ok
|
||||
|
||||
|
||||
def get(self, key):
|
||||
if key in self._dict:
|
||||
v = self._dict[key]
|
||||
@@ -72,6 +72,6 @@ class InitialConditionsDict(PamhyrModelDict):
|
||||
return new
|
||||
|
||||
def new(self, reach):
|
||||
new = InitialConditions(reach = reach, status = self._status)
|
||||
new = InitialConditions(reach=reach, status=self._status)
|
||||
self.set(reach, new)
|
||||
return new
|
||||
@@ -25,11 +25,12 @@ from Model.Except import NotImplementedMethodeError
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class LateralContribution(SQLSubModel):
|
||||
_sub_classes = []
|
||||
_id_cnt = 0
|
||||
|
||||
def __init__(self, id:int = -1, name:str = "", status = None):
|
||||
def __init__(self, id: int = -1, name: str = "", status=None):
|
||||
super(LateralContribution, self).__init__()
|
||||
|
||||
self._status = status
|
||||
@@ -39,7 +40,6 @@ class LateralContribution(SQLSubModel):
|
||||
else:
|
||||
self.id = id
|
||||
|
||||
|
||||
self._name = name
|
||||
self._type = ""
|
||||
self._edge = None
|
||||
@@ -49,7 +49,8 @@ class LateralContribution(SQLSubModel):
|
||||
self._header = []
|
||||
self._types = [float, float]
|
||||
|
||||
LateralContribution._id_cnt = max(LateralContribution._id_cnt + 1, self.id)
|
||||
LateralContribution._id_cnt = max(
|
||||
LateralContribution._id_cnt + 1, self.id)
|
||||
|
||||
@classmethod
|
||||
def _sql_create(cls, execute):
|
||||
@@ -99,7 +100,7 @@ class LateralContribution(SQLSubModel):
|
||||
return res
|
||||
|
||||
@classmethod
|
||||
def _sql_load(cls, execute, data = None):
|
||||
def _sql_load(cls, execute, data=None):
|
||||
new = []
|
||||
tab = data["tab"]
|
||||
|
||||
@@ -112,9 +113,9 @@ class LateralContribution(SQLSubModel):
|
||||
t = row[2]
|
||||
ctor = cls._get_ctor_from_type(t)
|
||||
lc = ctor(
|
||||
id = row[0],
|
||||
name = row[1],
|
||||
status = data['status']
|
||||
id=row[0],
|
||||
name=row[1],
|
||||
status=data['status']
|
||||
)
|
||||
lc.edge = None
|
||||
if row[3] != -1:
|
||||
@@ -141,7 +142,7 @@ class LateralContribution(SQLSubModel):
|
||||
|
||||
return new
|
||||
|
||||
def _sql_save(self, execute, data = None):
|
||||
def _sql_save(self, execute, data=None):
|
||||
tab = data["tab"]
|
||||
|
||||
execute(f"DELETE FROM lateral_contribution WHERE id = {self.id}")
|
||||
@@ -153,7 +154,7 @@ class LateralContribution(SQLSubModel):
|
||||
|
||||
sql = (
|
||||
"INSERT INTO " +
|
||||
"lateral_contribution(id, name, type, tab, edge, begin_kp, end_kp) "+
|
||||
"lateral_contribution(id, name, type, tab, edge, begin_kp, end_kp) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, '{self._sql_format(self._name)}', " +
|
||||
f"'{self._sql_format(self._type)}', '{tab}', {edge}, " +
|
||||
@@ -169,7 +170,7 @@ class LateralContribution(SQLSubModel):
|
||||
|
||||
sql = (
|
||||
"INSERT INTO " +
|
||||
"lateral_contribution_data(ind, data0, data1, lc) "+
|
||||
"lateral_contribution_data(ind, data0, data1, lc) " +
|
||||
f"VALUES ({ind}, '{data0}', {data1}, {self.id})"
|
||||
)
|
||||
execute(sql)
|
||||
@@ -282,7 +283,7 @@ class LateralContribution(SQLSubModel):
|
||||
new_1 = self._default_1
|
||||
|
||||
if len(header) != 0:
|
||||
for i in [0,1]:
|
||||
for i in [0, 1]:
|
||||
for j in range(len(header)):
|
||||
if self._header[i] == header[j]:
|
||||
if i == 0:
|
||||
@@ -295,13 +296,13 @@ class LateralContribution(SQLSubModel):
|
||||
|
||||
return (new_0, new_1)
|
||||
|
||||
def add(self, index:int):
|
||||
def add(self, index: int):
|
||||
value = (self._default_0, self._default_1)
|
||||
self._data.insert(index, value)
|
||||
self._status.modified()
|
||||
return value
|
||||
|
||||
def insert(self, index:int, value):
|
||||
def insert(self, index: int, value):
|
||||
self._data.insert(index, value)
|
||||
self._status.modified()
|
||||
|
||||
@@ -342,22 +343,21 @@ class LateralContribution(SQLSubModel):
|
||||
l.append(r)
|
||||
return l
|
||||
|
||||
|
||||
def _set_i_c_v(self, index, column, value):
|
||||
v = list(self._data[index])
|
||||
v[column] = self._types[column](value)
|
||||
self._data[index] = tuple(v)
|
||||
self._status.modified()
|
||||
|
||||
def set_i_0(self, index:int, value):
|
||||
def set_i_0(self, index: int, value):
|
||||
self._set_i_c_v(index, 0, value)
|
||||
|
||||
def set_i_1(self, index:int, value):
|
||||
def set_i_1(self, index: int, value):
|
||||
self._set_i_c_v(index, 1, value)
|
||||
|
||||
@timer
|
||||
def convert(self, cls):
|
||||
new = cls(name = self.name, status = self._status)
|
||||
new = cls(name=self.name, status=self._status)
|
||||
new.edge = self.edge
|
||||
new.begin_kp = self.begin_kp
|
||||
new.end_kp = self.end_kp
|
||||
@@ -365,8 +365,8 @@ class LateralContribution(SQLSubModel):
|
||||
for i, _ in enumerate(self.data):
|
||||
new.add(i)
|
||||
|
||||
for i in [0,1]:
|
||||
for j in [0,1]:
|
||||
for i in [0, 1]:
|
||||
for j in [0, 1]:
|
||||
if self._header[i] == new.header[j]:
|
||||
for ind, v in self.data:
|
||||
try:
|
||||
|
||||
@@ -27,6 +27,7 @@ from Model.LateralContribution.LateralContributionTypes import (
|
||||
NotDefined, LateralContrib, Rain, Evaporation,
|
||||
)
|
||||
|
||||
|
||||
class LateralContributionList(PamhyrModelListWithTab):
|
||||
_tabs_list = ["liquid", "solid", "suspenssion"]
|
||||
_sub_classes = [
|
||||
@@ -34,8 +35,8 @@ class LateralContributionList(PamhyrModelListWithTab):
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def _sql_load(cls, execute, data = None):
|
||||
new = cls(status = data['status'])
|
||||
def _sql_load(cls, execute, data=None):
|
||||
new = cls(status=data['status'])
|
||||
|
||||
if data is None:
|
||||
data = {}
|
||||
@@ -48,7 +49,7 @@ class LateralContributionList(PamhyrModelListWithTab):
|
||||
|
||||
return new
|
||||
|
||||
def _sql_save(self, execute, data = None):
|
||||
def _sql_save(self, execute, data=None):
|
||||
execute("DELETE FROM lateral_contribution")
|
||||
|
||||
if data is None:
|
||||
@@ -57,7 +58,7 @@ class LateralContributionList(PamhyrModelListWithTab):
|
||||
for tab in self._tabs:
|
||||
data["tab"] = tab
|
||||
for lc in self._tabs[tab]:
|
||||
lc._sql_save(execute, data = data)
|
||||
lc._sql_save(execute, data=data)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ from Model.LateralContribution.LateralContribution import LateralContribution
|
||||
|
||||
|
||||
class NotDefined(LateralContribution):
|
||||
def __init__(self, id:int = -1, name:str = "", status=None):
|
||||
def __init__(self, id: int = -1, name: str = "", status=None):
|
||||
super(NotDefined, self).__init__(id=id, name=name, status=status)
|
||||
|
||||
self._type = "ND"
|
||||
@@ -32,8 +32,9 @@ class NotDefined(LateralContribution):
|
||||
def _default_0(self):
|
||||
return 0.0
|
||||
|
||||
|
||||
class LateralContrib(LateralContribution):
|
||||
def __init__(self, id:int = -1, name:str = "", status=None):
|
||||
def __init__(self, id: int = -1, name: str = "", status=None):
|
||||
super(LateralContrib, self).__init__(id=id, name=name, status=status)
|
||||
|
||||
self._type = "LC"
|
||||
@@ -44,8 +45,9 @@ class LateralContrib(LateralContribution):
|
||||
def compatibility(cls):
|
||||
return ["liquid"]
|
||||
|
||||
|
||||
class Rain(LateralContribution):
|
||||
def __init__(self, id:int = -1, name:str = "", status=None):
|
||||
def __init__(self, id: int = -1, name: str = "", status=None):
|
||||
super(Rain, self).__init__(id=id, name=name, status=status)
|
||||
|
||||
self._type = "RA"
|
||||
@@ -56,8 +58,9 @@ class Rain(LateralContribution):
|
||||
def compatibility(cls):
|
||||
return ["liquid"]
|
||||
|
||||
|
||||
class Evaporation(LateralContribution):
|
||||
def __init__(self, id:int = -1, name:str = "", status=None):
|
||||
def __init__(self, id: int = -1, name: str = "", status=None):
|
||||
super(Evaporation, self).__init__(id=id, name=name, status=status)
|
||||
|
||||
self._type = "EV"
|
||||
|
||||
@@ -18,13 +18,14 @@
|
||||
|
||||
from Model.Network.Node import Node
|
||||
|
||||
|
||||
class Edge(object):
|
||||
_id_cnt = 0
|
||||
|
||||
def __init__(self, id:int, name:str,
|
||||
node1:Node = None,
|
||||
node2:Node = None,
|
||||
status = None):
|
||||
def __init__(self, id: int, name: str,
|
||||
node1: Node = None,
|
||||
node2: Node = None,
|
||||
status=None):
|
||||
super(Edge, self).__init__()
|
||||
|
||||
self._status = status
|
||||
|
||||
+15
-15
@@ -21,8 +21,9 @@ from functools import reduce
|
||||
from Model.Network.Node import Node
|
||||
from Model.Network.Edge import Edge
|
||||
|
||||
|
||||
class Graph(object):
|
||||
def __init__(self, status = None):
|
||||
def __init__(self, status=None):
|
||||
super(Graph, self).__init__()
|
||||
|
||||
self._status = status
|
||||
@@ -83,7 +84,7 @@ class Graph(object):
|
||||
False
|
||||
)
|
||||
|
||||
def node(self, node_name:str):
|
||||
def node(self, node_name: str):
|
||||
node = list(
|
||||
filter(
|
||||
lambda n: n.name == node_name,
|
||||
@@ -96,7 +97,7 @@ class Graph(object):
|
||||
|
||||
return node[0]
|
||||
|
||||
def edge(self, edge_name:str):
|
||||
def edge(self, edge_name: str):
|
||||
edge = list(
|
||||
filter(
|
||||
lambda e: e.name == edge_name,
|
||||
@@ -109,12 +110,12 @@ class Graph(object):
|
||||
|
||||
return edge[0]
|
||||
|
||||
def _create_node(self, x:float, y:float):
|
||||
def _create_node(self, x: float, y: float):
|
||||
node = self._node_ctor(
|
||||
-1,
|
||||
"",
|
||||
x = x, y = y,
|
||||
status = self._status
|
||||
x=x, y=y,
|
||||
status=self._status
|
||||
)
|
||||
return node
|
||||
|
||||
@@ -123,14 +124,14 @@ class Graph(object):
|
||||
self._status.modified()
|
||||
return node
|
||||
|
||||
def add_node(self, x:float = 0.0, y:float = 0.0):
|
||||
def add_node(self, x: float = 0.0, y: float = 0.0):
|
||||
node = self._create_node(x, y)
|
||||
return self._add_node(node)
|
||||
|
||||
def insert_node(self, node):
|
||||
return self._add_node(node)
|
||||
|
||||
def remove_node(self, node_name:str):
|
||||
def remove_node(self, node_name: str):
|
||||
self._nodes = list(
|
||||
filter(
|
||||
lambda n: n.name != node_name,
|
||||
@@ -139,19 +140,18 @@ class Graph(object):
|
||||
)
|
||||
self._status.modified()
|
||||
|
||||
def create_node(self, x:float = 0.0, y:float = 0.0):
|
||||
def create_node(self, x: float = 0.0, y: float = 0.0):
|
||||
node = self._create_node(x, y)
|
||||
return node
|
||||
|
||||
def _create_edge(self, n1:Node, n2:Node):
|
||||
def _create_edge(self, n1: Node, n2: Node):
|
||||
edge = self._edge_ctor(
|
||||
-1,
|
||||
"", n1, n2,
|
||||
status = self._status
|
||||
status=self._status
|
||||
)
|
||||
return edge
|
||||
|
||||
|
||||
def _add_edge(self, edge):
|
||||
# This edge already exists ?
|
||||
if any(filter(lambda e: (e.node1 == edge.node1 and
|
||||
@@ -164,17 +164,17 @@ class Graph(object):
|
||||
self._status.modified()
|
||||
return edge
|
||||
|
||||
def add_edge(self, n1:Node, n2:Node):
|
||||
def add_edge(self, n1: Node, n2: Node):
|
||||
edge = self._create_edge(n1, n2)
|
||||
return self._add_edge(edge)
|
||||
|
||||
def insert_edge(self, edge):
|
||||
return self._add_edge(edge)
|
||||
|
||||
def create_edge(self, n1:Node, n2:Node):
|
||||
def create_edge(self, n1: Node, n2: Node):
|
||||
return self._create_edge(n1, n2)
|
||||
|
||||
def remove_edge(self, edge_name:str):
|
||||
def remove_edge(self, edge_name: str):
|
||||
self._edges = list(
|
||||
filter(
|
||||
lambda e: e.name != edge_name,
|
||||
|
||||
@@ -18,12 +18,13 @@
|
||||
|
||||
from Model.Network.Point import Point
|
||||
|
||||
|
||||
class Node(object):
|
||||
_id_cnt = 0
|
||||
|
||||
def __init__(self, id:int, name:str,
|
||||
x:float = 0.0, y:float = 0.0,
|
||||
status = None):
|
||||
def __init__(self, id: int, name: str,
|
||||
x: float = 0.0, y: float = 0.0,
|
||||
status=None):
|
||||
super(Node, self).__init__()
|
||||
|
||||
self._status = status
|
||||
@@ -73,7 +74,6 @@ class Node(object):
|
||||
def y(self):
|
||||
return self.pos.y
|
||||
|
||||
|
||||
def setPos(self, x, y):
|
||||
self.pos.x = x
|
||||
self.pos.y = y
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
class Point(object):
|
||||
def __init__(self, x:float, y:float):
|
||||
def __init__(self, x: float, y: float):
|
||||
super(Point, self).__init__()
|
||||
|
||||
self.x = x
|
||||
|
||||
@@ -24,8 +24,9 @@ from Model.Results.River.River import River
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class Results(object):
|
||||
def __init__(self, study = None):
|
||||
def __init__(self, study=None):
|
||||
self._study = study
|
||||
self._river = River(self._study)
|
||||
|
||||
|
||||
@@ -20,11 +20,12 @@ from datetime import datetime
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class Profile(object):
|
||||
def __init__(self, profile, study):
|
||||
self._study = study
|
||||
self._profile = profile # Source profile in the study
|
||||
self._data = {} # Dict of dict {<ts>: {<key>: <value>, ...}, ...}
|
||||
self._profile = profile # Source profile in the study
|
||||
self._data = {} # Dict of dict {<ts>: {<key>: <value>, ...}, ...}
|
||||
|
||||
def __len__(self):
|
||||
return len(self._data)
|
||||
@@ -58,10 +59,11 @@ class Profile(object):
|
||||
def get_ts_key(self, timestamp, key):
|
||||
return self._data[timestamp][key]
|
||||
|
||||
|
||||
class Reach(object):
|
||||
def __init__(self, reach, study):
|
||||
self._study = study
|
||||
self._reach = reach # Source reach in the study
|
||||
self._reach = reach # Source reach in the study
|
||||
self._profiles = list(
|
||||
map(
|
||||
lambda p: Profile(p, self._study),
|
||||
@@ -90,6 +92,7 @@ class Reach(object):
|
||||
def set(self, profile_id, timestamp, key, data):
|
||||
self._profiles[profile_id].set(timestamp, key, data)
|
||||
|
||||
|
||||
class River(object):
|
||||
def __init__(self, study):
|
||||
self._study = study
|
||||
|
||||
+29
-27
@@ -37,16 +37,17 @@ from Model.SedimentLayer.SedimentLayerList import SedimentLayerList
|
||||
|
||||
from Solver.Solvers import solver_type_list
|
||||
|
||||
|
||||
class RiverNode(Node, SQLSubModel):
|
||||
_sub_classes = []
|
||||
|
||||
def __init__(self, id:str, name:str,
|
||||
x:float, y:float,
|
||||
status = None):
|
||||
def __init__(self, id: str, name: str,
|
||||
x: float, y: float,
|
||||
status=None):
|
||||
super(RiverNode, self).__init__(
|
||||
id, name,
|
||||
x, y,
|
||||
status = status
|
||||
status=status
|
||||
)
|
||||
|
||||
self._locker = None
|
||||
@@ -70,7 +71,7 @@ class RiverNode(Node, SQLSubModel):
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _sql_load(cls, execute, data = None):
|
||||
def _sql_load(cls, execute, data=None):
|
||||
nodes = []
|
||||
|
||||
table = execute("SELECT id, name, x, y FROM river_node")
|
||||
@@ -82,11 +83,11 @@ class RiverNode(Node, SQLSubModel):
|
||||
|
||||
return nodes
|
||||
|
||||
def _sql_save(self, execute, data = None):
|
||||
def _sql_save(self, execute, data=None):
|
||||
sql = (
|
||||
"INSERT OR REPLACE INTO river_node(id, name, x, y) VALUES (" +
|
||||
f"{self.id}, '{self._sql_format(self.name)}', " +
|
||||
f"{self.x}, {self.y}"+
|
||||
f"{self.x}, {self.y}" +
|
||||
")"
|
||||
)
|
||||
execute(sql)
|
||||
@@ -108,18 +109,18 @@ class RiverReach(Edge, SQLSubModel):
|
||||
FrictionList,
|
||||
]
|
||||
|
||||
def __init__(self, id:str, name:str,
|
||||
node1:RiverNode = None,
|
||||
node2:RiverNode = None,
|
||||
status = None):
|
||||
def __init__(self, id: str, name: str,
|
||||
node1: RiverNode = None,
|
||||
node2: RiverNode = None,
|
||||
status=None):
|
||||
super(RiverReach, self).__init__(
|
||||
id, name,
|
||||
node1, node2,
|
||||
status = status
|
||||
status=status
|
||||
)
|
||||
|
||||
self._reach = Reach(status=self._status, parent=self)
|
||||
self._frictions = FrictionList(status = self._status)
|
||||
self._frictions = FrictionList(status=self._status)
|
||||
|
||||
@classmethod
|
||||
def _sql_create(cls, execute):
|
||||
@@ -143,13 +144,14 @@ class RiverReach(Edge, SQLSubModel):
|
||||
return cls._update_submodel(execute, version)
|
||||
|
||||
@classmethod
|
||||
def _sql_load(cls, execute, data = None):
|
||||
def _sql_load(cls, execute, data=None):
|
||||
reachs = []
|
||||
|
||||
if data is None:
|
||||
data = {}
|
||||
|
||||
table = execute("SELECT id, name, enable, node1, node2 FROM river_reach")
|
||||
table = execute(
|
||||
"SELECT id, name, enable, node1, node2 FROM river_reach")
|
||||
for row in table:
|
||||
# Update id counter
|
||||
cls._id_cnt = max(cls._id_cnt, row[0])
|
||||
@@ -161,8 +163,8 @@ class RiverReach(Edge, SQLSubModel):
|
||||
node1 = next(filter(lambda n: n.id == row[3], data["nodes"]))
|
||||
node2 = next(filter(lambda n: n.id == row[4], data["nodes"]))
|
||||
|
||||
new = cls(id, name, node1, node2, status = data["status"])
|
||||
new.enable(enable = enable)
|
||||
new = cls(id, name, node1, node2, status=data["status"])
|
||||
new.enable(enable=enable)
|
||||
|
||||
data["reach"] = id
|
||||
data["parent"] = new
|
||||
@@ -174,14 +176,14 @@ class RiverReach(Edge, SQLSubModel):
|
||||
|
||||
return reachs
|
||||
|
||||
def _sql_save(self, execute, data = None):
|
||||
def _sql_save(self, execute, data=None):
|
||||
sql = (
|
||||
"INSERT OR REPLACE INTO " +
|
||||
"river_reach(id, name, enable, node1, node2) "+
|
||||
"river_reach(id, name, enable, node1, node2) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, '{self._sql_format(self._name)}', " +
|
||||
f"{self._sql_format(self.is_enable())},"
|
||||
f"{self.node1.id}, {self.node2.id}"+
|
||||
f"{self.node1.id}, {self.node2.id}" +
|
||||
")"
|
||||
)
|
||||
execute(sql)
|
||||
@@ -202,6 +204,7 @@ class RiverReach(Edge, SQLSubModel):
|
||||
def frictions(self):
|
||||
return self._frictions
|
||||
|
||||
|
||||
class River(Graph, SQLSubModel):
|
||||
_sub_classes = [
|
||||
RiverNode,
|
||||
@@ -223,7 +226,8 @@ class River(Graph, SQLSubModel):
|
||||
|
||||
self._current_reach = None
|
||||
self._boundary_condition = BoundaryConditionList(status=self._status)
|
||||
self._lateral_contribution = LateralContributionList(status=self._status)
|
||||
self._lateral_contribution = LateralContributionList(
|
||||
status=self._status)
|
||||
self._initial_conditions = InitialConditionsDict(status=self._status)
|
||||
self._stricklers = StricklersList(status=self._status)
|
||||
self._parameters = {}
|
||||
@@ -240,7 +244,7 @@ class River(Graph, SQLSubModel):
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _sql_load(cls, execute, data = None):
|
||||
def _sql_load(cls, execute, data=None):
|
||||
new = cls(data["status"])
|
||||
|
||||
# Stricklers (Stricklers is load in first because it's needed
|
||||
@@ -251,7 +255,6 @@ class River(Graph, SQLSubModel):
|
||||
)
|
||||
data["stricklers"] = new._stricklers
|
||||
|
||||
|
||||
# Initial conditions
|
||||
new._sediment_layers = SedimentLayerList._sql_load(
|
||||
execute,
|
||||
@@ -297,7 +300,7 @@ class River(Graph, SQLSubModel):
|
||||
|
||||
return new
|
||||
|
||||
def _sql_save(self, execute, data = None):
|
||||
def _sql_save(self, execute, data=None):
|
||||
objs = (self._nodes + self._edges)
|
||||
objs.append(self._boundary_condition)
|
||||
objs.append(self._initial_conditions)
|
||||
@@ -344,7 +347,6 @@ class River(Graph, SQLSubModel):
|
||||
|
||||
return ret[0]
|
||||
|
||||
|
||||
@property
|
||||
def parameters(self):
|
||||
return self._parameters
|
||||
@@ -354,8 +356,8 @@ class River(Graph, SQLSubModel):
|
||||
return self._parameters[solver]
|
||||
|
||||
new = SolverParametersList(
|
||||
solver_type = solver_type_list[solver],
|
||||
status = self._status
|
||||
solver_type=solver_type_list[solver],
|
||||
status=self._status
|
||||
)
|
||||
self._parameters[solver] = new
|
||||
self._status.modified()
|
||||
|
||||
@@ -20,6 +20,7 @@ import logging
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class SavedStatus(object):
|
||||
def __init__(self):
|
||||
super(SavedStatus, self).__init__()
|
||||
|
||||
@@ -5,16 +5,17 @@ from tools import trace, timer
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
|
||||
|
||||
class Layer(SQLSubModel):
|
||||
_sub_classes = []
|
||||
_id_cnt = 0
|
||||
|
||||
def __init__(self,
|
||||
id:int = -1, name:str = "",
|
||||
type = "",
|
||||
height = 0.0, d50 = 0.0, sigma = 0.0,
|
||||
critical_constraint = 0.0,
|
||||
sl = None, status = None):
|
||||
id: int = -1, name: str = "",
|
||||
type="",
|
||||
height=0.0, d50=0.0, sigma=0.0,
|
||||
critical_constraint=0.0,
|
||||
sl=None, status=None):
|
||||
super(Layer, self).__init__()
|
||||
|
||||
self._status = status
|
||||
@@ -111,7 +112,7 @@ class Layer(SQLSubModel):
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _sql_load(cls, execute, data = None):
|
||||
def _sql_load(cls, execute, data=None):
|
||||
new = []
|
||||
sl = data["sl"]
|
||||
|
||||
@@ -128,24 +129,24 @@ class Layer(SQLSubModel):
|
||||
ind = row[1]
|
||||
|
||||
layer = cls(
|
||||
id = row[0], name = row[2],
|
||||
type = row[3], height = row[4],
|
||||
d50 = row[5], sigma = row[6],
|
||||
critical_constraint = row[7],
|
||||
sl = sl, status = data['status']
|
||||
id=row[0], name=row[2],
|
||||
type=row[3], height=row[4],
|
||||
d50=row[5], sigma=row[6],
|
||||
critical_constraint=row[7],
|
||||
sl=sl, status=data['status']
|
||||
)
|
||||
|
||||
new[ind] = layer
|
||||
|
||||
return new
|
||||
|
||||
def _sql_save(self, execute, data = None):
|
||||
def _sql_save(self, execute, data=None):
|
||||
ind = data["ind"]
|
||||
sl = data["sl"]
|
||||
|
||||
sql = (
|
||||
"INSERT INTO " +
|
||||
"sedimentary_layer_layer(id, ind, name, type, height, d50, sigma, critical_constraint, sl) "+
|
||||
"sedimentary_layer_layer(id, ind, name, type, height, d50, sigma, critical_constraint, sl) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, {ind}, '{self._sql_format(self._name)}', " +
|
||||
f"'{self._sql_format(self._type)}', {self._height}, " +
|
||||
@@ -162,9 +163,9 @@ class SedimentLayer(SQLSubModel):
|
||||
_sub_classes = [Layer]
|
||||
_id_cnt = 0
|
||||
|
||||
def __init__(self, id:int = -1,
|
||||
name:str = "", comment:str = "",
|
||||
status = None):
|
||||
def __init__(self, id: int = -1,
|
||||
name: str = "", comment: str = "",
|
||||
status=None):
|
||||
super(SedimentLayer, self).__init__()
|
||||
|
||||
self._status = status
|
||||
@@ -242,7 +243,7 @@ class SedimentLayer(SQLSubModel):
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _sql_load(cls, execute, data = None):
|
||||
def _sql_load(cls, execute, data=None):
|
||||
new = []
|
||||
|
||||
table = execute(
|
||||
@@ -252,10 +253,10 @@ class SedimentLayer(SQLSubModel):
|
||||
|
||||
for row in table:
|
||||
sl = cls(
|
||||
id = row[0],
|
||||
name = row[1],
|
||||
comment = row[2],
|
||||
status = data['status']
|
||||
id=row[0],
|
||||
name=row[1],
|
||||
comment=row[2],
|
||||
status=data['status']
|
||||
)
|
||||
|
||||
data["sl"] = sl.id
|
||||
@@ -265,7 +266,7 @@ class SedimentLayer(SQLSubModel):
|
||||
|
||||
return new
|
||||
|
||||
def _sql_save(self, execute, data = None):
|
||||
def _sql_save(self, execute, data=None):
|
||||
if data is None:
|
||||
data = {}
|
||||
|
||||
@@ -298,7 +299,7 @@ class SedimentLayer(SQLSubModel):
|
||||
self._status.modified()
|
||||
|
||||
def new(self, index):
|
||||
n = Layer(sl=self, status = self._status)
|
||||
n = Layer(sl=self, status=self._status)
|
||||
self.insert(index, n)
|
||||
self._status.modified()
|
||||
return n
|
||||
|
||||
@@ -6,18 +6,19 @@ from Model.Except import NotImplementedMethodeError
|
||||
from Model.Tools.PamhyrList import PamhyrModelList
|
||||
from Model.SedimentLayer.SedimentLayer import SedimentLayer
|
||||
|
||||
|
||||
class SedimentLayerList(PamhyrModelList):
|
||||
_sub_classes = [SedimentLayer]
|
||||
|
||||
@classmethod
|
||||
def _sql_load(cls, execute, data = None):
|
||||
new = cls(status = data["status"])
|
||||
def _sql_load(cls, execute, data=None):
|
||||
new = cls(status=data["status"])
|
||||
|
||||
new._lst = SedimentLayer._sql_load(execute, data)
|
||||
|
||||
return new
|
||||
|
||||
def _sql_save(self, execute, data = None):
|
||||
def _sql_save(self, execute, data=None):
|
||||
ok = True
|
||||
|
||||
# Delete previous data
|
||||
@@ -34,7 +35,7 @@ class SedimentLayerList(PamhyrModelList):
|
||||
return self.lst
|
||||
|
||||
def new(self, index):
|
||||
n = SedimentLayer(status = self._status)
|
||||
n = SedimentLayer(status=self._status)
|
||||
self.insert(index, n)
|
||||
self._status.modified()
|
||||
return n
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
import pickle
|
||||
|
||||
|
||||
class Serializable():
|
||||
def __init__(self):
|
||||
return
|
||||
|
||||
@@ -22,10 +22,11 @@ from Solver.Solvers import solver_type_list
|
||||
|
||||
from Model.Tools.PamhyrList import PamhyrModelList
|
||||
|
||||
|
||||
class Parameter():
|
||||
def __init__(self,
|
||||
name = "", value = "",
|
||||
status = None):
|
||||
name="", value="",
|
||||
status=None):
|
||||
self._status = status
|
||||
|
||||
self._name = name
|
||||
@@ -57,14 +58,15 @@ class Parameter():
|
||||
|
||||
@classmethod
|
||||
def from_tuple(cls, data, status):
|
||||
new = cls(status = status)
|
||||
new = cls(status=status)
|
||||
new["name"] = data[0]
|
||||
new["value"] = data[1]
|
||||
|
||||
return new
|
||||
|
||||
|
||||
class SolverParametersList(PamhyrModelList):
|
||||
def __init__(self, solver_type = None, status = None):
|
||||
def __init__(self, solver_type=None, status=None):
|
||||
super(SolverParametersList, self).__init__()
|
||||
|
||||
self._status = status
|
||||
@@ -76,7 +78,6 @@ class SolverParametersList(PamhyrModelList):
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@classmethod
|
||||
def _sql_create(cls, execute):
|
||||
execute("""
|
||||
@@ -97,35 +98,38 @@ class SolverParametersList(PamhyrModelList):
|
||||
|
||||
if major == minor == "0":
|
||||
if int(release) < 3:
|
||||
execute(f"UPDATE solver_parameter SET name='mage_implicitation' WHERE name='mage_implication'")
|
||||
execute(f"UPDATE solver_parameter SET name='mage_iteration_type' WHERE name='mage_iter_type'")
|
||||
execute(
|
||||
f"UPDATE solver_parameter SET name='mage_implicitation' WHERE name='mage_implication'")
|
||||
execute(
|
||||
f"UPDATE solver_parameter SET name='mage_iteration_type' WHERE name='mage_iter_type'")
|
||||
|
||||
if int(release) < 4:
|
||||
solvers = execute("SELECT DISTINCT solver FROM solver_parameter")
|
||||
solvers = execute(
|
||||
"SELECT DISTINCT solver FROM solver_parameter")
|
||||
|
||||
for solver in solvers:
|
||||
if solver != "mage8":
|
||||
continue
|
||||
|
||||
data = execute("SELECT ind, name, value " +
|
||||
"FROM solver_parameter "+
|
||||
f"WHERE solver = '{solver}' " +
|
||||
"ORDER BY ind ACS")
|
||||
"FROM solver_parameter " +
|
||||
f"WHERE solver = '{solver}' " +
|
||||
"ORDER BY ind ACS")
|
||||
|
||||
execute(
|
||||
"DELETE FROM solver_parameter " +
|
||||
f"WHERE solver = '{solver}'"
|
||||
)
|
||||
|
||||
insert = lambda name, value, ind: execute(
|
||||
"INSERT INTO " +
|
||||
"solver_parameter(ind, name, value, solver) "+
|
||||
"VALUES (" +
|
||||
f"{ind}, " +
|
||||
f"'{cls._sql_format(name)}', " +
|
||||
f"'{cls._sql_format(value)}', " +
|
||||
f"'{cls._sql_format(solver)}'" +
|
||||
")"
|
||||
def insert(name, value, ind): return execute(
|
||||
"INSERT INTO " +
|
||||
"solver_parameter(ind, name, value, solver) " +
|
||||
"VALUES (" +
|
||||
f"{ind}, " +
|
||||
f"'{cls._sql_format(name)}', " +
|
||||
f"'{cls._sql_format(value)}', " +
|
||||
f"'{cls._sql_format(solver)}'" +
|
||||
")"
|
||||
)
|
||||
|
||||
ind = 0
|
||||
@@ -156,7 +160,7 @@ class SolverParametersList(PamhyrModelList):
|
||||
return cls._update_submodel(execute, version)
|
||||
|
||||
@classmethod
|
||||
def _sql_load(cls, execute, data = None):
|
||||
def _sql_load(cls, execute, data=None):
|
||||
status = data["status"]
|
||||
solvers = execute("SELECT DISTINCT solver FROM solver_parameter")
|
||||
new = {}
|
||||
@@ -167,7 +171,7 @@ class SolverParametersList(PamhyrModelList):
|
||||
continue
|
||||
|
||||
st = solver_type_list[solver]
|
||||
n = cls(solver_type = st, status = status)
|
||||
n = cls(solver_type=st, status=status)
|
||||
|
||||
table = execute(
|
||||
"SELECT ind, name, value " +
|
||||
@@ -186,7 +190,7 @@ class SolverParametersList(PamhyrModelList):
|
||||
|
||||
return new
|
||||
|
||||
def _sql_save(self, execute, data = None):
|
||||
def _sql_save(self, execute, data=None):
|
||||
t = self._solver._type
|
||||
execute(
|
||||
"DELETE FROM solver_parameter " +
|
||||
@@ -197,7 +201,7 @@ class SolverParametersList(PamhyrModelList):
|
||||
for param in self._lst:
|
||||
sql = (
|
||||
"INSERT INTO " +
|
||||
"solver_parameter(ind, name, value, solver) "+
|
||||
"solver_parameter(ind, name, value, solver) " +
|
||||
"VALUES (" +
|
||||
f"{ind}, " +
|
||||
f"'{self._sql_format(param.name)}', " +
|
||||
@@ -241,15 +245,15 @@ class SolverParametersList(PamhyrModelList):
|
||||
|
||||
self._lst.append(
|
||||
Parameter(
|
||||
name = key,
|
||||
value = value,
|
||||
status = self._status
|
||||
name=key,
|
||||
value=value,
|
||||
status=self._status
|
||||
)
|
||||
)
|
||||
self._status.modified()
|
||||
|
||||
def new(self, index):
|
||||
n = Parameter(status = self._status)
|
||||
n = Parameter(status=self._status)
|
||||
self._lst.insert(index, n)
|
||||
self._status.modified()
|
||||
return n
|
||||
@@ -20,16 +20,17 @@ from tools import trace, timer
|
||||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
|
||||
|
||||
class Stricklers(SQLSubModel):
|
||||
_id_cnt = 0
|
||||
_sub_classes = []
|
||||
|
||||
def __init__(self, id:int = -1,
|
||||
name:str = "",
|
||||
comment:str = "",
|
||||
minor:float = 35.0,
|
||||
medium:float = 15.0,
|
||||
status = None):
|
||||
def __init__(self, id: int = -1,
|
||||
name: str = "",
|
||||
comment: str = "",
|
||||
minor: float = 35.0,
|
||||
medium: float = 15.0,
|
||||
status=None):
|
||||
super(Stricklers, self).__init__()
|
||||
self._status = status
|
||||
|
||||
@@ -46,7 +47,6 @@ class Stricklers(SQLSubModel):
|
||||
self._minor = minor
|
||||
self._medium = medium
|
||||
|
||||
|
||||
@classmethod
|
||||
def _sql_create(cls, execute):
|
||||
execute("""
|
||||
@@ -66,7 +66,7 @@ class Stricklers(SQLSubModel):
|
||||
return cls._update_submodel(execute, version)
|
||||
|
||||
@classmethod
|
||||
def _sql_load(cls, execute, data = None):
|
||||
def _sql_load(cls, execute, data=None):
|
||||
stricklers = []
|
||||
status = data["status"]
|
||||
|
||||
@@ -86,21 +86,21 @@ class Stricklers(SQLSubModel):
|
||||
medium = row[4]
|
||||
|
||||
new = cls(
|
||||
id = id,
|
||||
name = name,
|
||||
comment = comment,
|
||||
minor = minor, medium = medium,
|
||||
status = status
|
||||
id=id,
|
||||
name=name,
|
||||
comment=comment,
|
||||
minor=minor, medium=medium,
|
||||
status=status
|
||||
)
|
||||
|
||||
stricklers.append(new)
|
||||
|
||||
return stricklers
|
||||
|
||||
def _sql_save(self, execute, data = None):
|
||||
def _sql_save(self, execute, data=None):
|
||||
sql = (
|
||||
"INSERT INTO " +
|
||||
"stricklers(id, name, comment, minor, medium) "+
|
||||
"stricklers(id, name, comment, minor, medium) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, " +
|
||||
f"'{self._sql_format(self.name)}', " +
|
||||
|
||||
@@ -22,6 +22,7 @@ from Model.Saved import SavedStatus
|
||||
from Model.Tools.PamhyrList import PamhyrModelList
|
||||
from Model.Stricklers.Stricklers import Stricklers
|
||||
|
||||
|
||||
class StricklersList(PamhyrModelList):
|
||||
_sub_classes = [
|
||||
Stricklers,
|
||||
@@ -36,17 +37,17 @@ class StricklersList(PamhyrModelList):
|
||||
return cls._update_submodel(execute, version)
|
||||
|
||||
@classmethod
|
||||
def _sql_load(cls, execute, data = None):
|
||||
new = cls(status = data["status"])
|
||||
def _sql_load(cls, execute, data=None):
|
||||
new = cls(status=data["status"])
|
||||
|
||||
new._lst = Stricklers._sql_load(
|
||||
execute,
|
||||
data = data
|
||||
data=data
|
||||
)
|
||||
|
||||
return new
|
||||
|
||||
def _sql_save(self, execute, data = None):
|
||||
def _sql_save(self, execute, data=None):
|
||||
execute("DELETE FROM stricklers")
|
||||
|
||||
objs = self._lst
|
||||
@@ -57,20 +58,20 @@ class StricklersList(PamhyrModelList):
|
||||
return self.lst
|
||||
|
||||
def new(self, index):
|
||||
s = Stricklers(status = self._status)
|
||||
s = Stricklers(status=self._status)
|
||||
self.insert(index, s)
|
||||
return s
|
||||
|
||||
@timer
|
||||
def sort(self, reverse:bool = False, key=None):
|
||||
f = lambda st: st.name
|
||||
def sort(self, reverse: bool = False, key=None):
|
||||
def f(st): return st.name
|
||||
if key is not None:
|
||||
f = key
|
||||
|
||||
self._lst = sorted(
|
||||
self._lst,
|
||||
key = f,
|
||||
reverse = reverse,
|
||||
key=f,
|
||||
reverse=reverse,
|
||||
)
|
||||
|
||||
if self._status is not None:
|
||||
|
||||
+39
-25
@@ -33,12 +33,13 @@ from Checker.Study import *
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class Study(SQLModel):
|
||||
_sub_classes = [
|
||||
River,
|
||||
]
|
||||
|
||||
def __init__(self, filename = None, init_new = True):
|
||||
def __init__(self, filename=None, init_new=True):
|
||||
# Metadata
|
||||
self._version = "0.0.4"
|
||||
self.creation_date = datetime.now()
|
||||
@@ -46,7 +47,7 @@ class Study(SQLModel):
|
||||
self.last_save_date = datetime.now()
|
||||
|
||||
self._filename = filename
|
||||
super(Study, self).__init__(filename = filename)
|
||||
super(Study, self).__init__(filename=filename)
|
||||
|
||||
self.status = SavedStatus()
|
||||
|
||||
@@ -59,9 +60,9 @@ class Study(SQLModel):
|
||||
|
||||
if init_new:
|
||||
# Study data
|
||||
self._river = River(status = self.status)
|
||||
self._river = River(status=self.status)
|
||||
else:
|
||||
self._init_db_file(filename, is_new = False)
|
||||
self._init_db_file(filename, is_new=False)
|
||||
|
||||
self._old_save_id = 0
|
||||
|
||||
@@ -128,7 +129,7 @@ class Study(SQLModel):
|
||||
@filename.setter
|
||||
def filename(self, filename):
|
||||
self._filename = str(filename)
|
||||
self._init_db_file(filename, is_new = True)
|
||||
self._init_db_file(filename, is_new=True)
|
||||
self.status.modified()
|
||||
|
||||
@property
|
||||
@@ -139,7 +140,7 @@ class Study(SQLModel):
|
||||
self._time_system = "time"
|
||||
self.status.modified()
|
||||
|
||||
def use_date(self, date:datetime):
|
||||
def use_date(self, date: datetime):
|
||||
self._time_system = "date"
|
||||
self._date = date
|
||||
self.status.modified()
|
||||
@@ -158,7 +159,7 @@ class Study(SQLModel):
|
||||
# return cls()
|
||||
|
||||
@classmethod
|
||||
def new(cls, name, description, date = None):
|
||||
def new(cls, name, description, date=None):
|
||||
me = cls()
|
||||
me.name = name
|
||||
me.description = description
|
||||
@@ -178,14 +179,16 @@ class Study(SQLModel):
|
||||
|
||||
def _create(self):
|
||||
# Info (metadata)
|
||||
self.execute("CREATE TABLE info(key TEXT NOT NULL UNIQUE, value TEXT NOT NULL)")
|
||||
self.execute(
|
||||
"CREATE TABLE info(key TEXT NOT NULL UNIQUE, value TEXT NOT NULL)")
|
||||
self.execute(
|
||||
f"INSERT INTO info VALUES ('version', '{self._sql_format(self._version)}')",
|
||||
commit = True
|
||||
commit=True
|
||||
)
|
||||
self.execute("INSERT INTO info VALUES ('name', '')")
|
||||
self.execute("INSERT INTO info VALUES ('description', '')")
|
||||
self.execute(f"INSERT INTO info VALUES ('time_system', '{self._time_system}')")
|
||||
self.execute(
|
||||
f"INSERT INTO info VALUES ('time_system', '{self._time_system}')")
|
||||
self.execute(
|
||||
f"INSERT INTO info VALUES ('date', " +
|
||||
"'{self._date.timestamp()}')"
|
||||
@@ -213,7 +216,8 @@ class Study(SQLModel):
|
||||
logger.info("Update database")
|
||||
|
||||
if self._update_submodel(version[0]):
|
||||
self.execute(f"UPDATE info SET value='{self._version}' WHERE key='version'")
|
||||
self.execute(
|
||||
f"UPDATE info SET value='{self._version}' WHERE key='version'")
|
||||
return True
|
||||
|
||||
logger.info("TODO: update failed")
|
||||
@@ -221,42 +225,52 @@ class Study(SQLModel):
|
||||
|
||||
@classmethod
|
||||
def _load(cls, filename):
|
||||
new = cls(init_new = False, filename = filename)
|
||||
new = cls(init_new=False, filename=filename)
|
||||
|
||||
# TODO: Load metadata
|
||||
new.name = new.execute("SELECT value FROM info WHERE key='name'")[0]
|
||||
new.description = new.execute("SELECT value FROM info WHERE key='description'")[0]
|
||||
new._time_system = new.execute("SELECT value FROM info WHERE key='time_system'")[0]
|
||||
new.description = new.execute(
|
||||
"SELECT value FROM info WHERE key='description'")[0]
|
||||
new._time_system = new.execute(
|
||||
"SELECT value FROM info WHERE key='time_system'")[0]
|
||||
new._date = datetime.fromtimestamp(
|
||||
float(new.execute("SELECT value FROM info WHERE key='date'")[0])
|
||||
)
|
||||
|
||||
new.creation_date = datetime.fromtimestamp(
|
||||
float(new.execute("SELECT value FROM info WHERE key='creation_date'")[0])
|
||||
float(new.execute(
|
||||
"SELECT value FROM info WHERE key='creation_date'")[0])
|
||||
)
|
||||
new.last_save_date = datetime.fromtimestamp(
|
||||
float(new.execute("SELECT value FROM info WHERE key='last_save_date'")[0])
|
||||
float(new.execute(
|
||||
"SELECT value FROM info WHERE key='last_save_date'")[0])
|
||||
)
|
||||
|
||||
# Load river data
|
||||
new._river = River._sql_load(
|
||||
lambda sql: new.execute(
|
||||
sql,
|
||||
fetch_one = False,
|
||||
commit = True
|
||||
fetch_one=False,
|
||||
commit=True
|
||||
),
|
||||
data = {"status": new.status}
|
||||
data={"status": new.status}
|
||||
)
|
||||
|
||||
return new
|
||||
|
||||
def _save(self):
|
||||
self.execute(f"UPDATE info SET value='{self._sql_format(self.name)}' WHERE key='name'")
|
||||
self.execute(f"UPDATE info SET value='{self._sql_format(self.description)}' WHERE key='description'")
|
||||
self.execute(f"UPDATE info SET value='{self._time_system}' WHERE key='time_system'")
|
||||
self.execute(f"UPDATE info SET value='{timestamp(self._date)}' WHERE key='date'")
|
||||
self.execute(f"UPDATE info SET value='{timestamp(self.creation_date)}' WHERE key='creation_date'")
|
||||
self.execute(f"UPDATE info SET value='{timestamp(self.last_save_date)}' WHERE key='last_save_date'")
|
||||
self.execute(
|
||||
f"UPDATE info SET value='{self._sql_format(self.name)}' WHERE key='name'")
|
||||
self.execute(
|
||||
f"UPDATE info SET value='{self._sql_format(self.description)}' WHERE key='description'")
|
||||
self.execute(
|
||||
f"UPDATE info SET value='{self._time_system}' WHERE key='time_system'")
|
||||
self.execute(
|
||||
f"UPDATE info SET value='{timestamp(self._date)}' WHERE key='date'")
|
||||
self.execute(
|
||||
f"UPDATE info SET value='{timestamp(self.creation_date)}' WHERE key='creation_date'")
|
||||
self.execute(
|
||||
f"UPDATE info SET value='{timestamp(self.last_save_date)}' WHERE key='last_save_date'")
|
||||
|
||||
self._save_submodel([self._river])
|
||||
self.commit()
|
||||
+21
-18
@@ -28,10 +28,12 @@ from Model.Except import NotImplementedMethodeError
|
||||
logger = logging.getLogger()
|
||||
|
||||
# Top level model class
|
||||
|
||||
|
||||
class SQLModel(SQL):
|
||||
_sub_classes = []
|
||||
|
||||
def _init_db_file(self, db, is_new = True):
|
||||
def _init_db_file(self, db, is_new=True):
|
||||
exists = Path(db).exists()
|
||||
|
||||
if exists and is_new:
|
||||
@@ -48,15 +50,14 @@ class SQLModel(SQL):
|
||||
self._update() # Update db scheme if necessary
|
||||
# self._load() # Load data
|
||||
|
||||
|
||||
def __init__(self, filename = None):
|
||||
def __init__(self, filename=None):
|
||||
self._db = None
|
||||
|
||||
def _create_submodel(self):
|
||||
fn = lambda sql: self.execute(
|
||||
def fn(sql): return self.execute(
|
||||
sql,
|
||||
fetch_one = False,
|
||||
commit = False
|
||||
fetch_one=False,
|
||||
commit=False
|
||||
)
|
||||
|
||||
for cls in self._sub_classes:
|
||||
@@ -69,10 +70,10 @@ class SQLModel(SQL):
|
||||
raise NotImplementedMethodeError(self, self._create)
|
||||
|
||||
def _update_submodel(self, version):
|
||||
fn = lambda sql: self.execute(
|
||||
def fn(sql): return self.execute(
|
||||
sql,
|
||||
fetch_one = False,
|
||||
commit = False
|
||||
fetch_one=False,
|
||||
commit=False
|
||||
)
|
||||
|
||||
ok = True
|
||||
@@ -85,11 +86,11 @@ class SQLModel(SQL):
|
||||
def _update(self):
|
||||
raise NotImplementedMethodeError(self, self._update)
|
||||
|
||||
def _save_submodel(self, objs, data = None):
|
||||
fn = lambda sql: self.execute(
|
||||
def _save_submodel(self, objs, data=None):
|
||||
def fn(sql): return self.execute(
|
||||
sql,
|
||||
fetch_one = False,
|
||||
commit = False
|
||||
fetch_one=False,
|
||||
commit=False
|
||||
)
|
||||
|
||||
ok = True
|
||||
@@ -103,10 +104,12 @@ class SQLModel(SQL):
|
||||
raise NotImplementedMethodeError(self, self._save)
|
||||
|
||||
@classmethod
|
||||
def _load(cls, filename = None):
|
||||
def _load(cls, filename=None):
|
||||
raise NotImplementedMethodeError(cls, cls._load)
|
||||
|
||||
# Sub model class
|
||||
|
||||
|
||||
class SQLSubModel(object):
|
||||
_sub_classes = []
|
||||
|
||||
@@ -154,7 +157,7 @@ class SQLSubModel(object):
|
||||
raise NotImplementedMethodeError(cls, cls._sql_update)
|
||||
|
||||
@classmethod
|
||||
def _sql_load(cls, execute, data = None):
|
||||
def _sql_load(cls, execute, data=None):
|
||||
"""Load instance of this class from SQL data base
|
||||
|
||||
Args:
|
||||
@@ -166,11 +169,11 @@ class SQLSubModel(object):
|
||||
"""
|
||||
raise NotImplementedMethodeError(cls, cls._sql_load)
|
||||
|
||||
def _save_submodel(self, execute, objs, data = None):
|
||||
def _save_submodel(self, execute, objs, data=None):
|
||||
for o in objs:
|
||||
o._sql_save(execute, data = data)
|
||||
o._sql_save(execute, data=data)
|
||||
|
||||
def _sql_save(self, execute, data = None):
|
||||
def _sql_save(self, execute, data=None):
|
||||
"""Save class data to data base
|
||||
|
||||
Args:
|
||||
|
||||
@@ -30,7 +30,7 @@ logger = logging.getLogger()
|
||||
class PamhyrModelDict(SQLSubModel):
|
||||
_sub_classes = []
|
||||
|
||||
def __init__(self, status = None):
|
||||
def __init__(self, status=None):
|
||||
super(PamhyrModelDict, self).__init__()
|
||||
|
||||
self._status = status
|
||||
@@ -46,10 +46,10 @@ class PamhyrModelDict(SQLSubModel):
|
||||
return cls._update_submodel(execute, version)
|
||||
|
||||
@classmethod
|
||||
def _sql_load(cls, execute, data = None):
|
||||
def _sql_load(cls, execute, data=None):
|
||||
raise NotImplementedMethodeError(cls, cls._sql_load)
|
||||
|
||||
def _sql_save(self, execute, data = None):
|
||||
def _sql_save(self, execute, data=None):
|
||||
raise NotImplementedMethodeError(self, self._sql_save)
|
||||
|
||||
def __len__(self):
|
||||
|
||||
@@ -26,11 +26,12 @@ from Model.Except import NotImplementedMethodeError
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class PamhyrModelList(SQLSubModel):
|
||||
_sub_classes = [
|
||||
]
|
||||
|
||||
def __init__(self, status = None):
|
||||
def __init__(self, status=None):
|
||||
super(PamhyrModelList, self).__init__()
|
||||
|
||||
self._status = status
|
||||
@@ -49,10 +50,10 @@ class PamhyrModelList(SQLSubModel):
|
||||
return cls._update_submodel(execute, version)
|
||||
|
||||
@classmethod
|
||||
def _sql_load(cls, execute, data = None):
|
||||
def _sql_load(cls, execute, data=None):
|
||||
raise NotImplementedMethodeError(cls, cls._sql_load)
|
||||
|
||||
def _sql_save(self, execute, data = None):
|
||||
def _sql_save(self, execute, data=None):
|
||||
raise NotImplementedMethodeError(self, self._sql_save)
|
||||
|
||||
################
|
||||
@@ -142,7 +143,7 @@ class PamhyrModelListWithTab(SQLSubModel):
|
||||
_sub_classes = [
|
||||
]
|
||||
|
||||
def __init__(self, status = None):
|
||||
def __init__(self, status=None):
|
||||
super(PamhyrModelListWithTab, self).__init__()
|
||||
|
||||
self._status = status
|
||||
@@ -163,10 +164,10 @@ class PamhyrModelListWithTab(SQLSubModel):
|
||||
return cls._update_submodel(execute, version)
|
||||
|
||||
@classmethod
|
||||
def _sql_load(cls, execute, data = None):
|
||||
def _sql_load(cls, execute, data=None):
|
||||
raise NotImplementedMethodeError(cls, cls._sql_load)
|
||||
|
||||
def _sql_save(self, execute, data = None):
|
||||
def _sql_save(self, execute, data=None):
|
||||
raise NotImplementedMethodeError(self, self._sql_save)
|
||||
|
||||
################
|
||||
|
||||
Reference in new issue
Block a user