Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema 300 structure control #384

Merged
merged 16 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ Changelog of threedi-modelchecker
=================================


2.9.1 (unreleased)
2.10.0 (unreleased)
------------------

- Nothing changed yet.
- Adapt modelchecker to work with schema upgrades for structure control (0.224)


2.9.0 (2024-08-01)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies = [
"Click",
"GeoAlchemy2>=0.9,!=0.11.*",
"SQLAlchemy>=1.4",
"threedi-schema==0.223.*"
"threedi-schema==0.224.*"
]

[project.optional-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion threedi_modelchecker/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .model_checks import * # NOQA

# fmt: off
__version__ = '2.9.1.dev0'
__version__ = '2.10.0.dev4'
# fmt: on
136 changes: 72 additions & 64 deletions threedi_modelchecker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2559,88 +2559,96 @@ def is_none_or_empty(col):
]
CHECKS += [FirstTimeSeriesEqualTimestepsCheck(error_code=1206)]

## 122x Structure controls
## 12xx Structure controls

CHECKS += [
ForeignKeyCheck(
error_code=1220,
column=models.ControlMeasureMap.object_id,
column=models.ControlMeasureLocation.object_id,
reference_column=models.ConnectionNode.id,
filters=models.ControlMeasureMap.object_type == "v2_connection_node",
)
]
CHECKS += [
ForeignKeyCheck(
error_code=1221,
column=control_table.target_id,
reference_column=models.Channel.id,
filters=control_table.target_type == "v2_channel",
)
for control_table in (models.ControlMemory, models.ControlTable)
]
CHECKS += [
ForeignKeyCheck(
error_code=1222,
column=control_table.target_id,
reference_column=models.Pipe.id,
filters=control_table.target_type == "v2_pipe",
)
for control_table in (models.ControlMemory, models.ControlTable)
]
CHECKS += [
ForeignKeyCheck(
error_code=1223,
column=control_table.target_id,
reference_column=models.Orifice.id,
filters=control_table.target_type == "v2_orifice",
)
for control_table in (models.ControlMemory, models.ControlTable)
]
CHECKS += [
ForeignKeyCheck(
error_code=1224,
column=control_table.target_id,
reference_column=models.Culvert.id,
filters=control_table.target_type == "v2_culvert",
)
for control_table in (models.ControlMemory, models.ControlTable)
]
CHECKS += [
ForeignKeyCheck(
error_code=1225,
column=control_table.target_id,
reference_column=models.Weir.id,
filters=control_table.target_type == "v2_weir",
)
for control_table in (models.ControlMemory, models.ControlTable)
]
CHECKS += [
ForeignKeyCheck(
error_code=1226,
column=control_table.target_id,
reference_column=models.Pumpstation.id,
filters=control_table.target_type == "v2_pumpstation",
)
for control_table in (models.ControlMemory, models.ControlTable)
]

# 1221 - 1226
ref_cols = [
models.Channel.id,
models.Pipe.id,
models.Orifice.id,
models.Culvert.id,
models.Weir.id,
models.Pumpstation.id,
]
target_types = [
"v2_channel",
"v2_pipe",
"v2_orifice",
"v2_culvert",
"v2_weir",
"v2_pumpstation",
]
for i, (ref_col, target_type) in enumerate(zip(ref_cols, target_types)):
for control_table in (models.ControlMemory, models.ControlTable):
CHECKS += [
ForeignKeyCheck(
error_code=1221 + i,
column=control_table.target_id,
reference_column=ref_col,
filters=control_table.target_type == target_type,
)
]


