mirror of https://gitlab.com/pamhyr/pamhyr2
Adists: IC: Fix update for scenario.
parent
6e79fe4cd5
commit
6cce02650b
|
|
@ -78,12 +78,16 @@ class InitialConditionsAdisTS(SQLSubModel):
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_update(cls, execute, version, data=None):
|
def _db_update(cls, execute, version, data=None):
|
||||||
major, minor, release = version.strip().split(".")
|
major, minor, release = version.strip().split(".")
|
||||||
|
created = False
|
||||||
|
|
||||||
if major == "0" and int(minor) <= 1:
|
if major == "0" and int(minor) <= 1:
|
||||||
if int(release) < 6:
|
if int(release) < 6:
|
||||||
cls._db_create(execute)
|
cls._db_create(execute)
|
||||||
|
created = True
|
||||||
|
|
||||||
elif major == "0" and int(minor) < 2:
|
if major == "0" and int(minor) < 2:
|
||||||
cls._db_update_to_0_2_0(execute, data)
|
if not created:
|
||||||
|
cls._db_update_to_0_2_0(execute, data)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
@ -95,22 +99,20 @@ class InitialConditionsAdisTS(SQLSubModel):
|
||||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||||
Scenario.update_db_add_scenario(execute, table)
|
Scenario.update_db_add_scenario(execute, table)
|
||||||
|
|
||||||
cls._db_create_lca(execute, ext="_tmp")
|
cls._db_create(execute, ext="_tmp")
|
||||||
|
|
||||||
execute(
|
execute(
|
||||||
f"INSERT INTO {table}_tmp " +
|
f"INSERT INTO {table}_tmp " +
|
||||||
"(pamhyr_id, pollutant, name, concentration, " +
|
"(pamhyr_id, pollutant, name, concentration, " +
|
||||||
"eg, em, ed, scenario) " +
|
"eg, em, ed, enabled, scenario) " +
|
||||||
"SELECT pamhyr_id, pollutant, name, concentration, " +
|
"SELECT pamhyr_id, pollutant, name, concentration, " +
|
||||||
"eg, em, ed, scenario " +
|
"eg, em, ed, enabled, scenario " +
|
||||||
f"FROM {table}"
|
f"FROM {table}"
|
||||||
)
|
)
|
||||||
|
|
||||||
execute(f"DROP TABLE {table}")
|
execute(f"DROP TABLE {table}")
|
||||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||||
|
|
||||||
cls._db_update_to_0_2_0_set_reach_pid(execute, table, reachs)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_load(cls, execute, data=None):
|
def _db_load(cls, execute, data=None):
|
||||||
new = []
|
new = []
|
||||||
|
|
@ -161,7 +163,7 @@ class InitialConditionsAdisTS(SQLSubModel):
|
||||||
ic._data = ICAdisTSSpec._db_load(execute, data)
|
ic._data = ICAdisTSSpec._db_load(execute, data)
|
||||||
|
|
||||||
loaded.add(pid)
|
loaded.add(pid)
|
||||||
new.append(IC)
|
new.append(ic)
|
||||||
|
|
||||||
data["scenario"] = scenario.parent
|
data["scenario"] = scenario.parent
|
||||||
new += cls._db_load(execute, data)
|
new += cls._db_load(execute, data)
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ class ICAdisTSSpec(SQLSubModel):
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_create(cls, execute, ext=""):
|
def _db_create(cls, execute, ext=""):
|
||||||
execute(f"""
|
execute(f"""
|
||||||
CREATE TABLE initial_conditions_spec{ext}(
|
CREATE TABLE initial_conditions_adists_spec{ext}(
|
||||||
{cls.create_db_add_pamhyr_id()},
|
{cls.create_db_add_pamhyr_id()},
|
||||||
ic_default INTEGER NOT NULL,
|
ic_default INTEGER NOT NULL,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
|
|
@ -76,27 +76,32 @@ class ICAdisTSSpec(SQLSubModel):
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_update(cls, execute, version, data=None):
|
def _db_update(cls, execute, version, data=None):
|
||||||
major, minor, release = version.strip().split(".")
|
major, minor, release = version.strip().split(".")
|
||||||
|
created = False
|
||||||
|
|
||||||
if major == 0 and minor < 1:
|
if major == 0 and minor < 1:
|
||||||
if int(release) < 6:
|
if int(release) < 6:
|
||||||
cls._db_create(execute)
|
cls._db_create(execute)
|
||||||
|
created =True
|
||||||
|
|
||||||
elif major == "0" and int(minor) < 2:
|
if major == "0" and int(minor) < 2:
|
||||||
cls._db_update_to_0_2_0(execute, data)
|
if not created:
|
||||||
|
cls._db_update_to_0_2_0(execute, data)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_update_to_0_2_0(cls, execute, data):
|
def _db_update_to_0_2_0(cls, execute, data):
|
||||||
table = "initial_conditions_spec"
|
table = "initial_conditions_spec"
|
||||||
|
table_new = "initial_conditions_adists_spec"
|
||||||
reachs = data['id2pid']['river_reach']
|
reachs = data['id2pid']['river_reach']
|
||||||
|
|
||||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||||
Scenario.update_db_add_scenario(execute, table)
|
Scenario.update_db_add_scenario(execute, table)
|
||||||
|
|
||||||
cls._db_create_lca(execute, ext="_tmp")
|
cls._db_create(execute, ext="_tmp")
|
||||||
|
|
||||||
execute(
|
execute(
|
||||||
f"INSERT INTO {table}_tmp " +
|
f"INSERT INTO {table_new}_tmp " +
|
||||||
"(pamhyr_id, ic_default, name, reach, start_rk, end_rk, " +
|
"(pamhyr_id, ic_default, name, reach, start_rk, end_rk, " +
|
||||||
"concentration, eg, em, ed, rate, enabled, scenario) " +
|
"concentration, eg, em, ed, rate, enabled, scenario) " +
|
||||||
"SELECT pamhyr_id, ic_default, name, reach, start_rk, end_rk, " +
|
"SELECT pamhyr_id, ic_default, name, reach, start_rk, end_rk, " +
|
||||||
|
|
@ -105,9 +110,9 @@ class ICAdisTSSpec(SQLSubModel):
|
||||||
)
|
)
|
||||||
|
|
||||||
execute(f"DROP TABLE {table}")
|
execute(f"DROP TABLE {table}")
|
||||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
execute(f"ALTER TABLE {table_new}_tmp RENAME TO {table_new}")
|
||||||
|
|
||||||
cls._db_update_to_0_2_0_set_reach_pid(execute, table, reachs)
|
cls._db_update_to_0_2_0_set_reach_pid(execute, table_new, reachs)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_load(cls, execute, data=None):
|
def _db_load(cls, execute, data=None):
|
||||||
|
|
@ -121,9 +126,9 @@ class ICAdisTSSpec(SQLSubModel):
|
||||||
return new
|
return new
|
||||||
|
|
||||||
table = execute(
|
table = execute(
|
||||||
"SELECT id, name, reach, start_rk, end_rk, " +
|
"SELECT pamhyr_id, name, reach, start_rk, end_rk, " +
|
||||||
"concentration, eg, em, ed, rate, enabled, scenario " +
|
"concentration, eg, em, ed, rate, enabled, scenario " +
|
||||||
"FROM initial_conditions_spec " +
|
"FROM initial_conditions_adists_spec " +
|
||||||
f"WHERE ic_default = {data['ic_default_id']} " +
|
f"WHERE ic_default = {data['ic_default_id']} " +
|
||||||
f"AND scenario = {scenario.id} " +
|
f"AND scenario = {scenario.id} " +
|
||||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
|
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
|
||||||
|
|
@ -179,7 +184,7 @@ class ICAdisTSSpec(SQLSubModel):
|
||||||
|
|
||||||
sql = (
|
sql = (
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"initial_conditions_spec(id, ic_default, name, reach, " +
|
"initial_conditions_adists_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, scenario) " +
|
"enabled, scenario) " +
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue