mirror of https://gitlab.com/pamhyr/pamhyr2
LC: Add scenario support.
parent
a2ff3ecd9a
commit
c01effbf4c
|
|
@ -252,7 +252,7 @@ class BoundaryCondition(SQLSubModel):
|
||||||
cls._db_update_to_0_1_0(execute, data)
|
cls._db_update_to_0_1_0(execute, data)
|
||||||
|
|
||||||
if major == "0" and minor == "1":
|
if major == "0" and minor == "1":
|
||||||
if release < 2:
|
if int(release) < 2:
|
||||||
execute(
|
execute(
|
||||||
"ALTER TABLE friction " +
|
"ALTER TABLE friction " +
|
||||||
"ADD COLUMN deleted BOOLEAN NOT NULL DEFAULT FALSE"
|
"ADD COLUMN deleted BOOLEAN NOT NULL DEFAULT FALSE"
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ class BoundaryConditionList(PamhyrModelListWithTab):
|
||||||
|
|
||||||
def _db_save(self, execute, data=None):
|
def _db_save(self, execute, data=None):
|
||||||
execute(
|
execute(
|
||||||
"DELETE FROM boundary_condition "
|
"DELETE FROM boundary_condition " +
|
||||||
f"WHERE scenario = {self._status.scenario_id}"
|
f"WHERE scenario = {self._status.scenario_id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,9 +39,12 @@ class Data(SQLSubModel):
|
||||||
data0, data1,
|
data0, data1,
|
||||||
id: int = -1,
|
id: int = -1,
|
||||||
types=[float, float],
|
types=[float, float],
|
||||||
status=None):
|
status=None,
|
||||||
super(Data, self).__init__(id)
|
owner_scenario=-1):
|
||||||
self._status = status
|
super(Data, self).__init__(
|
||||||
|
id=id, status=status,
|
||||||
|
owner_scenario=owner_scenario
|
||||||
|
)
|
||||||
|
|
||||||
self._types = types
|
self._types = types
|
||||||
self._data = [data0, data1]
|
self._data = [data0, data1]
|
||||||
|
|
@ -51,6 +54,7 @@ class Data(SQLSubModel):
|
||||||
execute(f"""
|
execute(f"""
|
||||||
CREATE TABLE lateral_contribution_data{ext} (
|
CREATE TABLE lateral_contribution_data{ext} (
|
||||||
{cls.create_db_add_pamhyr_id()},
|
{cls.create_db_add_pamhyr_id()},
|
||||||
|
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
ind INTEGER NOT NULL,
|
ind INTEGER NOT NULL,
|
||||||
data0 TEXT NOT NULL,
|
data0 TEXT NOT NULL,
|
||||||
data1 TEXT NOT NULL,
|
data1 TEXT NOT NULL,
|
||||||
|
|
@ -71,6 +75,13 @@ class Data(SQLSubModel):
|
||||||
if major == minor == "0":
|
if major == minor == "0":
|
||||||
cls._db_update_to_0_1_0(execute, data)
|
cls._db_update_to_0_1_0(execute, data)
|
||||||
|
|
||||||
|
if major == "0" and minor == "1":
|
||||||
|
if int(release) < 2:
|
||||||
|
execute(
|
||||||
|
"ALTER TABLE boundary_condition_data " +
|
||||||
|
"ADD COLUMN deleted BOOLEAN NOT NULL DEFAULT FALSE"
|
||||||
|
)
|
||||||
|
|
||||||
return cls._update_submodel(execute, version, data)
|
return cls._update_submodel(execute, version, data)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
@ -115,11 +126,20 @@ class Data(SQLSubModel):
|
||||||
def _db_load(cls, execute, data=None):
|
def _db_load(cls, execute, data=None):
|
||||||
new = []
|
new = []
|
||||||
lc = data["lc"]
|
lc = data["lc"]
|
||||||
|
status = data['status']
|
||||||
|
scenario = data["scenario"]
|
||||||
|
loaded = data['loaded_pid']
|
||||||
|
|
||||||
|
if scenario is None:
|
||||||
|
return new
|
||||||
|
|
||||||
values = execute(
|
values = execute(
|
||||||
"SELECT pamhyr_id, ind, data0, data1 " +
|
"SELECT pamhyr_id, deleted, " +
|
||||||
|
"data0, data1, scenario " +
|
||||||
"FROM lateral_contribution_data " +
|
"FROM lateral_contribution_data " +
|
||||||
f"WHERE lc = {lc._pamhyr_id} " +
|
f"WHERE lc = {lc._pamhyr_id} " +
|
||||||
|
f"AND scenario = {scenario.id} " +
|
||||||
|
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) " +
|
||||||
"ORDER BY ind ASC"
|
"ORDER BY ind ASC"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -127,18 +147,27 @@ class Data(SQLSubModel):
|
||||||
it = iter(v)
|
it = iter(v)
|
||||||
|
|
||||||
pid = next(it)
|
pid = next(it)
|
||||||
ind = next(it)
|
delete = next(it)
|
||||||
data0 = bc._types[0](next(it))
|
data0 = bc._types[0](next(it))
|
||||||
data1 = bc._types[1](next(it))
|
data1 = bc._types[1](next(it))
|
||||||
|
owner_scenario = next(it)
|
||||||
|
|
||||||
nd = cls(
|
nd = cls(
|
||||||
|
data0, data1,
|
||||||
id=pid,
|
id=pid,
|
||||||
types=lc._types,
|
types=lc._types,
|
||||||
status=data['status']
|
status=status,
|
||||||
|
owner_scenario=owner_scenario
|
||||||
)
|
)
|
||||||
nd._data = [data0, data1]
|
if deleted:
|
||||||
|
nd.set_as_deleted()
|
||||||
|
|
||||||
new.append((ind, nd))
|
loaded.add(pid)
|
||||||
|
new.append(nd)
|
||||||
|
|
||||||
|
data["scenario"] = scenario.parent
|
||||||
|
new += cls._db_load(execute, data)
|
||||||
|
data["scenario"] = scenario
|
||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
|
|
@ -149,12 +178,17 @@ class Data(SQLSubModel):
|
||||||
data1 = self._db_format(str(self[1]))
|
data1 = self._db_format(str(self[1]))
|
||||||
lc = data["lc"]
|
lc = data["lc"]
|
||||||
|
|
||||||
sql = (
|
execute(
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"lateral_contribution_data (pamhyr_id, ind, data0, data1, bc) " +
|
"lateral_contribution_data (pamhyr_id, deleted, ind, " +
|
||||||
f"VALUES ({pid}, {ind}, '{data0}', {data1}, {lc._pamhyr_id})"
|
"data0, data1, lc, scenario) " +
|
||||||
|
f"VALUES ({pid}, {self._db_format(self.is_deleted())}, " +
|
||||||
|
f"{ind}, '{self._db_format(data0)}', {self._db_format(data1)}, " +
|
||||||
|
f"{lc._pamhyr_id}, {self._status.scenario_id}" +
|
||||||
|
")"
|
||||||
)
|
)
|
||||||
execute(sql)
|
|
||||||
|
return True
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
return self._types[key](self._data[key])
|
return self._types[key](self._data[key])
|
||||||
|
|
@ -165,17 +199,20 @@ class Data(SQLSubModel):
|
||||||
|
|
||||||
class LateralContribution(SQLSubModel):
|
class LateralContribution(SQLSubModel):
|
||||||
_sub_classes = [Data]
|
_sub_classes = [Data]
|
||||||
_id_cnt = 0
|
|
||||||
|
|
||||||
def __init__(self, id: int = -1, name: str = "", status=None):
|
def __init__(self, id: int = -1,
|
||||||
super(LateralContribution, self).__init__(id)
|
name: str = "",
|
||||||
self._status = status
|
status=None, owner_scenario=-1):
|
||||||
|
super(LateralContribution, self).__init__(
|
||||||
|
id=id, status=status,
|
||||||
|
owner_scenario=owner_scenario
|
||||||
|
)
|
||||||
|
|
||||||
self._name = name
|
self._name = name
|
||||||
self._type = ""
|
self._type = ""
|
||||||
self._reach = None
|
self._reach = None
|
||||||
self._begin_rk = None
|
self._begin_section = None
|
||||||
self._end_rk = None
|
self._end_section = None
|
||||||
self._data = []
|
self._data = []
|
||||||
self._header = []
|
self._header = []
|
||||||
self._types = [float, float]
|
self._types = [float, float]
|
||||||
|
|
@ -185,6 +222,7 @@ class LateralContribution(SQLSubModel):
|
||||||
execute(f"""
|
execute(f"""
|
||||||
CREATE TABLE lateral_contribution{ext}(
|
CREATE TABLE lateral_contribution{ext}(
|
||||||
{cls.create_db_add_pamhyr_id()},
|
{cls.create_db_add_pamhyr_id()},
|
||||||
|
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
type TEXT NOT NULL,
|
type TEXT NOT NULL,
|
||||||
tab TEXT NOT NULL,
|
tab TEXT NOT NULL,
|
||||||
|
|
@ -234,6 +272,13 @@ class LateralContribution(SQLSubModel):
|
||||||
|
|
||||||
cls._db_update_to_0_1_0(execute, data)
|
cls._db_update_to_0_1_0(execute, data)
|
||||||
|
|
||||||
|
if major == "0" and minor == "1":
|
||||||
|
if int(release) < 2:
|
||||||
|
execute(
|
||||||
|
"ALTER TABLE lateral_contribution " +
|
||||||
|
"ADD COLUMN deleted BOOLEAN NOT NULL DEFAULT FALSE"
|
||||||
|
)
|
||||||
|
|
||||||
return cls._update_submodel(execute, version, data)
|
return cls._update_submodel(execute, version, data)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
@ -277,20 +322,40 @@ class LateralContribution(SQLSubModel):
|
||||||
def _db_load(cls, execute, data=None):
|
def _db_load(cls, execute, data=None):
|
||||||
new = []
|
new = []
|
||||||
tab = data["tab"]
|
tab = data["tab"]
|
||||||
|
status = data['status']
|
||||||
|
edges = data["edges"]
|
||||||
|
scenario = data["scenario"]
|
||||||
|
loaded = data['loaded_pid']
|
||||||
|
|
||||||
|
if scenario is None:
|
||||||
|
return new
|
||||||
|
|
||||||
table = execute(
|
table = execute(
|
||||||
"SELECT pamhyr_id, name, type, " +
|
"SELECT pamhyr_id, deleted, name, type, " +
|
||||||
"reach, begin_section, end_section " +
|
"reach, begin_section, end_section, scenario " +
|
||||||
f"FROM lateral_contribution WHERE tab = '{tab}'"
|
"FROM lateral_contribution " +
|
||||||
|
f"WHERE tab = '{tab}'" +
|
||||||
|
f"AND scenario = {scenario.id} " +
|
||||||
|
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
|
||||||
)
|
)
|
||||||
|
|
||||||
for row in table:
|
for row in table:
|
||||||
t = row[2]
|
it = iter(row)
|
||||||
|
|
||||||
|
pid = next(it)
|
||||||
|
deleted = next(it)
|
||||||
|
name = next(it)
|
||||||
|
t = next(it)
|
||||||
|
reach = next(it)
|
||||||
|
b_section = next(it)
|
||||||
|
e_section = next(it)
|
||||||
|
owner_scenario = next(it)
|
||||||
|
|
||||||
ctor = cls._get_ctor_from_type(t)
|
ctor = cls._get_ctor_from_type(t)
|
||||||
lc = ctor(
|
lc = ctor(
|
||||||
id=row[0],
|
id=pid, name=name,
|
||||||
name=row[1],
|
status=status,
|
||||||
status=data['status']
|
owner_scenario=owner_scenario
|
||||||
)
|
)
|
||||||
lc.reach = None
|
lc.reach = None
|
||||||
lc._begin_section = None
|
lc._begin_section = None
|
||||||
|
|
@ -299,28 +364,46 @@ class LateralContribution(SQLSubModel):
|
||||||
if row[3] != -1:
|
if row[3] != -1:
|
||||||
lc.reach = next(
|
lc.reach = next(
|
||||||
filter(
|
filter(
|
||||||
lambda e: e.id == row[3],
|
lambda e: e.id == reach,
|
||||||
data["edges"]
|
edges
|
||||||
|
)
|
||||||
|
)
|
||||||
|
lc._begin_section = next(
|
||||||
|
filter(
|
||||||
|
lambda p: p.id == b_section,
|
||||||
|
lc.reach.reach.profiles
|
||||||
|
)
|
||||||
|
)
|
||||||
|
lc._end_section = next(
|
||||||
|
filter(
|
||||||
|
lambda p: p.id == e_section,
|
||||||
|
lc.reach.reach.profiles
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
lc._begin_section = lc.reach.profile(row[4])
|
|
||||||
lc._end_section = lc.reach.profile(row[5])
|
|
||||||
|
|
||||||
data["lc"] = lc
|
data["lc"] = lc
|
||||||
lc._data = Data._db_load(execute, data=data)
|
lc._data = Data._db_load(execute, data=data)
|
||||||
|
|
||||||
|
loaded.add(pid)
|
||||||
|
new.append(lc)
|
||||||
|
|
||||||
|
data["scenario"] = scenario.parent
|
||||||
|
new += cls._db_load(execute, data)
|
||||||
|
data["scenario"] = scenario
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
tab = data["tab"]
|
tab = data["tab"]
|
||||||
|
data["lc"] = self
|
||||||
|
|
||||||
execute(
|
|
||||||
"DELETE FROM lateral_contribution " +
|
|
||||||
f"WHERE pamhyr_id = {self._pamhyr_id}"
|
|
||||||
)
|
|
||||||
execute(
|
execute(
|
||||||
"DELETE FROM lateral_contribution_data " +
|
"DELETE FROM lateral_contribution_data " +
|
||||||
f"WHERE lc = {self._pamhyr_id}"
|
f"WHERE lc = {self._pamhyr_id} " +
|
||||||
|
f"AND scenario = {self._status.scenario_id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
reach = -1
|
reach = -1
|
||||||
|
|
@ -332,35 +415,39 @@ class LateralContribution(SQLSubModel):
|
||||||
begin_section = self._begin_section._pamhyr_id
|
begin_section = self._begin_section._pamhyr_id
|
||||||
end_section = self._end_section._pamhyr_id
|
end_section = self._end_section._pamhyr_id
|
||||||
|
|
||||||
sql = (
|
execute(
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"lateral_contribution(pamhyr_id, name, type, tab, " +
|
"lateral_contribution(" +
|
||||||
"reach, begin_section, end_section) " +
|
"pamhyr_id, deleted, name, type, tab, " +
|
||||||
|
"reach, begin_section, end_section, scenario) " +
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{self.id}, '{self._db_format(self._name)}', " +
|
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
||||||
|
f"'{self._db_format(self._name)}', " +
|
||||||
f"'{self._db_format(self._type)}', '{tab}', {reach}, " +
|
f"'{self._db_format(self._type)}', '{tab}', {reach}, " +
|
||||||
f"{self._begin_rk}, {self._end_rk}" +
|
f"{begin_section}, {end_section}, " +
|
||||||
|
f"{self._status.scenario_id}" +
|
||||||
")"
|
")"
|
||||||
)
|
)
|
||||||
execute(sql)
|
|
||||||
|
|
||||||
ind = 0
|
ind = 0
|
||||||
for d in self._data:
|
for d in self._data:
|
||||||
data0 = self._db_format(str(d[0]))
|
data["ind"] = ind
|
||||||
data1 = self._db_format(str(d[1]))
|
|
||||||
|
d._db_save(execute, data)
|
||||||
|
|
||||||
sql = (
|
|
||||||
"INSERT INTO " +
|
|
||||||
"lateral_contribution_data(ind, data0, data1, lc) " +
|
|
||||||
f"VALUES ({ind}, '{data0}', {data1}, {self.id})"
|
|
||||||
)
|
|
||||||
execute(sql)
|
|
||||||
ind += 1
|
ind += 1
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self._data)
|
return len(
|
||||||
|
list(
|
||||||
|
filter(
|
||||||
|
lambda el: not el.is_deleted(),
|
||||||
|
self._data
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def compatibility(cls):
|
def compatibility(cls):
|
||||||
|
|
@ -392,7 +479,7 @@ class LateralContribution(SQLSubModel):
|
||||||
@name.setter
|
@name.setter
|
||||||
def name(self, name):
|
def name(self, name):
|
||||||
self._name = name
|
self._name = name
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def lctype(self):
|
def lctype(self):
|
||||||
|
|
@ -406,46 +493,45 @@ class LateralContribution(SQLSubModel):
|
||||||
def reach(self, reach):
|
def reach(self, reach):
|
||||||
self._reach = reach
|
self._reach = reach
|
||||||
if reach is not None:
|
if reach is not None:
|
||||||
self._begin_rk = self._reach.reach.get_rk_min()
|
self._begin_section = self._reach.reach.profiles[0]
|
||||||
self._end_rk = self._reach.reach.get_rk_max()
|
self._end_section = self._reach.reach.profiles[-1]
|
||||||
self._status.modified()
|
|
||||||
|
self.modified()
|
||||||
|
|
||||||
def has_reach(self):
|
def has_reach(self):
|
||||||
return self._reach is not None
|
return self._reach is not None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def begin_rk(self):
|
def begin_rk(self):
|
||||||
return self._begin_rk
|
if self._begin_section is None:
|
||||||
|
return 0
|
||||||
|
|
||||||
@begin_rk.setter
|
return self._begin_section.rk
|
||||||
def begin_rk(self, begin_rk):
|
|
||||||
if self._reach is None:
|
|
||||||
self._begin_rk = begin_rk
|
|
||||||
else:
|
|
||||||
_min = self._reach.reach.get_rk_min()
|
|
||||||
_max = self._reach.reach.get_rk_max()
|
|
||||||
|
|
||||||
if _min <= begin_rk <= _max:
|
@property
|
||||||
self._begin_rk = begin_rk
|
def begin_section(self):
|
||||||
|
return self._begin_section
|
||||||
|
|
||||||
self._status.modified()
|
@begin_section.setter
|
||||||
|
def begin_section(self, section):
|
||||||
|
self._begin_section = section
|
||||||
|
self.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def end_rk(self):
|
def end_rk(self):
|
||||||
return self._end_rk
|
if self._end_section is None:
|
||||||
|
return 0
|
||||||
|
|
||||||
@end_rk.setter
|
return self._end_section.rk
|
||||||
def end_rk(self, end_rk):
|
|
||||||
if self._reach is None:
|
|
||||||
self._end_rk = end_rk
|
|
||||||
else:
|
|
||||||
_min = self._reach.reach.get_rk_min()
|
|
||||||
_max = self._reach.reach.get_rk_max()
|
|
||||||
|
|
||||||
if _min <= end_rk <= _max:
|
@property
|
||||||
self._end_rk = end_rk
|
def end_section(self):
|
||||||
|
return self._end_section
|
||||||
|
|
||||||
self._status.modified()
|
@end_section.setter
|
||||||
|
def end_section(self, section):
|
||||||
|
self._end_section = section
|
||||||
|
self.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def header(self):
|
def header(self):
|
||||||
|
|
@ -453,7 +539,12 @@ class LateralContribution(SQLSubModel):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def data(self):
|
def data(self):
|
||||||
return self._data.copy()
|
return list(
|
||||||
|
filter(
|
||||||
|
lambda el: not el.is_deleted(),
|
||||||
|
self._data
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def get_type_column(self, column):
|
def get_type_column(self, column):
|
||||||
if 0 <= column < 2:
|
if 0 <= column < 2:
|
||||||
|
|
@ -487,17 +578,17 @@ class LateralContribution(SQLSubModel):
|
||||||
new_0 = self._types[0](data[0].replace(",", "."))
|
new_0 = self._types[0](data[0].replace(",", "."))
|
||||||
new_1 = self._types[1](data[1].replace(",", "."))
|
new_1 = self._types[1](data[1].replace(",", "."))
|
||||||
|
|
||||||
return Data(new_0, new_1)
|
return Data(new_0, new_1, status=self._status)
|
||||||
|
|
||||||
def add(self, index: int):
|
def add(self, index: int):
|
||||||
value = Data(self._default_0, self._default_1)
|
value = Data(self._default_0, self._default_1, status=self._status)
|
||||||
self._data.insert(index, value)
|
self._data.insert(index, value)
|
||||||
self._status.modified()
|
self.modified()
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def insert(self, index: int, value):
|
def insert(self, index: int, value):
|
||||||
self._data.insert(index, value)
|
self._data.insert(index, value)
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
def delete_i(self, indexes):
|
def delete_i(self, indexes):
|
||||||
self._data = list(
|
self._data = list(
|
||||||
|
|
@ -509,7 +600,7 @@ class LateralContribution(SQLSubModel):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
def delete(self, els):
|
def delete(self, els):
|
||||||
self._data = list(
|
self._data = list(
|
||||||
|
|
@ -518,14 +609,14 @@ class LateralContribution(SQLSubModel):
|
||||||
self.data
|
self.data
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
def sort(self, _reverse=False, key=None):
|
def sort(self, _reverse=False, key=None):
|
||||||
if key is None:
|
if key is None:
|
||||||
self._data.sort(reverse=_reverse)
|
self._data.sort(reverse=_reverse)
|
||||||
else:
|
else:
|
||||||
self._data.sort(reverse=_reverse, key=key)
|
self._data.sort(reverse=_reverse, key=key)
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
def get_i(self, index):
|
def get_i(self, index):
|
||||||
return self.data[index]
|
return self.data[index]
|
||||||
|
|
@ -540,7 +631,7 @@ class LateralContribution(SQLSubModel):
|
||||||
v = self._data[index]
|
v = self._data[index]
|
||||||
v[column] = self._types[column](value)
|
v[column] = self._types[column](value)
|
||||||
self._data[index] = v
|
self._data[index] = v
|
||||||
self._status.modified()
|
self.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)
|
self._set_i_c_v(index, 0, value)
|
||||||
|
|
@ -552,8 +643,8 @@ class LateralContribution(SQLSubModel):
|
||||||
def convert(self, cls):
|
def convert(self, cls):
|
||||||
new = cls(name=self.name, status=self._status)
|
new = cls(name=self.name, status=self._status)
|
||||||
new.reach = self.reach
|
new.reach = self.reach
|
||||||
new.begin_rk = self.begin_rk
|
new.begin_section = self.begin_section
|
||||||
new.end_rk = self.end_rk
|
new.end_section = self.end_section
|
||||||
|
|
||||||
for i, _ in enumerate(self.data):
|
for i, _ in enumerate(self.data):
|
||||||
new.add(i)
|
new.add(i)
|
||||||
|
|
@ -567,7 +658,7 @@ class LateralContribution(SQLSubModel):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.info(e)
|
logger.info(e)
|
||||||
|
|
||||||
self._status.modified()
|
self.modified()
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def move_up(self, index):
|
def move_up(self, index):
|
||||||
|
|
@ -575,11 +666,11 @@ class LateralContribution(SQLSubModel):
|
||||||
next = index - 1
|
next = index - 1
|
||||||
d = self._data
|
d = self._data
|
||||||
d[index], d[next] = d[next], d[index]
|
d[index], d[next] = d[next], d[index]
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
def move_down(self, index):
|
def move_down(self, index):
|
||||||
if index >= 0:
|
if index >= 0:
|
||||||
prev = index + 1
|
prev = index + 1
|
||||||
d = self._data
|
d = self._data
|
||||||
d[index], d[prev] = d[prev], d[index]
|
d[index], d[prev] = d[prev], d[index]
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
from copy import copy
|
from copy import copy
|
||||||
from tools import trace, timer
|
from tools import trace, timer
|
||||||
|
|
||||||
from Model.Tools.PamhyrList import PamhyrModelListWithTab
|
from Model.Tools.PamhyrListExt import PamhyrModelListWithTab
|
||||||
from Model.Except import NotImplementedMethodeError
|
from Model.Except import NotImplementedMethodeError
|
||||||
|
|
||||||
from Model.LateralContribution.LateralContribution import LateralContribution
|
from Model.LateralContribution.LateralContribution import LateralContribution
|
||||||
|
|
@ -50,7 +50,10 @@ class LateralContributionList(PamhyrModelListWithTab):
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def _db_save(self, execute, data=None):
|
def _db_save(self, execute, data=None):
|
||||||
execute("DELETE FROM lateral_contribution")
|
execute(
|
||||||
|
"DELETE FROM lateral_contribution " +
|
||||||
|
f"WHERE scenario = {self._status.scenario_id}"
|
||||||
|
)
|
||||||
|
|
||||||
if data is None:
|
if data is None:
|
||||||
data = {}
|
data = {}
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,12 @@ from Model.LateralContribution.LateralContribution import LateralContribution
|
||||||
|
|
||||||
|
|
||||||
class NotDefined(LateralContribution):
|
class NotDefined(LateralContribution):
|
||||||
def __init__(self, id: int = -1, name: str = "", status=None):
|
def __init__(self, id: int = -1, name: str = "",
|
||||||
super(NotDefined, self).__init__(id=id, name=name, status=status)
|
status=None, owner_scenario=-1):
|
||||||
|
super(NotDefined, self).__init__(
|
||||||
|
id=id, name=name, status=status,
|
||||||
|
owner_scenario=owner_scenario
|
||||||
|
)
|
||||||
|
|
||||||
self._type = "ND"
|
self._type = "ND"
|
||||||
self._header = ["x", "y"]
|
self._header = ["x", "y"]
|
||||||
|
|
@ -34,8 +38,12 @@ class NotDefined(LateralContribution):
|
||||||
|
|
||||||
|
|
||||||
class LateralContrib(LateralContribution):
|
class LateralContrib(LateralContribution):
|
||||||
def __init__(self, id: int = -1, name: str = "", status=None):
|
def __init__(self, id: int = -1, name: str = "",
|
||||||
super(LateralContrib, self).__init__(id=id, name=name, status=status)
|
status=None, owner_scenario=-1):
|
||||||
|
super(LateralContrib, self).__init__(
|
||||||
|
id=id, name=name, status=status,
|
||||||
|
owner_scenario=owner_scenario
|
||||||
|
)
|
||||||
|
|
||||||
self._type = "LC"
|
self._type = "LC"
|
||||||
self._header = ["time", "discharge"]
|
self._header = ["time", "discharge"]
|
||||||
|
|
@ -47,8 +55,12 @@ class LateralContrib(LateralContribution):
|
||||||
|
|
||||||
|
|
||||||
class Rain(LateralContribution):
|
class Rain(LateralContribution):
|
||||||
def __init__(self, id: int = -1, name: str = "", status=None):
|
def __init__(self, id: int = -1, name: str = "",
|
||||||
super(Rain, self).__init__(id=id, name=name, status=status)
|
status=None, owner_scenario=-1):
|
||||||
|
super(Rain, self).__init__(
|
||||||
|
id=id, name=name, status=status,
|
||||||
|
owner_scenario=owner_scenario
|
||||||
|
)
|
||||||
|
|
||||||
self._type = "RA"
|
self._type = "RA"
|
||||||
self._header = ["time", "discharge"]
|
self._header = ["time", "discharge"]
|
||||||
|
|
@ -60,8 +72,12 @@ class Rain(LateralContribution):
|
||||||
|
|
||||||
|
|
||||||
class Evaporation(LateralContribution):
|
class Evaporation(LateralContribution):
|
||||||
def __init__(self, id: int = -1, name: str = "", status=None):
|
def __init__(self, id: int = -1, name: str = "",
|
||||||
super(Evaporation, self).__init__(id=id, name=name, status=status)
|
status=None, owner_scenario=-1):
|
||||||
|
super(Evaporation, self).__init__(
|
||||||
|
id=id, name=name, status=status,
|
||||||
|
owner_scenario=owner_scenario
|
||||||
|
)
|
||||||
|
|
||||||
self._type = "EV"
|
self._type = "EV"
|
||||||
self._header = ["time", "discharge"]
|
self._header = ["time", "discharge"]
|
||||||
|
|
|
||||||
|
|
@ -233,6 +233,8 @@ class SQLSubModel(PamhyrID):
|
||||||
value = value.replace("'", "'")
|
value = value.replace("'", "'")
|
||||||
elif type(value) is bool:
|
elif type(value) is bool:
|
||||||
value = 'TRUE' if value else 'FALSE'
|
value = 'TRUE' if value else 'FALSE'
|
||||||
|
elif value is None:
|
||||||
|
value = "NULL"
|
||||||
return value
|
return value
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
||||||
|
|
@ -241,6 +241,13 @@ class PamhyrModelListWithTab(SQLSubModel):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def set(self, lst, index, new):
|
||||||
|
old = self.get_tab(lst)[index]
|
||||||
|
old.set_as_deleted()
|
||||||
|
|
||||||
|
self._tabs[lst][index] = new
|
||||||
|
self._status.modified()
|
||||||
|
|
||||||
def get(self, lst, index):
|
def get(self, lst, index):
|
||||||
return self.get_tab(lst)[index]
|
return self.get_tab(lst)[index]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,8 @@ class SQL(object):
|
||||||
# Replace ''' by ''' to preserve SQL injection
|
# Replace ''' by ''' to preserve SQL injection
|
||||||
if type(value) is str:
|
if type(value) is str:
|
||||||
value = value.replace("'", "'")
|
value = value.replace("'", "'")
|
||||||
|
elif value is None:
|
||||||
|
value = "NULL"
|
||||||
return value
|
return value
|
||||||
|
|
||||||
@timer
|
@timer
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ class EditLateralContributionWindow(PamhyrWindow):
|
||||||
trad = LCETranslate()
|
trad = LCETranslate()
|
||||||
name = trad[self._pamhyr_name]
|
name = trad[self._pamhyr_name]
|
||||||
if self._data is not None:
|
if self._data is not None:
|
||||||
edge_name = (self._data.edge.name if self._data.edge is not None
|
edge_name = (self._data.reach.name if self._data.reach is not None
|
||||||
else trad['not_associated'])
|
else trad['not_associated'])
|
||||||
name += (
|
name += (
|
||||||
f" - {study.name} " +
|
f" - {study.name} " +
|
||||||
|
|
|
||||||
|
|
@ -89,12 +89,15 @@ class ComboBoxDelegate(QItemDelegate):
|
||||||
elif self._mode == "rk":
|
elif self._mode == "rk":
|
||||||
if self._data is None:
|
if self._data is None:
|
||||||
self.editor.addItems(
|
self.editor.addItems(
|
||||||
["0"]
|
["-"]
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.editor.addItems(
|
self.editor.addItems(
|
||||||
list(
|
list(
|
||||||
map(str, self._data.reach.get_rk())
|
map(
|
||||||
|
lambda p: p.display_name(),
|
||||||
|
self._data.reach.profiles
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
|
@ -111,8 +114,17 @@ class ComboBoxDelegate(QItemDelegate):
|
||||||
self.editor.currentTextChanged.connect(self.currentItemChanged)
|
self.editor.currentTextChanged.connect(self.currentItemChanged)
|
||||||
|
|
||||||
def setModelData(self, editor, model, index):
|
def setModelData(self, editor, model, index):
|
||||||
text = str(editor.currentText())
|
value = str(editor.currentText())
|
||||||
model.setData(index, text)
|
|
||||||
|
if self._mode == "rk":
|
||||||
|
value = next(
|
||||||
|
filter(
|
||||||
|
lambda p: p.display_name() == value,
|
||||||
|
self._data.reach.profiles
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
model.setData(index, value)
|
||||||
editor.close()
|
editor.close()
|
||||||
editor.deleteLater()
|
editor.deleteLater()
|
||||||
|
|
||||||
|
|
@ -150,7 +162,7 @@ class TableModel(PamhyrTableModel):
|
||||||
t = self._lst.get(self._tab, row).lctype
|
t = self._lst.get(self._tab, row).lctype
|
||||||
return self._long_types[t]
|
return self._long_types[t]
|
||||||
elif self._headers[column] == "edge":
|
elif self._headers[column] == "edge":
|
||||||
n = self._lst.get(self._tab, row).edge
|
n = self._lst.get(self._tab, row).reach
|
||||||
if n is None:
|
if n is None:
|
||||||
return self._trad['not_associated']
|
return self._trad['not_associated']
|
||||||
return n.name
|
return n.name
|
||||||
|
|
|
||||||
|
|
@ -53,14 +53,14 @@ class SetBeginCommand(QUndoCommand):
|
||||||
self._lcs = lcs
|
self._lcs = lcs
|
||||||
self._tab = tab
|
self._tab = tab
|
||||||
self._index = index
|
self._index = index
|
||||||
self._old = self._lcs.get(self._tab, self._index).begin_rk
|
self._old = self._lcs.get(self._tab, self._index).begin_section
|
||||||
self._new = float(new_value)
|
self._new = new_value
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
self._lcs.get(self._tab, self._index).begin_rk = float(self._old)
|
self._lcs.get(self._tab, self._index).begin_section = self._old
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
self._lcs.get(self._tab, self._index).begin_rk = float(self._new)
|
self._lcs.get(self._tab, self._index).begin_section = self._new
|
||||||
|
|
||||||
|
|
||||||
class SetEndCommand(QUndoCommand):
|
class SetEndCommand(QUndoCommand):
|
||||||
|
|
@ -70,14 +70,14 @@ class SetEndCommand(QUndoCommand):
|
||||||
self._lcs = lcs
|
self._lcs = lcs
|
||||||
self._tab = tab
|
self._tab = tab
|
||||||
self._index = index
|
self._index = index
|
||||||
self._old = self._lcs.get(self._tab, self._index).end_rk
|
self._old = self._lcs.get(self._tab, self._index).end_section
|
||||||
self._new = float(new_value)
|
self._new = new_value
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
self._lcs.get(self._tab, self._index).end_rk = float(self._old)
|
self._lcs.get(self._tab, self._index).end_section = self._old
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
self._lcs.get(self._tab, self._index).end_rk = float(self._new)
|
self._lcs.get(self._tab, self._index).end_section = self._new
|
||||||
|
|
||||||
|
|
||||||
class SetEdgeCommand(QUndoCommand):
|
class SetEdgeCommand(QUndoCommand):
|
||||||
|
|
@ -87,14 +87,14 @@ class SetEdgeCommand(QUndoCommand):
|
||||||
self._lcs = lcs
|
self._lcs = lcs
|
||||||
self._tab = tab
|
self._tab = tab
|
||||||
self._index = index
|
self._index = index
|
||||||
self._old = self._lcs.get(self._tab, self._index).edge
|
self._old = self._lcs.get(self._tab, self._index).reach
|
||||||
self._new = edge
|
self._new = edge
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
self._lcs.get(self._tab, self._index).edge = self._old
|
self._lcs.get(self._tab, self._index).reach = self._old
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
self._lcs.get(self._tab, self._index).edge = self._new
|
self._lcs.get(self._tab, self._index).reach = self._new
|
||||||
|
|
||||||
|
|
||||||
class SetTypeCommand(QUndoCommand):
|
class SetTypeCommand(QUndoCommand):
|
||||||
|
|
|
||||||
|
|
@ -211,7 +211,7 @@ class LateralContributionWindow(PamhyrWindow):
|
||||||
edge = self._study.river\
|
edge = self._study.river\
|
||||||
.lateral_contribution\
|
.lateral_contribution\
|
||||||
.get(tab, rows[0])\
|
.get(tab, rows[0])\
|
||||||
.edge
|
.reach
|
||||||
if edge:
|
if edge:
|
||||||
data = edge.reach
|
data = edge.reach
|
||||||
lc = self._lcs.get(tab, rows[0])
|
lc = self._lcs.get(tab, rows[0])
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,7 @@ class WidgetInfo(PamhyrWidget):
|
||||||
|
|
||||||
for tab in lc._tabs_list:
|
for tab in lc._tabs_list:
|
||||||
for c in lc.get_tab(tab):
|
for c in lc.get_tab(tab):
|
||||||
if c.edge is not None:
|
if c.reach is not None:
|
||||||
n_lc += 1
|
n_lc += 1
|
||||||
else:
|
else:
|
||||||
n_na_lc += 1
|
n_na_lc += 1
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue