Adists: D90, DIF: Fix update for scenario.

This commit is contained in:
parouby committed 2025-08-15 14:41:58 +02:00
1 parent 93340a48b1
commit 23a0bc33fa
4 files changed
+35 -19

No files matched your search

+11 -7
View File
@@ -67,12 +67,16 @@ class D90AdisTS(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
@@ -83,7 +87,7 @@ class D90AdisTS(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 " +
@@ -116,14 +120,14 @@ class D90AdisTS(SQLSubModel):
for row in table: for row in table:
it = iter(row) it = iter(row)
d90_id = next(it) pid = next(it)
name = next(it) name = next(it)
value_d90 = next(it) value_d90 = next(it)
enabled = (next(it) == 1) enabled = (next(it) == 1)
owner_scenario = next(it) owner_scenario = next(it)
d90 = cls( d90 = cls(
id=d90_id, id=pid,
name=name, name=name,
status=status, status=status,
owner_scenario=owner_scenario owner_scenario=owner_scenario
@@ -132,8 +136,8 @@ class D90AdisTS(SQLSubModel):
d90.d90 = value_d90 d90.d90 = value_d90
d90.enabled = enabled d90.enabled = enabled
data['d90_default_id'] = d90_id data['d90_default_id'] = pid
d90._data = d90AdisTSSpec._db_load(execute, data) d90._data = D90AdisTSSpec._db_load(execute, data)
loaded.add(pid) loaded.add(pid)
new.append(d90) new.append(d90)
+7 -3
View File
@@ -70,12 +70,16 @@ class D90AdisTSSpec(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
if 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
@@ -87,7 +91,7 @@ class D90AdisTSSpec(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_new}_tmp " + f"INSERT INTO {table_new}_tmp " +
@@ -110,7 +114,7 @@ class D90AdisTSSpec(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, " +
"d90, enabled, scenario " + "d90, enabled, scenario " +
"FROM d90_adists_spec " + "FROM d90_adists_spec " +
f"WHERE d90_default = {data['d90_default_id']} " + f"WHERE d90_default = {data['d90_default_id']} " +
+8 -4
View File
@@ -74,12 +74,16 @@ class DIFAdisTS(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
@@ -90,7 +94,7 @@ class DIFAdisTS(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 " +
@@ -146,7 +150,7 @@ class DIFAdisTS(SQLSubModel):
dif.enabled = enabled dif.enabled = enabled
data['dif_default_id'] = pid data['dif_default_id'] = pid
dif._data = difAdisTSSpec._db_load(execute, data) dif._data = DIFAdisTSSpec._db_load(execute, data)
loaded.add(pid) loaded.add(pid)
new.append(dif) new.append(dif)
+9 -5
View File
@@ -80,12 +80,16 @@ class DIFAdisTSSpec(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
if 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
@@ -98,7 +102,7 @@ class DIFAdisTSSpec(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_new}_tmp " + f"INSERT INTO {table_new}_tmp " +
@@ -123,9 +127,9 @@ class DIFAdisTSSpec(SQLSubModel):
return new return new
table = execute( table = execute(
"SELECT id, method, reach, start_rk, end_rk, " + "SELECT pamhyr_id, method, reach, start_rk, end_rk, " +
"dif, b, c, enabled, scenario " + "dif, b, c, enabled, scenario " +
"FROM dif_spec " + "FROM dif_adists_spec " +
f"WHERE dif_default = {data['dif_default_id']} " + f"WHERE dif_default = {data['dif_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))}) "
@@ -178,7 +182,7 @@ class DIFAdisTSSpec(SQLSubModel):
execute( execute(
"INSERT INTO " + "INSERT INTO " +
"dif_spec(id, dif_default, method, reach, " + "dif_adists_spec(pamhyr_id, dif_default, method, reach, " +
"start_rk, end_rk, dif, b, c, enabled, scenario) " + "start_rk, end_rk, dif, b, c, enabled, scenario) " +
"VALUES (" + "VALUES (" +
f"{self.id}, {dif_default}, " + f"{self.id}, {dif_default}, " +