CHECKS += [
QueryCheck(
error_code=1227,
column=models.Control.id,
invalid=Query(models.Control).filter(
column=models.ControlMeasureMap.id,
invalid=Query(models.ControlMeasureMap).filter(
(
(models.Control.control_type == "memory")
& models.Control.control_id.not_in(Query(models.ControlMemory.id))
(models.ControlMeasureMap.control_type == "memory")
& models.ControlMeasureMap.control_id.not_in(
Query(models.ControlMemory.id)
)
)
| (
(models.Control.control_type == "table")
& models.Control.control_id.not_in(Query(models.ControlTable.id))
(models.ControlMeasureMap.control_type == "table")
& models.ControlMeasureMap.control_id.not_in(
Query(models.ControlTable.id)
)
)
),
message="v2_control.control_id references an id in v2_control_memory or v2_control_table, but the table it references does not contain an entry with that id.",
message="control_measure_map.control_id references an id in memory_control or table_control, but the table it references does not contain an entry with that id.",
)
]

CHECKS += [
ForeignKeyCheck(
error_code=1228,
column=models.ControlMeasureMap.control_measure_location_id,
reference_column=models.ControlMeasureLocation.id,
)
]

# 1230 - 1242
not_null_cols = [
models.ControlMemory.measure_variable,
models.ControlMemory.action_type,
models.ControlMemory.action_value_1,
models.ControlMemory.action_value_2,
models.ControlMemory.target_type,
models.ControlMemory.target_id,
models.ControlTable.action_table,
models.ControlTable.action_type,
models.ControlTable.measure_variable,
models.ControlTable.target_type,
models.ControlMeasureMap.weight,
models.ControlMeasureMap.control_measure_location_id,
models.ControlMeasureLocation.object_id,
]
CHECKS += [
NotNullCheck(error_code=1230 + i, column=col) for i, col in enumerate(not_null_cols)
]


## 018x cross section parameters (continues 008x)
vegetation_parameter_columns = [
models.CrossSectionDefinition.vegetation_drag_coefficients,
Expand Down
39 changes: 5 additions & 34 deletions threedi_modelchecker/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ class Meta:
friction_type = constants.FrictionType.CHEZY


class ControlGroupFactory(factory.alchemy.SQLAlchemyModelFactory):
class Meta:
model = models.ControlGroup
sqlalchemy_session = None


class ConnectionNodeFactory(factory.alchemy.SQLAlchemyModelFactory):
class Meta:
model = models.ConnectionNode
Expand Down Expand Up @@ -248,11 +242,12 @@ class Meta:
sqlalchemy_session = None

action_type = constants.ControlTableActionTypes.set_discharge_coefficients
action_table = "0.0;-1.0;2.0#1.0;-1.1;2.1"
action_table = "0.0,-1.0 2.0\n1.0,-1.1 2.1"
measure_operator = constants.MeasureOperators.greater_than
measure_variable = constants.MeasureVariables.waterlevel
target_type = constants.StructureControlTypes.channel
target_id = 10
geom = "SRID=4326;POINT(-71.064544 42.28787)"


class ControlMemoryFactory(factory.alchemy.SQLAlchemyModelFactory):
Expand All @@ -261,40 +256,16 @@ class Meta:
sqlalchemy_session = None

action_type = constants.ControlTableActionTypes.set_discharge_coefficients
action_value = "0.0 -1.0"
action_value_1 = 0.0
action_value_2 = -1.0
measure_variable = constants.MeasureVariables.waterlevel
target_type = constants.StructureControlTypes.channel
target_id = 10
is_inverse = False
is_active = True
upper_threshold = 1.0
lower_threshold = -1.0


class ControlMeasureGroupFactory(factory.alchemy.SQLAlchemyModelFactory):
class Meta:
model = models.ControlMeasureGroup
sqlalchemy_session = None


class ControlMeasureMapFactory(factory.alchemy.SQLAlchemyModelFactory):
class Meta:
model = models.ControlMeasureMap
sqlalchemy_session = None

object_type = "v2_connection_nodes"
object_id = 101
weight = 0.1


class ControlFactory(factory.alchemy.SQLAlchemyModelFactory):
class Meta:
model = models.Control
sqlalchemy_session = None

start = "0"
end = "300"
measure_frequency = 10
geom = "SRID=4326;POINT(-71.064544 42.28787)"


class CulvertFactory(factory.alchemy.SQLAlchemyModelFactory):
Expand Down
Loading