Compare commits

..

No commits in common. "914a1f886649543cad25a62fa4f13cf65011277b" and "ea2287215e2fcb15a6bcf91d3679fdb76fa61548" have entirely different histories.

3 changed files with 27 additions and 83 deletions

View File

@ -71,7 +71,7 @@ class Data(SQLSubModel):
major, minor, release = version.strip().split(".") major, minor, release = version.strip().split(".")
created = False created = False
if major == "0" and minor == "0": if major == "0" and int(minor) <= 1:
if int(release) < 7: if int(release) < 7:
cls._db_create(execute) cls._db_create(execute)
created = True created = True
@ -249,7 +249,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
major, minor, release = version.strip().split(".") major, minor, release = version.strip().split(".")
created = False created = False
if major == "0" and minor == "0": if major == "0" and int(minor) <= 1:
if int(release) < 7: if int(release) < 7:
cls._db_create(execute) cls._db_create(execute)
created = True created = True

View File

@ -278,10 +278,8 @@ class PollutantCharacteristics(SQLSubModel):
class Pollutants(SQLSubModel): class Pollutants(SQLSubModel):
_sub_classes = [ _sub_classes = [PollutantCharacteristics,
PollutantCharacteristics, BoundaryConditionAdisTS]
# BoundaryConditionAdisTS
]
def __init__(self, id: int = -1, name: str = "", def __init__(self, id: int = -1, name: str = "",
status=None, owner_scenario=-1): status=None, owner_scenario=-1):

View File

@ -17,43 +17,16 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os import os
import logging
from tools import logger_exception from tools import logger_exception
from Model.Tools.PamhyrDB import SQLSubModel from Model.Tools.PamhyrDB import SQLSubModel
logger = logging.getLogger()
class Scenario(SQLSubModel): class Scenario(SQLSubModel):
_id_cnt = 0 _id_cnt = 0
_sub_classes = [] _sub_classes = []
related_tables = [
# Adists
"output_rk_adists",
"boundary_condition_adists", "boundary_condition_data_adists",
"lateral_contribution_adists", "lateral_contribution_data_adists",
"initial_conditions_adists",
"d90_adists", "dif_adists",
"pollutants", "pollutants_characteristics",
# Hydraulic
"additional_files",
"boundary_condition", "boundary_condition_data",
"lateral_contribution", "lateral_contribution_data",
"friction", "stricklers",
"hydraulic_structures",
"hydraulic_structures_basic", "hydraulic_structures_basic_value",
"initial_conditions",
"sedimentary_layer", "sedimentary_layer_layer",
"reservoir", "reservoir_data",
"rep_lines",
"solver_parameter",
"geometry_pointXYZ", "geometry_profileXYZ",
"river_reach", "river_node",
]
def __init__(self, def __init__(self,
id: int = -1, id: int = -1,
name: str = "", name: str = "",
@ -198,7 +171,29 @@ class Scenario(SQLSubModel):
def drop_all(self, execute): def drop_all(self, execute):
execute(f"DELETE FROM scenario WHERE id = {self.id}") execute(f"DELETE FROM scenario WHERE id = {self.id}")
tables = self.related_tables tables = [
# Adists
"output_rk_adists",
"boundary_condition_adists", "boundary_condition_data_adists",
"lateral_contribution_adists", "lateral_contribution_data_adists",
"initial_conditions_adists",
"d90_adists", "dif_adists",
"pollutants", "pollutants_characteristics",
# Hydraulic
"additional_files",
"boundary_condition", "boundary_condition_data",
"lateral_contribution", "lateral_contribution_data",
"friction", "stricklers",
"hydraulic_structures",
"hydraulic_structures_basic", "hydraulic_structures_basic_value",
"initial_conditions",
"sedimentary_layer", "sedimentary_layer_layer",
"reservoir", "reservoir_data",
"rep_lines",
"solver_parameter",
"geometry_pointXYZ", "geometry_profileXYZ",
"river_reach", "river_node",
]
for table in tables: for table in tables:
execute( execute(
@ -208,55 +203,6 @@ class Scenario(SQLSubModel):
return True return True
def get_parent_branch(self):
def aux(scenario, acc):
if scenario.parent == None:
return [scenario.id] + acc
return aux(scenario.parent, [scenario.id] + acc)
return aux(self, [])
def drop_deleted_data(self, execute):
tables = self.related_tables
branch = self.get_parent_branch()
for table in tables:
if self.parent == None:
execute(
f"DELETE FROM {table} " +
f"WHERE scenario = {self.id} " +
"AND deleted = TRUE"
)
continue
ids = execute(
f"""
SELECT pamhyr_id FROM {table}
WHERE deleted = TRUE
AND scenario = {self.id}
AND pamhyr_id NOT IN (
SELECT pamhyr_id FROM {table}
WHERE scenario IN
({', '.join(map(str, branch[:-1]))})
)
""", fetch_one=False
)
if ids == None or len(ids) == 0:
continue
logger.debug(
f"Drop deleted data into '{table}' : {ids}"
)
execute(
f"DELETE FROM {table} " +
f"WHERE scenario = {self.id} " +
f"AND pamhyr_id IN ({', '.join(map(lambda x: str(x[0]), ids))})"
)
return True
@property @property
def id(self): def id(self):
return self._id return self._id