mirror of https://gitlab.com/pamhyr/pamhyr2
Adists: LC: Prepare update for scenarios.
parent
5a6574921a
commit
c43a26870e
|
|
@ -53,31 +53,42 @@ class LateralContributionAdisTS(SQLSubModel):
|
||||||
self._types = [self.time_convert, float]
|
self._types = [self.time_convert, float]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_create(cls, execute):
|
def _db_create(cls, execute, ext=""):
|
||||||
execute("""
|
cls._db_create_lca(execute, ext)
|
||||||
CREATE TABLE lateral_contribution_adists(
|
cls._db_create_lca_data(execute, ext)
|
||||||
id INTEGER NOT NULL PRIMARY KEY,
|
|
||||||
pollutant INTEGER NOT NULL,
|
|
||||||
edge INTEGER NOT NULL,
|
|
||||||
begin_rk REAL NOT NULL,
|
|
||||||
end_rk REAL NOT NULL,
|
|
||||||
FOREIGN KEY(pollutant) REFERENCES Pollutants(id),
|
|
||||||
FOREIGN KEY(edge) REFERENCES river_reach(id)
|
|
||||||
)
|
|
||||||
""")
|
|
||||||
|
|
||||||
execute("""
|
|
||||||
CREATE TABLE lateral_contribution_data_adists(
|
|
||||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
|
||||||
data0 TEXT NOT NULL,
|
|
||||||
data1 TEXT NOT NULL,
|
|
||||||
lc INTEGER,
|
|
||||||
FOREIGN KEY(lc) REFERENCES lateral_contribution(id)
|
|
||||||
)
|
|
||||||
""")
|
|
||||||
|
|
||||||
return cls._create_submodel(execute)
|
return cls._create_submodel(execute)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _db_create_lca(cls, execute, ext=""):
|
||||||
|
execute(f"""
|
||||||
|
CREATE TABLE lateral_contribution_adists{ext}(
|
||||||
|
{cls.create_db_add_pamhyr_id()},
|
||||||
|
pollutant INTEGER NOT NULL,
|
||||||
|
reach INTEGER NOT NULL,
|
||||||
|
begin_rk REAL NOT NULL,
|
||||||
|
end_rk REAL NOT NULL,
|
||||||
|
{Scenario.create_db_add_scenario()},
|
||||||
|
{Scenario.create_db_add_scenario_fk()},
|
||||||
|
FOREIGN KEY(pollutant) REFERENCES Pollutants(pamhyr_id),
|
||||||
|
FOREIGN KEY(reach) REFERENCES river_reach(pamhyr_id)
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _db_create_lca_data(cls, execute, ext=""):
|
||||||
|
execute(f"""
|
||||||
|
CREATE TABLE lateral_contribution_data_adists{ext}(
|
||||||
|
{cls.create_db_add_pamhyr_id()},
|
||||||
|
data0 TEXT NOT NULL,
|
||||||
|
data1 TEXT NOT NULL,
|
||||||
|
lca INTEGER,
|
||||||
|
{Scenario.create_db_add_scenario()},
|
||||||
|
{Scenario.create_db_add_scenario_fk()},
|
||||||
|
FOREIGN KEY(lca) REFERENCES lateral_contribution_adists(pamhyr_id)
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
@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(".")
|
||||||
|
|
@ -85,8 +96,58 @@ class LateralContributionAdisTS(SQLSubModel):
|
||||||
if int(release) < 7:
|
if int(release) < 7:
|
||||||
cls._db_create(execute)
|
cls._db_create(execute)
|
||||||
|
|
||||||
|
if major == "0" and int(minor) <= 2:
|
||||||
|
if int(release) <= 0:
|
||||||
|
cls._db_update_to_0_2_0(execute, data)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _db_update_to_0_2_0(cls, execute, data):
|
||||||
|
table = "lateral_contribution_adists"
|
||||||
|
reachs = data['id2pid']['river_reach']
|
||||||
|
|
||||||
|
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}_tmp " +
|
||||||
|
"(pamhyr_id, pollutant, reach, begin_rk, end_rk, scenario) " +
|
||||||
|
"SELECT pamhyr_id, pollutant, edge, begin_rk, end_rk, scenario) " +
|
||||||
|
f"FROM {table}"
|
||||||
|
)
|
||||||
|
|
||||||
|
execute(f"DROP TABLE {table}")
|
||||||
|
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||||
|
|
||||||
|
cls._db_update_to_0_2_0_set_reach_pid(execute, table, reachs)
|
||||||
|
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _db_update_to_0_2_0_data(cls, execute, data):
|
||||||
|
table = "lateral_contribution_data_adists"
|
||||||
|
reachs = data['id2pid']['river_reach']
|
||||||
|
|
||||||
|
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||||
|
Scenario.update_db_add_scenario(execute, table)
|
||||||
|
|
||||||
|
cls._db_create_lca_data(execute, ext="_tmp")
|
||||||
|
|
||||||
|
execute(
|
||||||
|
f"INSERT INTO {table}_tmp " +
|
||||||
|
"(pamhyr_id, data0, data1, lca, scenario) " +
|
||||||
|
"SELECT pamhyr_id, data0, data1, lc, scenario) " +
|
||||||
|
f"FROM {table}"
|
||||||
|
)
|
||||||
|
|
||||||
|
execute(f"DROP TABLE {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 = []
|
||||||
|
|
|
||||||
|
|
@ -45,8 +45,14 @@ class LateralContributionsAdisTSList(PamhyrModelList):
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def _db_save(self, execute, data=None):
|
def _db_save(self, execute, data=None):
|
||||||
execute("DELETE FROM lateral_contribution_adists")
|
execute(
|
||||||
execute("DELETE FROM lateral_contribution_data_adists")
|
"DELETE FROM lateral_contribution_adists" +
|
||||||
|
f"WHERE scenario = {self._status.scenario_id}"
|
||||||
|
)
|
||||||
|
execute(
|
||||||
|
"DELETE FROM lateral_contribution_data_adists" +
|
||||||
|
f"WHERE scenario = {self._status.scenario_id}"
|
||||||
|
)
|
||||||
|
|
||||||
if data is None:
|
if data is None:
|
||||||
data = {}
|
data = {}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue