mirror of https://gitlab.com/pamhyr/pamhyr2
Scenario: Clean DB.
parent
914a1f8866
commit
0df4cf0fd5
|
|
@ -30,13 +30,13 @@ class Scenario(SQLSubModel):
|
||||||
_id_cnt = 0
|
_id_cnt = 0
|
||||||
_sub_classes = []
|
_sub_classes = []
|
||||||
|
|
||||||
related_tables = [
|
tables_with_deleted_column = [
|
||||||
# Adists
|
# Adists
|
||||||
"output_rk_adists",
|
"output_rk_adists",
|
||||||
"boundary_condition_adists", "boundary_condition_data_adists",
|
"boundary_condition_adists", "boundary_condition_data_adists",
|
||||||
"lateral_contribution_adists", "lateral_contribution_data_adists",
|
"lateral_contribution_adists", "lateral_contribution_data_adists",
|
||||||
"initial_conditions_adists",
|
"initial_conditions_adists",
|
||||||
"d90_adists", "dif_adists",
|
"d90_adists",
|
||||||
"pollutants", "pollutants_characteristics",
|
"pollutants", "pollutants_characteristics",
|
||||||
# Hydraulic
|
# Hydraulic
|
||||||
"additional_files",
|
"additional_files",
|
||||||
|
|
@ -44,16 +44,21 @@ class Scenario(SQLSubModel):
|
||||||
"lateral_contribution", "lateral_contribution_data",
|
"lateral_contribution", "lateral_contribution_data",
|
||||||
"friction", "stricklers",
|
"friction", "stricklers",
|
||||||
"hydraulic_structures",
|
"hydraulic_structures",
|
||||||
"hydraulic_structures_basic", "hydraulic_structures_basic_value",
|
"hydraulic_structures_basic",
|
||||||
"initial_conditions",
|
"initial_conditions",
|
||||||
"sedimentary_layer", "sedimentary_layer_layer",
|
"sedimentary_layer", "sedimentary_layer_layer",
|
||||||
"reservoir", "reservoir_data",
|
"reservoir", "reservoir_data",
|
||||||
"rep_lines",
|
"rep_lines",
|
||||||
"solver_parameter",
|
|
||||||
"geometry_pointXYZ", "geometry_profileXYZ",
|
"geometry_pointXYZ", "geometry_profileXYZ",
|
||||||
"river_reach", "river_node",
|
"river_reach", "river_node",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
related_tables = tables_with_deleted_column + [
|
||||||
|
"dif_adists",
|
||||||
|
"solver_parameter",
|
||||||
|
"hydraulic_structures_basic_value",
|
||||||
|
]
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
id: int = -1,
|
id: int = -1,
|
||||||
name: str = "",
|
name: str = "",
|
||||||
|
|
@ -210,19 +215,19 @@ class Scenario(SQLSubModel):
|
||||||
|
|
||||||
def get_parent_branch(self):
|
def get_parent_branch(self):
|
||||||
def aux(scenario, acc):
|
def aux(scenario, acc):
|
||||||
if scenario.parent == None:
|
if scenario is None:
|
||||||
return [scenario.id] + acc
|
return acc
|
||||||
|
|
||||||
return aux(scenario.parent, [scenario.id] + acc)
|
return aux(scenario.parent, [scenario.id] + acc)
|
||||||
|
|
||||||
return aux(self, [])
|
return aux(self, [])
|
||||||
|
|
||||||
def drop_deleted_data(self, execute):
|
def drop_deleted_data(self, execute):
|
||||||
tables = self.related_tables
|
tables = self.tables_with_deleted_column
|
||||||
branch = self.get_parent_branch()
|
branch = self.get_parent_branch()
|
||||||
|
|
||||||
for table in tables:
|
for table in tables:
|
||||||
if self.parent == None:
|
if self.parent is None:
|
||||||
execute(
|
execute(
|
||||||
f"DELETE FROM {table} " +
|
f"DELETE FROM {table} " +
|
||||||
f"WHERE scenario = {self.id} " +
|
f"WHERE scenario = {self.id} " +
|
||||||
|
|
@ -242,21 +247,20 @@ class Scenario(SQLSubModel):
|
||||||
)
|
)
|
||||||
""", fetch_one=False
|
""", fetch_one=False
|
||||||
)
|
)
|
||||||
if ids == None or len(ids) == 0:
|
if ids is None or len(ids) == 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"Drop deleted data into '{table}' : {ids}"
|
f"(s{self.id}) Drop deleted data into '{table}' : {ids}"
|
||||||
)
|
)
|
||||||
|
|
||||||
execute(
|
execute(
|
||||||
f"DELETE FROM {table} " +
|
f"DELETE FROM {table} " +
|
||||||
f"WHERE scenario = {self.id} " +
|
f"WHERE scenario = {self.id} " +
|
||||||
f"AND pamhyr_id IN ({', '.join(map(lambda x: str(x[0]), ids))})"
|
"AND pamhyr_id IN " +
|
||||||
|
f"({', '.join(map(lambda x: str(x[0]), ids))})"
|
||||||
)
|
)
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def id(self):
|
def id(self):
|
||||||
return self._id
|
return self._id
|
||||||
|
|
|
||||||
|
|
@ -449,6 +449,11 @@ class Study(SQLModel):
|
||||||
[self.scenarios, self._river],
|
[self.scenarios, self._river],
|
||||||
data=progress
|
data=progress
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Clear DB for each scenarios
|
||||||
|
for scenar in self.scenarios.lst:
|
||||||
|
scenar.drop_deleted_data(self.execute)
|
||||||
|
|
||||||
self.commit()
|
self.commit()
|
||||||
|
|
||||||
def sql_save_request_count(self, *args, **kargs):
|
def sql_save_request_count(self, *args, **kargs):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue