mirror of https://gitlab.com/pamhyr/pamhyr2
Compare commits
3 Commits
ea2287215e
...
914a1f8866
| Author | SHA1 | Date |
|---|---|---|
|
|
914a1f8866 | |
|
|
fa88e05d91 | |
|
|
a6915020cb |
|
|
@ -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 int(minor) <= 1:
|
if major == "0" and minor == "0":
|
||||||
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 int(minor) <= 1:
|
if major == "0" and minor == "0":
|
||||||
if int(release) < 7:
|
if int(release) < 7:
|
||||||
cls._db_create(execute)
|
cls._db_create(execute)
|
||||||
created = True
|
created = True
|
||||||
|
|
|
||||||
|
|
@ -278,8 +278,10 @@ class PollutantCharacteristics(SQLSubModel):
|
||||||
|
|
||||||
|
|
||||||
class Pollutants(SQLSubModel):
|
class Pollutants(SQLSubModel):
|
||||||
_sub_classes = [PollutantCharacteristics,
|
_sub_classes = [
|
||||||
BoundaryConditionAdisTS]
|
PollutantCharacteristics,
|
||||||
|
# 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):
|
||||||
|
|
|
||||||
|
|
@ -17,16 +17,43 @@
|
||||||
# -*- 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 = "",
|
||||||
|
|
@ -171,29 +198,7 @@ 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 = [
|
tables = self.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",
|
|
||||||
]
|
|
||||||
|
|
||||||
for table in tables:
|
for table in tables:
|
||||||
execute(
|
execute(
|
||||||
|
|
@ -203,6 +208,55 @@ 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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue