mirror of https://gitlab.com/pamhyr/pamhyr2
Compare commits
No commits in common. "739eb56006883e62c59639a3fdf1fa455717ee79" and "89a898410fa21b2d4ed27e620ef14ac252972a09" have entirely different histories.
739eb56006
...
89a898410f
|
|
@ -147,48 +147,27 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
|||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
status = data['status']
|
||||
nodes = data['nodes']
|
||||
scenario = data["scenario"]
|
||||
loaded = data['loaded_pid']
|
||||
|
||||
if scenario is None:
|
||||
return new
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, pollutant, type, node, scenario " +
|
||||
"FROM boundary_condition_adists " +
|
||||
f"WHERE scenario = {scenario.id} " +
|
||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
|
||||
"SELECT pamhyr_id, pollutant, type, node " +
|
||||
"FROM boundary_condition_adists"
|
||||
)
|
||||
|
||||
if table is not None:
|
||||
for row in table:
|
||||
it = iter(row)
|
||||
|
||||
pid = next(it)
|
||||
pollutant = next(it)
|
||||
bc_type = next(it)
|
||||
node = next(it)
|
||||
owner_scenario = next(it)
|
||||
|
||||
bc = cls(
|
||||
id=pid,
|
||||
pollutant=pollutant,
|
||||
status=status,
|
||||
owner_scenario=owner_scenario
|
||||
id=row[0],
|
||||
pollutant=row[1],
|
||||
status=data['status']
|
||||
)
|
||||
|
||||
bc.type = bc_type
|
||||
bc.type = row[2]
|
||||
|
||||
bc.node = None
|
||||
if row[3] != -1:
|
||||
tmp = next(
|
||||
filter(
|
||||
lambda n: n.id == node, nodes
|
||||
),
|
||||
None
|
||||
)
|
||||
tmp = next(filter(
|
||||
lambda n: n.id == row[3], data["nodes"]),
|
||||
None)
|
||||
if tmp is not None:
|
||||
bc.node = tmp.id
|
||||
else:
|
||||
|
|
@ -197,8 +176,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
|||
values = execute(
|
||||
"SELECT data0, data1 FROM " +
|
||||
"boundary_condition_data_adists " +
|
||||
f"WHERE bc = '{bc.id}' " +
|
||||
f"AND scenario = {scenario.id}"
|
||||
f"WHERE bc = '{bc.id}'"
|
||||
)
|
||||
|
||||
# Write data
|
||||
|
|
@ -208,55 +186,40 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
|||
# Replace data at pos ind
|
||||
bc._data.append((data0, data1))
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(bc)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
new += cls._db_load(execute, data)
|
||||
data["scenario"] = scenario
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
execute(
|
||||
"DELETE FROM boundary_condition_adists " +
|
||||
f"WHERE pamhyr_id = {self.id} " +
|
||||
f"AND scenario = {self._status.scenario_id} "
|
||||
)
|
||||
execute(
|
||||
"DELETE FROM boundary_condition_data_adists " +
|
||||
f"WHERE bc = {self.id} " +
|
||||
f"AND scenario = {self._status.scenario_id} "
|
||||
)
|
||||
execute(f"DELETE FROM boundary_condition_adists WHERE id = {self.id}")
|
||||
execute(f"DELETE FROM boundary_condition_data_adists" +
|
||||
f" WHERE bc = {self.id}")
|
||||
|
||||
node = -1
|
||||
if self._node is not None:
|
||||
node = self._node
|
||||
|
||||
execute(
|
||||
sql = (
|
||||
"INSERT INTO " +
|
||||
"boundary_condition_adists(id, pollutant, type, " +
|
||||
"node, scenario) " +
|
||||
"boundary_condition_adists(id, pollutant, type, node) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, {self._pollutant}, " +
|
||||
f"'{self._db_format(self._type)}', {node}, " +
|
||||
f"{self._status.scenario_id}" +
|
||||
f"'{self._db_format(self._type)}', {node}" +
|
||||
")"
|
||||
)
|
||||
execute(sql)
|
||||
|
||||
for d in self._data:
|
||||
data0 = self._db_format(str(d[0]))
|
||||
data1 = self._db_format(str(d[1]))
|
||||
|
||||
execute(
|
||||
sql = (
|
||||
"INSERT INTO " +
|
||||
"boundary_condition_data_adists(data0, data1, bc, scenario) " +
|
||||
f"VALUES ('{data0}', {data1}, {self.id}, " +
|
||||
f"{self._status.scenario_id})"
|
||||
"boundary_condition_data_adists(data0, data1, bc) " +
|
||||
f"VALUES ('{data0}', {data1}, {self.id})"
|
||||
)
|
||||
execute(sql)
|
||||
|
||||
return True
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,8 @@ class D90AdisTS(SQLSubModel):
|
|||
]
|
||||
|
||||
def __init__(self, id: int = -1, name: str = "default",
|
||||
status=None, owner_scenario=-1):
|
||||
status=None,
|
||||
owner_scenario=-1):
|
||||
super(D90AdisTS, self).__init__(
|
||||
id=id, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
|
|
@ -98,82 +99,59 @@ class D90AdisTS(SQLSubModel):
|
|||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
status = data['status']
|
||||
scenario = data["scenario"]
|
||||
loaded = data['loaded_pid']
|
||||
|
||||
if scenario is None:
|
||||
return new
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, name, d90, enabled, scenario " +
|
||||
"FROM d90_adists " +
|
||||
f"WHERE scenario = {scenario.id} " +
|
||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
|
||||
"SELECT pamhyr_id, name, d90, enabled " +
|
||||
"FROM d90_adists"
|
||||
)
|
||||
|
||||
if table is not None:
|
||||
for row in table:
|
||||
it = iter(row)
|
||||
d90_id = row[0]
|
||||
name = row[1]
|
||||
d90 = row[2]
|
||||
enabled = (row[3] == 1)
|
||||
|
||||
d90_id = next(it)
|
||||
name = next(it)
|
||||
value_d90 = next(it)
|
||||
enabled = (next(it) == 1)
|
||||
owner_scenario = next(it)
|
||||
|
||||
d90 = cls(
|
||||
D90 = cls(
|
||||
id=d90_id,
|
||||
name=name,
|
||||
status=status,
|
||||
owner_scenario=owner_scenario
|
||||
status=data['status']
|
||||
)
|
||||
|
||||
d90.d90 = value_d90
|
||||
d90.enabled = enabled
|
||||
D90.d90 = d90
|
||||
D90.enabled = enabled
|
||||
|
||||
data['d90_default_id'] = d90_id
|
||||
d90._data = d90AdisTSSpec._db_load(execute, data)
|
||||
D90._data = D90AdisTSSpec._db_load(execute, data)
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(d90)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
new += cls._db_load(execute, data)
|
||||
data["scenario"] = scenario
|
||||
new.append(D90)
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
execute(
|
||||
f"DELETE FROM d90_adists " +
|
||||
f"WHERE pamhyr_id = {self.id} " +
|
||||
f"AND scenario = {self._status.scenario_id} "
|
||||
)
|
||||
execute(f"DELETE FROM d90_adists WHERE pamhyr_id = {self.id}")
|
||||
|
||||
d90 = -1.
|
||||
if self.d90 is not None:
|
||||
d90 = self.d90
|
||||
|
||||
execute(
|
||||
sql = (
|
||||
"INSERT INTO " +
|
||||
"d90_adists(" +
|
||||
"pamhyr_id, name, d90, enabled, scenario" +
|
||||
"pamhyr_id, name, d90, enabled" +
|
||||
") " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, '{self._db_format(self._name)}', " +
|
||||
f"{d90}, {self._enabled}, {self._status.scenario_id}" +
|
||||
f"{d90}, {self._enabled}" +
|
||||
")"
|
||||
)
|
||||
|
||||
execute(sql)
|
||||
|
||||
data['d90_default_id'] = self.id
|
||||
execute(
|
||||
"DELETE FROM d90_spec " +
|
||||
f"WHERE d90_default = {self.id} " +
|
||||
f"AND scenario = {self._status.scenario_id} "
|
||||
f"WHERE d90_default = {self.id}"
|
||||
)
|
||||
|
||||
for d90_spec in self._data:
|
||||
|
|
@ -191,7 +169,7 @@ class D90AdisTS(SQLSubModel):
|
|||
@name.setter
|
||||
def name(self, name):
|
||||
self._name = name
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def d90(self):
|
||||
|
|
@ -200,7 +178,7 @@ class D90AdisTS(SQLSubModel):
|
|||
@d90.setter
|
||||
def d90(self, d90):
|
||||
self._d90 = d90
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def enabled(self):
|
||||
|
|
@ -209,12 +187,12 @@ class D90AdisTS(SQLSubModel):
|
|||
@enabled.setter
|
||||
def enabled(self, enabled):
|
||||
self._enabled = enabled
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
||||
def new(self, index):
|
||||
n = D90AdisTSSpec(status=self._status)
|
||||
self._data.insert(index, n)
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
return n
|
||||
|
||||
def delete(self, data):
|
||||
|
|
@ -224,13 +202,13 @@ class D90AdisTS(SQLSubModel):
|
|||
self._data
|
||||
)
|
||||
)
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
||||
def delete_i(self, indexes):
|
||||
for ind in indexes:
|
||||
del self._data[ind]
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
||||
def insert(self, index, data):
|
||||
self._data.insert(index, data)
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
|
|
|||
|
|
@ -33,11 +33,15 @@ class D90AdisTSSpec(SQLSubModel):
|
|||
_id_cnt = 0
|
||||
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
super(D90AdisTSSpec, self).__init__(
|
||||
id=id, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
status=None):
|
||||
super(D90AdisTSSpec, self).__init__()
|
||||
|
||||
self._status = status
|
||||
|
||||
if id == -1:
|
||||
self.id = D90AdisTSSpec._id_cnt
|
||||
else:
|
||||
self.id = id
|
||||
|
||||
self._name_section = name
|
||||
self._reach = None
|
||||
|
|
@ -46,6 +50,8 @@ class D90AdisTSSpec(SQLSubModel):
|
|||
self._d90 = None
|
||||
self._enabled = True
|
||||
|
||||
D90AdisTSSpec._id_cnt = max(D90AdisTSSpec._id_cnt + 1, self.id)
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
|
|
@ -102,40 +108,28 @@ class D90AdisTSSpec(SQLSubModel):
|
|||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
status = data['status']
|
||||
scenario = data["scenario"]
|
||||
loaded = data['loaded_pid']
|
||||
|
||||
if scenario is None:
|
||||
return new
|
||||
|
||||
table = execute(
|
||||
"SELECT id, name, reach, start_rk, end_rk, " +
|
||||
"d90, enabled, scenario " +
|
||||
"FROM d90_adists_spec " +
|
||||
f"WHERE d90_default = {data['d90_default_id']} " +
|
||||
f"AND scenario = {scenario.id} " +
|
||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
|
||||
"SELECT id, d90_default, name, reach, start_rk, end_rk, " +
|
||||
"d90, enabled " +
|
||||
"FROM d90_spec " +
|
||||
f"WHERE d90_default = {data['d90_default_id']} "
|
||||
)
|
||||
|
||||
if table is not None:
|
||||
for row in table:
|
||||
it = iter(row)
|
||||
|
||||
pid = next(it)
|
||||
name = next(it)
|
||||
reach = next(it)
|
||||
start_rk = next(it)
|
||||
end_rk = next(it)
|
||||
d90 = next(it)
|
||||
enabled = (next(it) == 1)
|
||||
owner_scenario = next(it)
|
||||
id = row[0]
|
||||
name = row[2]
|
||||
reach = row[3]
|
||||
start_rk = row[4]
|
||||
end_rk = row[5]
|
||||
d90 = row[6]
|
||||
enabled = (row[7] == 1)
|
||||
|
||||
new_spec = cls(
|
||||
id=pid,
|
||||
id=id,
|
||||
name=name,
|
||||
status=status,
|
||||
owner_scenario=owner_scenario
|
||||
status=data['status']
|
||||
)
|
||||
|
||||
new_spec.reach = reach
|
||||
|
|
@ -144,34 +138,29 @@ class D90AdisTSSpec(SQLSubModel):
|
|||
new_spec.d90 = d90
|
||||
new_spec.enabled = enabled
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(new_spec)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
new += cls._db_load(execute, data)
|
||||
data["scenario"] = scenario
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
d90_default = data['d90_default_id']
|
||||
|
||||
execute(
|
||||
sql = (
|
||||
"INSERT INTO " +
|
||||
"d90_spec(pamhyr_id, d90_default, name, reach, " +
|
||||
"start_rk, end_rk, d90, enabled, scenario) " +
|
||||
"d90_spec(id, d90_default, name, reach, " +
|
||||
"start_rk, end_rk, d90, enabled) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, {d90_default}, " +
|
||||
f"{self.id}, " +
|
||||
f"{d90_default}, " +
|
||||
f"'{self._db_format(self._name_section)}', " +
|
||||
f"{self._reach}, " +
|
||||
f"{self._start_rk}, {self._end_rk}, " +
|
||||
f"{self._d90}, {self._enabled}" +
|
||||
f"{self._status.scenario_id}" +
|
||||
f"{self._start_rk}, " +
|
||||
f"{self._end_rk}, " +
|
||||
f"{self._d90}, " +
|
||||
f"{self._enabled}" +
|
||||
")"
|
||||
)
|
||||
execute(sql)
|
||||
|
||||
return True
|
||||
|
||||
|
|
@ -182,7 +171,7 @@ class D90AdisTSSpec(SQLSubModel):
|
|||
@name.setter
|
||||
def name(self, name):
|
||||
self._name_section = name
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def reach(self):
|
||||
|
|
@ -191,7 +180,7 @@ class D90AdisTSSpec(SQLSubModel):
|
|||
@reach.setter
|
||||
def reach(self, reach):
|
||||
self._reach = reach
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def start_rk(self):
|
||||
|
|
@ -200,7 +189,7 @@ class D90AdisTSSpec(SQLSubModel):
|
|||
@start_rk.setter
|
||||
def start_rk(self, start_rk):
|
||||
self._start_rk = start_rk
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def end_rk(self):
|
||||
|
|
@ -209,7 +198,7 @@ class D90AdisTSSpec(SQLSubModel):
|
|||
@end_rk.setter
|
||||
def end_rk(self, end_rk):
|
||||
self._end_rk = end_rk
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def d90(self):
|
||||
|
|
@ -218,7 +207,7 @@ class D90AdisTSSpec(SQLSubModel):
|
|||
@d90.setter
|
||||
def d90(self, d90):
|
||||
self._d90 = d90
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def enabled(self):
|
||||
|
|
@ -227,4 +216,4 @@ class D90AdisTSSpec(SQLSubModel):
|
|||
@enabled.setter
|
||||
def enabled(self, enabled):
|
||||
self._enabled = enabled
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
|
|
|||
|
|
@ -105,67 +105,43 @@ class DIFAdisTS(SQLSubModel):
|
|||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
status = data['status']
|
||||
scenario = data["scenario"]
|
||||
loaded = data['loaded_pid']
|
||||
|
||||
if scenario is None:
|
||||
return new
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, name, method, dif, b, c, enabled, scenario " +
|
||||
"FROM dif_adists " +
|
||||
f"WHERE scenario = {scenario.id} " +
|
||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
|
||||
"SELECT pamhyr_id, name, method, dif, b, c, enabled " +
|
||||
"FROM dif_adists"
|
||||
)
|
||||
|
||||
if table is not None:
|
||||
for row in table:
|
||||
it = iter(row)
|
||||
dif_id = row[0]
|
||||
name = row[1]
|
||||
method = row[2]
|
||||
dif = row[3]
|
||||
b = row[4]
|
||||
c = row[5]
|
||||
enabled = (row[6] == 1)
|
||||
|
||||
pid = next(it)
|
||||
name = next(it)
|
||||
method = next(it)
|
||||
dif = next(it)
|
||||
b = next(it)
|
||||
c = next(it)
|
||||
enabled = (next(it) == 1)
|
||||
owner_scenario = next(it)
|
||||
|
||||
dif = cls(
|
||||
id=pid,
|
||||
DIF = cls(
|
||||
id=dif_id,
|
||||
name=name,
|
||||
status=status,
|
||||
owner_scenario=owner_scenario,
|
||||
status=data['status']
|
||||
)
|
||||
|
||||
dif.method = method
|
||||
dif.dif = dif
|
||||
dif.b = b
|
||||
dif.c = c
|
||||
dif.enabled = enabled
|
||||
DIF.method = method
|
||||
DIF.dif = dif
|
||||
DIF.b = b
|
||||
DIF.c = c
|
||||
DIF.enabled = enabled
|
||||
|
||||
data['dif_default_id'] = pid
|
||||
dif._data = difAdisTSSpec._db_load(execute, data)
|
||||
data['dif_default_id'] = dif_id
|
||||
DIF._data = DIFAdisTSSpec._db_load(execute, data)
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(dif)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
new += cls._db_load(execute, data)
|
||||
data["scenario"] = scenario
|
||||
new.append(DIF)
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
execute(
|
||||
"DELETE FROM dif_adists " +
|
||||
f"WHERE pamhyr_id = {self.id} " +
|
||||
f"AND scenario = {self._status.scenario_id} "
|
||||
)
|
||||
execute(f"DELETE FROM dif_adists WHERE id = {self.id}")
|
||||
|
||||
method = ""
|
||||
if self.method is not None:
|
||||
|
|
@ -186,13 +162,12 @@ class DIFAdisTS(SQLSubModel):
|
|||
sql = (
|
||||
"INSERT INTO " +
|
||||
"dif_adists(" +
|
||||
"pamhyr_id, name, method, dif, b, c, enabled, scenario" +
|
||||
"pamhyr_id, name, method, dif, b, c, enabled" +
|
||||
") " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, '{self._db_format(self._name)}', " +
|
||||
f"'{self._db_format(self._method)}', " +
|
||||
f"{dif}, {b}, {c}, {self._enabled}" +
|
||||
f"{self._status.scenario_id}" +
|
||||
")"
|
||||
)
|
||||
|
||||
|
|
@ -201,8 +176,7 @@ class DIFAdisTS(SQLSubModel):
|
|||
data['dif_default_id'] = self.id
|
||||
execute(
|
||||
"DELETE FROM dif_adists_spec " +
|
||||
f"WHERE dif_default = {self.id} " +
|
||||
f"AND scenario = {self._status.scenario_id} "
|
||||
f"WHERE dif_default = {self.id}"
|
||||
)
|
||||
|
||||
for dif_spec in self._data:
|
||||
|
|
@ -220,7 +194,7 @@ class DIFAdisTS(SQLSubModel):
|
|||
@name.setter
|
||||
def name(self, name):
|
||||
self._name = name
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def method(self):
|
||||
|
|
@ -229,7 +203,7 @@ class DIFAdisTS(SQLSubModel):
|
|||
@method.setter
|
||||
def method(self, method):
|
||||
self._method = method
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def types(self):
|
||||
|
|
@ -242,7 +216,7 @@ class DIFAdisTS(SQLSubModel):
|
|||
@dif.setter
|
||||
def dif(self, dif):
|
||||
self._dif = dif
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def b(self):
|
||||
|
|
@ -251,7 +225,7 @@ class DIFAdisTS(SQLSubModel):
|
|||
@b.setter
|
||||
def b(self, b):
|
||||
self._b = b
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def c(self):
|
||||
|
|
@ -260,7 +234,7 @@ class DIFAdisTS(SQLSubModel):
|
|||
@c.setter
|
||||
def c(self, c):
|
||||
self._c = c
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def enabled(self):
|
||||
|
|
@ -269,12 +243,12 @@ class DIFAdisTS(SQLSubModel):
|
|||
@enabled.setter
|
||||
def enabled(self, enabled):
|
||||
self._enabled = enabled
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
||||
def new(self, index):
|
||||
n = DIFAdisTSSpec(status=self._status)
|
||||
self._data.insert(index, n)
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
return n
|
||||
|
||||
def delete(self, data):
|
||||
|
|
@ -284,13 +258,13 @@ class DIFAdisTS(SQLSubModel):
|
|||
self._data
|
||||
)
|
||||
)
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
||||
def delete_i(self, indexes):
|
||||
for ind in indexes:
|
||||
del self._data[ind]
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
||||
def insert(self, index, data):
|
||||
self._data.insert(index, data)
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
|
|
|||
|
|
@ -115,42 +115,30 @@ class DIFAdisTSSpec(SQLSubModel):
|
|||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
status = data['status']
|
||||
scenario = data["scenario"]
|
||||
loaded = data['loaded_pid']
|
||||
|
||||
if scenario is None:
|
||||
return new
|
||||
|
||||
table = execute(
|
||||
"SELECT id, method, reach, start_rk, end_rk, " +
|
||||
"dif, b, c, enabled, scenario " +
|
||||
"SELECT id, dif_default, method, reach, start_rk, end_rk, " +
|
||||
"dif, b, c, enabled " +
|
||||
"FROM dif_spec " +
|
||||
f"WHERE dif_default = {data['dif_default_id']} " +
|
||||
f"AND scenario = {scenario.id} " +
|
||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
|
||||
f"WHERE dif_default = {data['dif_default_id']} "
|
||||
)
|
||||
|
||||
if table is not None:
|
||||
for row in table:
|
||||
it = iter(row)
|
||||
|
||||
id = next(it)
|
||||
method = next(it)
|
||||
reach = next(it)
|
||||
start_rk = next(it)
|
||||
end_rk = next(it)
|
||||
dif = next(it)
|
||||
b = next(it)
|
||||
c = next(it)
|
||||
enabled = (next(it) == 1)
|
||||
owner_scenario = next(it)
|
||||
id = row[0]
|
||||
method = row[2]
|
||||
reach = row[3]
|
||||
start_rk = row[4]
|
||||
end_rk = row[5]
|
||||
dif = row[6]
|
||||
b = row[7]
|
||||
c = row[8]
|
||||
enabled = (row[9] == 1)
|
||||
|
||||
new_spec = cls(
|
||||
id=id,
|
||||
method=method,
|
||||
status=status,
|
||||
owner_scenario=owner_scenario
|
||||
status=data['status']
|
||||
)
|
||||
|
||||
new_spec.reach = reach
|
||||
|
|
@ -161,35 +149,31 @@ class DIFAdisTSSpec(SQLSubModel):
|
|||
new_spec.c = c
|
||||
new_spec.enabled = enabled
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(new_spec)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
new += cls._db_load(execute, data)
|
||||
data["scenario"] = scenario
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
dif_default = data['dif_default_id']
|
||||
|
||||
execute(
|
||||
sql = (
|
||||
"INSERT INTO " +
|
||||
"dif_spec(id, dif_default, method, reach, " +
|
||||
"start_rk, end_rk, dif, b, c, enabled, scenario) " +
|
||||
"start_rk, end_rk, dif, b, c, enabled) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, {dif_default}, " +
|
||||
f"{self.id}, " +
|
||||
f"{dif_default}, " +
|
||||
f"'{self._db_format(self._method)}', " +
|
||||
f"{self._reach}, " +
|
||||
f"{self._start_rk}, {self._end_rk}, " +
|
||||
f"{self._dif}, {self._b}, {self._c}, " +
|
||||
f"{self._start_rk}, " +
|
||||
f"{self._end_rk}, " +
|
||||
f"{self._dif}, " +
|
||||
f"{self._b}, " +
|
||||
f"{self._c}, " +
|
||||
f"{self._enabled}" +
|
||||
f"{self._status.scenario_id}" +
|
||||
")"
|
||||
)
|
||||
execute(sql)
|
||||
|
||||
return True
|
||||
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ class InitialConditionsAdisTS(SQLSubModel):
|
|||
"(pamhyr_id, pollutant, name, concentration, " +
|
||||
"eg, em, ed, scenario) " +
|
||||
"SELECT pamhyr_id, pollutant, name, concentration, " +
|
||||
"eg, em, ed, scenario " +
|
||||
"eg, em, ed, scenario) " +
|
||||
f"FROM {table}"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -43,6 +43,8 @@ class OutputRKAdists(SQLSubModel):
|
|||
owner_scenario=owner_scenario
|
||||
)
|
||||
|
||||
self._status = status
|
||||
|
||||
self._reach = reach
|
||||
self._rk = rk
|
||||
self._title = str(title)
|
||||
|
|
@ -129,67 +131,48 @@ class OutputRKAdists(SQLSubModel):
|
|||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
status = data['status']
|
||||
scenario = data["scenario"]
|
||||
loaded = data['loaded_pid']
|
||||
|
||||
# reach = data["reach"]
|
||||
# profile = data["profile"]
|
||||
|
||||
if scenario is None:
|
||||
return new
|
||||
status = data["status"]
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, reach, rk, title, scenario " +
|
||||
"SELECT pamhyr_id, reach, rk, title " +
|
||||
f"FROM OutputRKAdists"
|
||||
)
|
||||
|
||||
if table is not None:
|
||||
for row in table:
|
||||
it = iter(row)
|
||||
|
||||
pid = next(it)
|
||||
id_reach = next(it)
|
||||
id_rk = next(it)
|
||||
title = next(it)
|
||||
owner_scenario = next(it)
|
||||
id = row[0]
|
||||
id_reach = row[1]
|
||||
id_rk = row[2]
|
||||
title = row[3]
|
||||
|
||||
new_output = cls(
|
||||
id=pid, reach=id_reach,
|
||||
id=id, reach=id_reach,
|
||||
rk=id_rk, title=title,
|
||||
status=status,
|
||||
owner_scenario=owner_scenario,
|
||||
status=status
|
||||
)
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(new_output)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
new += cls._db_load(execute, data)
|
||||
data["scenario"] = scenario
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
execute(
|
||||
"DELETE FROM OutputRKAdists " +
|
||||
f"WHERE pamhyr_id = {self.id} " +
|
||||
f"AND scenario = {self._status.scenario_id} "
|
||||
)
|
||||
execute(f"DELETE FROM OutputRKAdists WHERE id = {self.id}")
|
||||
|
||||
execute(
|
||||
sql = (
|
||||
"INSERT INTO " +
|
||||
"OutputRKAdists(pamhyr_id, reach, rk, title, scenario) " +
|
||||
"OutputRKAdists(pamhyr_id, reach, rk, title) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, {self._reach}, {self._rk}, " +
|
||||
f"'{self._db_format(self._title)}'" +
|
||||
f"{self._status.scenario_id}" +
|
||||
")"
|
||||
)
|
||||
|
||||
execute(sql)
|
||||
|
||||
return True
|
||||
|
||||
@property
|
||||
|
|
|
|||
|
|
@ -27,20 +27,20 @@ from tools import (
|
|||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
from Model.Scenario import Scenario
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class Pollutants(SQLSubModel):
|
||||
_sub_classes = []
|
||||
_id_cnt = 0
|
||||
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
status=None,
|
||||
owner_scenario=-1):
|
||||
super(Pollutants, self).__init__(
|
||||
id=id, status=status,
|
||||
owner_scenario=owner_scenario
|
||||
)
|
||||
owner_scenario=owner_scenario)
|
||||
|
||||
self._status = status
|
||||
|
||||
|
|
@ -52,6 +52,9 @@ class Pollutants(SQLSubModel):
|
|||
|
||||
self._data = []
|
||||
|
||||
Pollutants._id_cnt = max(
|
||||
Pollutants._id_cnt + 1, self.id)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._name
|
||||
|
|
@ -66,26 +69,17 @@ class Pollutants(SQLSubModel):
|
|||
return self._data.copy()
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute, ext=""):
|
||||
cls._db_create_pol(execute, ext=ext)
|
||||
cls._db_create_pol_char(execute, ext=ext)
|
||||
|
||||
@classmethod
|
||||
def _db_create_pol(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
CREATE TABLE pollutants{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
name TEXT NOT NULL UNIQUE,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()}
|
||||
def _db_create(cls, execute):
|
||||
execute("""
|
||||
CREATE TABLE Pollutants(
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
name TEXT NOT NULL UNIQUE
|
||||
)
|
||||
""")
|
||||
|
||||
@classmethod
|
||||
def _db_create_pol_char(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
CREATE TABLE pollutants_characteristics{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
execute("""
|
||||
CREATE TABLE Pollutants_characteristics(
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
type INTEGER NOT NULL,
|
||||
diametre REAL NOT NULL,
|
||||
rho REAL NOT NULL,
|
||||
|
|
@ -96,9 +90,7 @@ class Pollutants(SQLSubModel):
|
|||
ac REAL NOT NULL,
|
||||
bc REAL NOT NULL,
|
||||
pollutant INTEGER NOT NULL,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
FOREIGN KEY(pollutant) REFERENCES pollutants(pamhyr_id)
|
||||
FOREIGN KEY(pollutant) REFERENCES Pollutants(id)
|
||||
)
|
||||
""")
|
||||
|
||||
|
|
@ -111,70 +103,17 @@ class Pollutants(SQLSubModel):
|
|||
if int(release) < 7:
|
||||
cls._db_create(execute)
|
||||
|
||||
elif major == "0" and int(minor) < 2:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
cls._db_update_to_0_2_0_char(execute, data)
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "Pollutants"
|
||||
table_new = "pollutants"
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
cls._db_create_lca(execute, ext="_tmp")
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table_new}_tmp " +
|
||||
"(pamhyr_id, name, scenario) " +
|
||||
"SELECT pamhyr_id, name, scenario) " +
|
||||
f"FROM {table}"
|
||||
)
|
||||
|
||||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table_new}_tmp RENAME TO {table_new}")
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_2_0_char(cls, execute, data):
|
||||
table = "Pollutants_characteristics"
|
||||
table_new = "pollutants_characteristics"
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
cls._db_create_lca(execute, ext="_tmp")
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table_new}_tmp " +
|
||||
"(pamhyr_id, type, diametre, rho, porosity, " +
|
||||
"cdc_riv, cdc_cas, apd, ac, bc, pollutant, scenario) " +
|
||||
"SELECT pamhyr_id, type, diametre, rho, porosity, " +
|
||||
"cdc_riv, cdc_cas, apd, ac, bc, pollutant, scenario " +
|
||||
f"FROM {table}"
|
||||
)
|
||||
|
||||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table_new}_tmp RENAME TO {table_new}")
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
|
||||
status = data["status"]
|
||||
scenario = data["scenario"]
|
||||
loaded = data['loaded_pid']
|
||||
|
||||
if scenario is None:
|
||||
return new
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, name FROM pollutants " +
|
||||
f"WHERE scenario = {scenario.id} " +
|
||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))})"
|
||||
|
||||
"SELECT id, name " +
|
||||
f"FROM Pollutants"
|
||||
)
|
||||
|
||||
if table is not None:
|
||||
|
|
@ -190,10 +129,8 @@ class Pollutants(SQLSubModel):
|
|||
new_data = []
|
||||
table = execute(
|
||||
"SELECT * " +
|
||||
"FROM pollutants_characteristics " +
|
||||
f"WHERE pollutant = {id}" +
|
||||
f"AND scenario = {scenario.id} " +
|
||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))})"
|
||||
"FROM Pollutants_characteristics " +
|
||||
f"WHERE pollutant = {id}"
|
||||
)
|
||||
|
||||
if table is not None:
|
||||
|
|
@ -202,49 +139,36 @@ class Pollutants(SQLSubModel):
|
|||
|
||||
new_pollutant._data.append(new_data)
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(new_pollutant)
|
||||
|
||||
data["scenario"] = scenario.parent
|
||||
new += cls._db_load(execute, data)
|
||||
data["scenario"] = scenario
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
execute(
|
||||
"DELETE FROM pollutants " +
|
||||
f"WHERE pamhyr_id = {self.id} " +
|
||||
f"AND scenario = {self._status.scenario_id}"
|
||||
)
|
||||
execute(
|
||||
f"DELETE FROM pollutants_characteristics " +
|
||||
f"WHERE pollutant = {self.id} " +
|
||||
f"AND scenario = {self._status.scenario_id}"
|
||||
)
|
||||
execute(f"DELETE FROM Pollutants WHERE id = {self.id}")
|
||||
execute(f"DELETE FROM Pollutants_characteristics" +
|
||||
f" WHERE pollutant = {self.id}")
|
||||
|
||||
execute(
|
||||
sql = (
|
||||
"INSERT INTO " +
|
||||
"pollutants(id, name, scenario) " +
|
||||
"Pollutants(id, name) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, " +
|
||||
f"'{self._db_format(self._name)}', " +
|
||||
f"{self._status.scenario_id}" +
|
||||
f"'{self._db_format(self._name)}'" +
|
||||
")"
|
||||
)
|
||||
|
||||
execute(sql)
|
||||
|
||||
for d in self._data:
|
||||
execute(
|
||||
sql = (
|
||||
"INSERT INTO " +
|
||||
"pollutants_characteristics(type, diametre, rho, porosity, " +
|
||||
"cdc_riv, cdc_cas, apd, ac, bc, pollutant, scenario) " +
|
||||
"Pollutants_characteristics(type, diametre, rho, porosity, " +
|
||||
"cdc_riv, cdc_cas, apd, ac, bc, pollutant) " +
|
||||
f"VALUES ({d[0]}, {d[1]}, {d[2]},{d[3]}, {d[4]}, "
|
||||
f"{d[5]}, {d[6]}, {d[7]}, {d[8]}, {self.id}, " +
|
||||
f"{self._status.scenario_id})"
|
||||
f"{d[5]}, {d[6]}, {d[7]}, {d[8]}, {self.id})"
|
||||
)
|
||||
execute(sql)
|
||||
|
||||
return True
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue