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(".")
|
||||
created = False
|
||||
|
||||
if major == "0" and int(minor) <= 1:
|
||||
if major == "0" and minor == "0":
|
||||
if int(release) < 7:
|
||||
cls._db_create(execute)
|
||||
created = True
|
||||
|
|
@ -249,7 +249,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
|||
major, minor, release = version.strip().split(".")
|
||||
created = False
|
||||
|
||||
if major == "0" and int(minor) <= 1:
|
||||
if major == "0" and minor == "0":
|
||||
if int(release) < 7:
|
||||
cls._db_create(execute)
|
||||
created = True
|
||||
|
|
|
|||
|
|
@ -278,8 +278,10 @@ class PollutantCharacteristics(SQLSubModel):
|
|||
|
||||
|
||||
class Pollutants(SQLSubModel):
|
||||
_sub_classes = [PollutantCharacteristics,
|
||||
BoundaryConditionAdisTS]
|
||||
_sub_classes = [
|
||||
PollutantCharacteristics,
|
||||
# BoundaryConditionAdisTS
|
||||
]
|
||||
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
|
|
|
|||
|
|
@ -17,16 +17,43 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import logging
|
||||
|
||||
from tools import logger_exception
|
||||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class Scenario(SQLSubModel):
|
||||
_id_cnt = 0
|
||||
_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,
|
||||
id: int = -1,
|
||||
name: str = "",
|
||||
|
|
@ -171,29 +198,7 @@ class Scenario(SQLSubModel):
|
|||
def drop_all(self, execute):
|
||||
execute(f"DELETE FROM scenario WHERE id = {self.id}")
|
||||
|
||||
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",
|
||||
]
|
||||
tables = self.related_tables
|
||||
|
||||
for table in tables:
|
||||
execute(
|
||||
|
|
@ -203,6 +208,55 @@ class Scenario(SQLSubModel):
|
|||
|
||||
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
|
||||
def id(self):
|
||||
return self._id
|
||||
|
|
|
|||
Loading…
Reference in New Issue