mirror of https://gitlab.com/pamhyr/pamhyr2
Compare commits
No commits in common. "89a898410fa21b2d4ed27e620ef14ac252972a09" and "a525d8a2b0f8a351896f5fa4f70a05f9b8382a7a" have entirely different histories.
89a898410f
...
a525d8a2b0
|
|
@ -114,70 +114,46 @@ class InitialConditionsAdisTS(SQLSubModel):
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_load(cls, execute, data=None):
|
def _db_load(cls, execute, data=None):
|
||||||
new = []
|
new = []
|
||||||
status = data['status']
|
|
||||||
scenario = data["scenario"]
|
|
||||||
loaded = data['loaded_pid']
|
|
||||||
|
|
||||||
if scenario is None:
|
|
||||||
return new
|
|
||||||
|
|
||||||
table = execute(
|
table = execute(
|
||||||
"SELECT pamhyr_id, pollutant, name, concentration, eg, em, ed, " +
|
"SELECT pamhyr_id, pollutant, name, concentration, eg, em, ed, " +
|
||||||
"enabled, scenario " +
|
"enabled, scenario " +
|
||||||
"FROM initial_conditions_adists " +
|
"FROM initial_conditions_adists"
|
||||||
f"WHERE scenario = {scenario.id} " +
|
|
||||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))})"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if table is not None:
|
if table is not None:
|
||||||
for row in table:
|
for row in table:
|
||||||
it = iter(row)
|
IC_id = row[0]
|
||||||
|
pollutant = row[1]
|
||||||
|
name = row[2]
|
||||||
|
concentration = row[3]
|
||||||
|
eg = row[4]
|
||||||
|
em = row[5]
|
||||||
|
ed = row[6]
|
||||||
|
enabled = (row[7] == 1)
|
||||||
|
|
||||||
pid = next(it)
|
IC = cls(
|
||||||
pollutant = next(it)
|
id=IC_id,
|
||||||
name = next(it)
|
|
||||||
concentration = next(it)
|
|
||||||
eg = next(it)
|
|
||||||
em = next(it)
|
|
||||||
ed = next(it)
|
|
||||||
enabled = (next(it) == 1)
|
|
||||||
owner_scenario = next(it)
|
|
||||||
|
|
||||||
ic = cls(
|
|
||||||
id=pid,
|
|
||||||
name=name,
|
name=name,
|
||||||
status=status,
|
status=data['status']
|
||||||
owner_scenario=owner_scenario
|
|
||||||
)
|
)
|
||||||
|
|
||||||
ic.pollutant = pollutant
|
IC.pollutant = pollutant
|
||||||
ic.concentration = concentration
|
IC.concentration = concentration
|
||||||
ic.eg = eg
|
IC.eg = eg
|
||||||
ic.em = em
|
IC.em = em
|
||||||
ic.ed = ed
|
IC.ed = ed
|
||||||
ic.enabled = enabled
|
IC.enabled = enabled
|
||||||
|
|
||||||
data['ic_default_id'] = pid
|
data['ic_default_id'] = IC_id
|
||||||
ic._data = ICAdisTSSpec._db_load(execute, data)
|
IC._data = ICAdisTSSpec._db_load(execute, data)
|
||||||
|
|
||||||
loaded.add(pid)
|
|
||||||
new.append(IC)
|
new.append(IC)
|
||||||
|
|
||||||
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():
|
execute(f"DELETE FROM initial_conditions_adists WHERE id = {self.id}")
|
||||||
return True
|
|
||||||
|
|
||||||
execute(
|
|
||||||
"DELETE FROM initial_conditions_adists " +
|
|
||||||
f"WHERE pamhyr_id = {self.id} " +
|
|
||||||
f"AND scenario = {self._status.scenario_id}"
|
|
||||||
)
|
|
||||||
|
|
||||||
pollutant = -1
|
pollutant = -1
|
||||||
if self.pollutant is not None:
|
if self.pollutant is not None:
|
||||||
|
|
@ -203,12 +179,11 @@ class InitialConditionsAdisTS(SQLSubModel):
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"initial_conditions_adists(" +
|
"initial_conditions_adists(" +
|
||||||
"pamhyr_id, pollutant, name, concentration, " +
|
"pamhyr_id, pollutant, name, concentration, " +
|
||||||
"eg, em, ed, enabled, scenario" +
|
"eg, em, ed, enabled" +
|
||||||
") " +
|
") " +
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{self.id}, {pollutant}, '{self._db_format(self._name)}', " +
|
f"{self.id}, {pollutant}, '{self._db_format(self._name)}', " +
|
||||||
f"{concentration}, {eg}, {em}, {ed}, {self._enabled}, " +
|
f"{concentration}, {eg}, {em}, {ed}, {self._enabled}" +
|
||||||
f"{self._status.scenario_id}" +
|
|
||||||
")"
|
")"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -217,8 +192,7 @@ class InitialConditionsAdisTS(SQLSubModel):
|
||||||
data['ic_default_id'] = self.id
|
data['ic_default_id'] = self.id
|
||||||
execute(
|
execute(
|
||||||
"DELETE FROM initial_conditions_spec " +
|
"DELETE FROM initial_conditions_spec " +
|
||||||
f"WHERE ic_default = {self.id} " +
|
f"WHERE ic_default = {self.id}"
|
||||||
f"AND scenario = {self._status.scenario_id}"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
for ic_spec in self._data:
|
for ic_spec in self._data:
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,9 @@ logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
class ICAdisTSSpec(SQLSubModel):
|
class ICAdisTSSpec(SQLSubModel):
|
||||||
_sub_classes = []
|
_sub_classes = [
|
||||||
|
]
|
||||||
|
_id_cnt = 0
|
||||||
|
|
||||||
def __init__(self, id: int = -1, name: str = "",
|
def __init__(self, id: int = -1, name: str = "",
|
||||||
status=None):
|
status=None):
|
||||||
|
|
@ -36,6 +38,11 @@ class ICAdisTSSpec(SQLSubModel):
|
||||||
|
|
||||||
self._status = status
|
self._status = status
|
||||||
|
|
||||||
|
if id == -1:
|
||||||
|
self.id = ICAdisTSSpec._id_cnt
|
||||||
|
else:
|
||||||
|
self.id = id
|
||||||
|
|
||||||
self._name_section = name
|
self._name_section = name
|
||||||
self._reach = None
|
self._reach = None
|
||||||
self._start_rk = None
|
self._start_rk = None
|
||||||
|
|
@ -47,6 +54,8 @@ class ICAdisTSSpec(SQLSubModel):
|
||||||
self._rate = None
|
self._rate = None
|
||||||
self._enabled = True
|
self._enabled = True
|
||||||
|
|
||||||
|
ICAdisTSSpec._id_cnt = max(ICAdisTSSpec._id_cnt + 1, self.id)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_create(cls, execute, ext=""):
|
def _db_create(cls, execute, ext=""):
|
||||||
execute(f"""
|
execute(f"""
|
||||||
|
|
@ -80,7 +89,7 @@ class ICAdisTSSpec(SQLSubModel):
|
||||||
if int(release) < 6:
|
if int(release) < 6:
|
||||||
cls._db_create(execute)
|
cls._db_create(execute)
|
||||||
|
|
||||||
elif major == "0" and int(minor) < 2:
|
if major == "0" and int(minor) < 2:
|
||||||
cls._db_update_to_0_2_0(execute, data)
|
cls._db_update_to_0_2_0(execute, data)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
@ -112,44 +121,35 @@ class ICAdisTSSpec(SQLSubModel):
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_load(cls, execute, data=None):
|
def _db_load(cls, execute, data=None):
|
||||||
new = []
|
new = []
|
||||||
status = data['status']
|
|
||||||
reachs = data["edges"]
|
|
||||||
scenario = data["scenario"]
|
|
||||||
loaded = data['loaded_pid']
|
|
||||||
|
|
||||||
if scenario is None:
|
|
||||||
return new
|
|
||||||
|
|
||||||
table = execute(
|
table = execute(
|
||||||
"SELECT id, name, reach, start_rk, end_rk, " +
|
"SELECT id, ic_default, name, reach, start_rk, end_rk, " +
|
||||||
"concentration, eg, em, ed, rate, enabled, scenario " +
|
"concentration, eg, em, ed, rate, enabled " +
|
||||||
"FROM initial_conditions_spec " +
|
"FROM initial_conditions_spec " +
|
||||||
f"WHERE ic_default = {data['ic_default_id']} " +
|
f"WHERE ic_default = {data['ic_default_id']} "
|
||||||
f"AND scenario = {scenario.id} " +
|
|
||||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if table is not None:
|
if table is not None:
|
||||||
for row in table:
|
for row in table:
|
||||||
it = iter(row)
|
id = row[0]
|
||||||
|
name = row[2]
|
||||||
|
reach = row[3]
|
||||||
|
start_rk = row[4]
|
||||||
|
end_rk = row[5]
|
||||||
|
concentration = row[6]
|
||||||
|
eg = row[7]
|
||||||
|
em = row[8]
|
||||||
|
ed = row[9]
|
||||||
|
rate = row[10]
|
||||||
|
enabled = (row[11] == 1)
|
||||||
|
|
||||||
id = next(it)
|
# new_spec = [name, reach, start_rk, end_rk,
|
||||||
name = next(it)
|
# concentration, eg, em, ed, rate, enabled]
|
||||||
reach = next(it)
|
|
||||||
start_rk = next(it)
|
|
||||||
end_rk = next(it)
|
|
||||||
concentration = next(it)
|
|
||||||
eg = next(it)
|
|
||||||
em = next(it)
|
|
||||||
ed = next(it)
|
|
||||||
rate = next(it)
|
|
||||||
enabled = (next(it) == 1)
|
|
||||||
owner_scenario = next(it)
|
|
||||||
|
|
||||||
new_spec = cls(
|
new_spec = cls(
|
||||||
id=id, name=name,
|
id=id,
|
||||||
status=status,
|
name=name,
|
||||||
owner_scenario=owner_scenario
|
status=data['status']
|
||||||
)
|
)
|
||||||
|
|
||||||
new_spec.reach = reach
|
new_spec.reach = reach
|
||||||
|
|
@ -162,35 +162,30 @@ class ICAdisTSSpec(SQLSubModel):
|
||||||
new_spec.rate = rate
|
new_spec.rate = rate
|
||||||
new_spec.enabled = enabled
|
new_spec.enabled = enabled
|
||||||
|
|
||||||
loaded.add(pid)
|
|
||||||
new.append(new_spec)
|
new.append(new_spec)
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
ic_default = data['ic_default_id']
|
ic_default = data['ic_default_id']
|
||||||
|
|
||||||
sql = (
|
sql = (
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"initial_conditions_spec(id, ic_default, name, reach, " +
|
"initial_conditions_spec(id, ic_default, name, reach, " +
|
||||||
"start_rk, end_rk, concentration, eg, em, ed, rate, " +
|
"start_rk, end_rk, concentration, eg, em, ed, rate, enabled) " +
|
||||||
"enabled, scenario) " +
|
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{self.id}, {ic_default}, " +
|
f"{self.id}, " +
|
||||||
|
f"{ic_default}, " +
|
||||||
f"'{self._db_format(self._name_section)}', " +
|
f"'{self._db_format(self._name_section)}', " +
|
||||||
f"{self._reach}, " +
|
f"{self._reach}, " +
|
||||||
f"{self._start_rk}, {self._end_rk}, " +
|
f"{self._start_rk}, " +
|
||||||
|
f"{self._end_rk}, " +
|
||||||
f"{self._concentration}, " +
|
f"{self._concentration}, " +
|
||||||
f"{self._eg}, {self._em}, {self._ed}, " +
|
f"{self._eg}, " +
|
||||||
f"{self._rate}, {self._enabled}, " +
|
f"{self._em}, " +
|
||||||
f"{self._status.scenario_id}" +
|
f"{self._ed}, " +
|
||||||
|
f"{self._rate}, " +
|
||||||
|
f"{self._enabled}" +
|
||||||
")"
|
")"
|
||||||
)
|
)
|
||||||
execute(sql)
|
execute(sql)
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ class LateralContributionAdisTS(SQLSubModel):
|
||||||
self._status = status
|
self._status = status
|
||||||
|
|
||||||
self._pollutant = pollutant
|
self._pollutant = pollutant
|
||||||
self._reach = None
|
self._edge = None
|
||||||
self._begin_rk = 0.0
|
self._begin_rk = 0.0
|
||||||
self._end_rk = 0.0
|
self._end_rk = 0.0
|
||||||
self._data = []
|
self._data = []
|
||||||
|
|
@ -149,7 +149,7 @@ class LateralContributionAdisTS(SQLSubModel):
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_load(cls, execute, data=None):
|
def _db_load(cls, execute, data=None):
|
||||||
new = []
|
new = []
|
||||||
status = data['status']
|
|
||||||
scenario = data["scenario"]
|
scenario = data["scenario"]
|
||||||
loaded = data['loaded_pid']
|
loaded = data['loaded_pid']
|
||||||
|
|
||||||
|
|
@ -157,8 +157,7 @@ class LateralContributionAdisTS(SQLSubModel):
|
||||||
return new
|
return new
|
||||||
|
|
||||||
table = execute(
|
table = execute(
|
||||||
"SELECT pamhyr_id, pollutant, reach, " +
|
"SELECT pamhyr_id, pollutant, reach, begin_rk, end_rk " +
|
||||||
"begin_rk, end_rk, scenario " +
|
|
||||||
"FROM lateral_contribution_adists " +
|
"FROM lateral_contribution_adists " +
|
||||||
f"WHERE scenario = {scenario.id} " +
|
f"WHERE scenario = {scenario.id} " +
|
||||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
|
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
|
||||||
|
|
@ -166,25 +165,15 @@ class LateralContributionAdisTS(SQLSubModel):
|
||||||
|
|
||||||
if table is not None:
|
if table is not None:
|
||||||
for row in table:
|
for row in table:
|
||||||
it = iter(row)
|
|
||||||
|
|
||||||
pid = next(it)
|
|
||||||
pollutant = next(it)
|
|
||||||
reach = next(it)
|
|
||||||
brk = next(it)
|
|
||||||
erk = next(it)
|
|
||||||
owner_scenario = next(it)
|
|
||||||
|
|
||||||
lca = cls(
|
lca = cls(
|
||||||
id=pid,
|
id=row[0],
|
||||||
pollutant=pollutant,
|
pollutant=row[1],
|
||||||
status=status,
|
status=data['status']
|
||||||
owner_scenario=owner_scenario
|
|
||||||
)
|
)
|
||||||
|
|
||||||
lca.reach = reach
|
lca.edge = row[2]
|
||||||
lca.begin_rk = brk
|
lca.begin_rk = row[3]
|
||||||
lca.end_rk = erk
|
lca.end_rk = row[4]
|
||||||
|
|
||||||
values = execute(
|
values = execute(
|
||||||
"SELECT data0, data1 " +
|
"SELECT data0, data1 " +
|
||||||
|
|
@ -196,13 +185,12 @@ class LateralContributionAdisTS(SQLSubModel):
|
||||||
|
|
||||||
# Write data
|
# Write data
|
||||||
for v in values:
|
for v in values:
|
||||||
data0 = lca._types[0](v[1])
|
data0 = lca._types[0](v[0])
|
||||||
data1 = lca._types[1](v[2])
|
data1 = lca._types[1](v[1])
|
||||||
# Replace data at pos ind
|
# Replace data at pos ind
|
||||||
lca._data.append((data0, data1))
|
lca._data.append((data0, data1))
|
||||||
|
|
||||||
loaded.add(pid)
|
new.append(lc)
|
||||||
new.append(lca)
|
|
||||||
|
|
||||||
data["scenario"] = scenario.parent
|
data["scenario"] = scenario.parent
|
||||||
new += cls._db_load(execute, data)
|
new += cls._db_load(execute, data)
|
||||||
|
|
@ -225,7 +213,7 @@ class LateralContributionAdisTS(SQLSubModel):
|
||||||
f"AND scenario = {self._status.scenario_id}"
|
f"AND scenario = {self._status.scenario_id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
execute(
|
sql = (
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"lateral_contribution_adists(id, " +
|
"lateral_contribution_adists(id, " +
|
||||||
"pollutant, reach, begin_rk, end_rk, scenario) " +
|
"pollutant, reach, begin_rk, end_rk, scenario) " +
|
||||||
|
|
@ -235,6 +223,7 @@ class LateralContributionAdisTS(SQLSubModel):
|
||||||
f"{self._status.scenario_id}" +
|
f"{self._status.scenario_id}" +
|
||||||
")"
|
")"
|
||||||
)
|
)
|
||||||
|
execute(sql)
|
||||||
|
|
||||||
for d in self._data:
|
for d in self._data:
|
||||||
data0 = self._db_format(str(d[0]))
|
data0 = self._db_format(str(d[0]))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue