mirror of https://gitlab.com/pamhyr/pamhyr2
Compare commits
3 Commits
914a1f8866
...
5ce94a63d3
| Author | SHA1 | Date |
|---|---|---|
|
|
5ce94a63d3 | |
|
|
42ea50d62e | |
|
|
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,21 @@ 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:
|
||||||
|
# This scenario is the default scenario, so we can
|
||||||
|
# delete all data marked as deleted
|
||||||
execute(
|
execute(
|
||||||
f"DELETE FROM {table} " +
|
f"DELETE FROM {table} " +
|
||||||
f"WHERE scenario = {self.id} " +
|
f"WHERE scenario = {self.id} " +
|
||||||
|
|
@ -230,6 +237,8 @@ class Scenario(SQLSubModel):
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# Select pamhyr_id for each deleted data in this scenario
|
||||||
|
# who do not exists into parents scenarios
|
||||||
ids = execute(
|
ids = execute(
|
||||||
f"""
|
f"""
|
||||||
SELECT pamhyr_id FROM {table}
|
SELECT pamhyr_id FROM {table}
|
||||||
|
|
@ -242,21 +251,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,13 @@ 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)
|
||||||
|
|
||||||
|
progress()
|
||||||
|
|
||||||
self.commit()
|
self.commit()
|
||||||
|
|
||||||
def sql_save_request_count(self, *args, **kargs):
|
def sql_save_request_count(self, *args, **kargs):
|
||||||
|
|
@ -459,7 +466,7 @@ class Study(SQLModel):
|
||||||
[self.scenarios, self._river]
|
[self.scenarios, self._river]
|
||||||
)
|
)
|
||||||
logger.debug(cnt)
|
logger.debug(cnt)
|
||||||
return cnt + 7
|
return cnt + 8
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""Close db connection
|
"""Close db connection
|
||||||
|
|
@ -518,7 +525,8 @@ class Study(SQLModel):
|
||||||
data["study"] = self
|
data["study"] = self
|
||||||
river._db_load_results(sql_exec, data=data)
|
river._db_load_results(sql_exec, data=data)
|
||||||
|
|
||||||
self._river_scenario_cache[scenario] = river
|
# FIXME: Disable scenario cache to save memory usage
|
||||||
|
# self._river_scenario_cache[scenario] = river
|
||||||
self.status.scenario = old_scenario
|
self.status.scenario = old_scenario
|
||||||
|
|
||||||
return river
|
return river
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue