diff --git a/.gitignore b/.gitignore index 3d9ceb6..a26cc72 100644 --- a/.gitignore +++ b/.gitignore @@ -73,7 +73,7 @@ instance/ # Scrapy stuff: .scrapy -# Sphinx documentation +# Sphinx reporting docs/_build/ # PyBuilder @@ -142,7 +142,7 @@ venv.bak/ # Rope project settings .ropeproject -# mkdocs documentation +# mkdocs reporting /site # mypy diff --git a/poetry.lock b/poetry.lock index 5dca637..377db05 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1630,41 +1630,52 @@ files = [ [[package]] name = "matplotlib" -version = "3.9.1.post1" +version = "3.9.2" description = "Python plotting package" category = "main" optional = false python-versions = ">=3.9" files = [ - {file = "matplotlib-3.9.1.post1-cp310-cp310-macosx_10_12_x86_64.whl", hash = "sha256:3779ad3e8b72df22b8a622c5796bbcfabfa0069b835412e3c1dec8ee3de92d0c"}, - {file = "matplotlib-3.9.1.post1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:ec400340f8628e8e2260d679078d4e9b478699f386e5cc8094e80a1cb0039c7c"}, - {file = "matplotlib-3.9.1.post1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:82c18791b8862ea095081f745b81f896b011c5a5091678fb33204fef641476af"}, - {file = "matplotlib-3.9.1.post1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:621a628389c09a6b9f609a238af8e66acecece1cfa12febc5fe4195114ba7446"}, - {file = "matplotlib-3.9.1.post1-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:9a54734ca761ebb27cd4f0b6c2ede696ab6861052d7d7e7b8f7a6782665115f5"}, - {file = "matplotlib-3.9.1.post1-cp310-cp310-win_amd64.whl", hash = "sha256:0721f93db92311bb514e446842e2b21c004541dcca0281afa495053e017c5458"}, - {file = "matplotlib-3.9.1.post1-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:b08b46058fe2a31ecb81ef6aa3611f41d871f6a8280e9057cb4016cb3d8e894a"}, - {file = "matplotlib-3.9.1.post1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:22b344e84fcc574f561b5731f89a7625db8ef80cdbb0026a8ea855a33e3429d1"}, - {file = "matplotlib-3.9.1.post1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4b49fee26d64aefa9f061b575f0f7b5fc4663e51f87375c7239efa3d30d908fa"}, - {file = "matplotlib-3.9.1.post1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:89eb7e89e2b57856533c5c98f018aa3254fa3789fcd86d5f80077b9034a54c9a"}, - {file = "matplotlib-3.9.1.post1-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:c06e742bade41fda6176d4c9c78c9ea016e176cd338e62a1686384cb1eb8de41"}, - {file = "matplotlib-3.9.1.post1-cp311-cp311-win_amd64.whl", hash = "sha256:c44edab5b849e0fc1f1c9d6e13eaa35ef65925f7be45be891d9784709ad95561"}, - {file = "matplotlib-3.9.1.post1-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:bf28b09986aee06393e808e661c3466be9c21eff443c9bc881bce04bfbb0c500"}, - {file = "matplotlib-3.9.1.post1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:92aeb8c439d4831510d8b9d5e39f31c16c7f37873879767c26b147cef61e54cd"}, - {file = "matplotlib-3.9.1.post1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f15798b0691b45c80d3320358a88ce5a9d6f518b28575b3ea3ed31b4bd95d009"}, - {file = "matplotlib-3.9.1.post1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d59fc6096da7b9c1df275f9afc3fef5cbf634c21df9e5f844cba3dd8deb1847d"}, - {file = "matplotlib-3.9.1.post1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:ab986817a32a70ce22302438691e7df4c6ee4a844d47289db9d583d873491e0b"}, - {file = "matplotlib-3.9.1.post1-cp312-cp312-win_amd64.whl", hash = "sha256:0d78e7d2d86c4472da105d39aba9b754ed3dfeaeaa4ac7206b82706e0a5362fa"}, - {file = "matplotlib-3.9.1.post1-cp39-cp39-macosx_10_12_x86_64.whl", hash = "sha256:bd07eba6431b4dc9253cce6374a28c415e1d3a7dc9f8aba028ea7592f06fe172"}, - {file = "matplotlib-3.9.1.post1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:ca230cc4482010d646827bd2c6d140c98c361e769ae7d954ebf6fff2a226f5b1"}, - {file = "matplotlib-3.9.1.post1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ace27c0fdeded399cbc43f22ffa76e0f0752358f5b33106ec7197534df08725a"}, - {file = "matplotlib-3.9.1.post1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9a4f3aeb7ba14c497dc6f021a076c48c2e5fbdf3da1e7264a5d649683e284a2f"}, - {file = "matplotlib-3.9.1.post1-cp39-cp39-musllinux_1_2_x86_64.whl", hash = "sha256:23f96fbd4ff4cfa9b8a6b685a65e7eb3c2ced724a8d965995ec5c9c2b1f7daf5"}, - {file = "matplotlib-3.9.1.post1-cp39-cp39-win_amd64.whl", hash = "sha256:2808b95452b4ffa14bfb7c7edffc5350743c31bda495f0d63d10fdd9bc69e895"}, - {file = "matplotlib-3.9.1.post1-pp39-pypy39_pp73-macosx_10_15_x86_64.whl", hash = "sha256:ffc91239f73b4179dec256b01299d46d0ffa9d27d98494bc1476a651b7821cbe"}, - {file = "matplotlib-3.9.1.post1-pp39-pypy39_pp73-macosx_11_0_arm64.whl", hash = "sha256:f965ebca9fd4feaaca45937c4849d92b70653057497181100fcd1e18161e5f29"}, - {file = "matplotlib-3.9.1.post1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:801ee9323fd7b2da0d405aebbf98d1da77ea430bbbbbec6834c0b3af15e5db44"}, - {file = "matplotlib-3.9.1.post1-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:50113e9b43ceb285739f35d43db36aa752fb8154325b35d134ff6e177452f9ec"}, - {file = "matplotlib-3.9.1.post1.tar.gz", hash = "sha256:c91e585c65092c975a44dc9d4239ba8c594ba3c193d7c478b6d178c4ef61f406"}, + {file = "matplotlib-3.9.2-cp310-cp310-macosx_10_12_x86_64.whl", hash = "sha256:9d78bbc0cbc891ad55b4f39a48c22182e9bdaea7fc0e5dbd364f49f729ca1bbb"}, + {file = "matplotlib-3.9.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:c375cc72229614632c87355366bdf2570c2dac01ac66b8ad048d2dabadf2d0d4"}, + {file = "matplotlib-3.9.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1d94ff717eb2bd0b58fe66380bd8b14ac35f48a98e7c6765117fe67fb7684e64"}, + {file = "matplotlib-3.9.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ab68d50c06938ef28681073327795c5db99bb4666214d2d5f880ed11aeaded66"}, + {file = "matplotlib-3.9.2-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:65aacf95b62272d568044531e41de26285d54aec8cb859031f511f84bd8b495a"}, + {file = "matplotlib-3.9.2-cp310-cp310-win_amd64.whl", hash = "sha256:3fd595f34aa8a55b7fc8bf9ebea8aa665a84c82d275190a61118d33fbc82ccae"}, + {file = "matplotlib-3.9.2-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:d8dd059447824eec055e829258ab092b56bb0579fc3164fa09c64f3acd478772"}, + {file = "matplotlib-3.9.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:c797dac8bb9c7a3fd3382b16fe8f215b4cf0f22adccea36f1545a6d7be310b41"}, + {file = "matplotlib-3.9.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d719465db13267bcef19ea8954a971db03b9f48b4647e3860e4bc8e6ed86610f"}, + {file = "matplotlib-3.9.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8912ef7c2362f7193b5819d17dae8629b34a95c58603d781329712ada83f9447"}, + {file = "matplotlib-3.9.2-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:7741f26a58a240f43bee74965c4882b6c93df3e7eb3de160126d8c8f53a6ae6e"}, + {file = "matplotlib-3.9.2-cp311-cp311-win_amd64.whl", hash = "sha256:ae82a14dab96fbfad7965403c643cafe6515e386de723e498cf3eeb1e0b70cc7"}, + {file = "matplotlib-3.9.2-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:ac43031375a65c3196bee99f6001e7fa5bdfb00ddf43379d3c0609bdca042df9"}, + {file = "matplotlib-3.9.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:be0fc24a5e4531ae4d8e858a1a548c1fe33b176bb13eff7f9d0d38ce5112a27d"}, + {file = "matplotlib-3.9.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:bf81de2926c2db243c9b2cbc3917619a0fc85796c6ba4e58f541df814bbf83c7"}, + {file = "matplotlib-3.9.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f6ee45bc4245533111ced13f1f2cace1e7f89d1c793390392a80c139d6cf0e6c"}, + {file = "matplotlib-3.9.2-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:306c8dfc73239f0e72ac50e5a9cf19cc4e8e331dd0c54f5e69ca8758550f1e1e"}, + {file = "matplotlib-3.9.2-cp312-cp312-win_amd64.whl", hash = "sha256:5413401594cfaff0052f9d8b1aafc6d305b4bd7c4331dccd18f561ff7e1d3bd3"}, + {file = "matplotlib-3.9.2-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:18128cc08f0d3cfff10b76baa2f296fc28c4607368a8402de61bb3f2eb33c7d9"}, + {file = "matplotlib-3.9.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:4876d7d40219e8ae8bb70f9263bcbe5714415acfdf781086601211335e24f8aa"}, + {file = "matplotlib-3.9.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6d9f07a80deab4bb0b82858a9e9ad53d1382fd122be8cde11080f4e7dfedb38b"}, + {file = "matplotlib-3.9.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f7c0410f181a531ec4e93bbc27692f2c71a15c2da16766f5ba9761e7ae518413"}, + {file = "matplotlib-3.9.2-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:909645cce2dc28b735674ce0931a4ac94e12f5b13f6bb0b5a5e65e7cea2c192b"}, + {file = "matplotlib-3.9.2-cp313-cp313-win_amd64.whl", hash = "sha256:f32c7410c7f246838a77d6d1eff0c0f87f3cb0e7c4247aebea71a6d5a68cab49"}, + {file = "matplotlib-3.9.2-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:37e51dd1c2db16ede9cfd7b5cabdfc818b2c6397c83f8b10e0e797501c963a03"}, + {file = "matplotlib-3.9.2-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:b82c5045cebcecd8496a4d694d43f9cc84aeeb49fe2133e036b207abe73f4d30"}, + {file = "matplotlib-3.9.2-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f053c40f94bc51bc03832a41b4f153d83f2062d88c72b5e79997072594e97e51"}, + {file = "matplotlib-3.9.2-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:dbe196377a8248972f5cede786d4c5508ed5f5ca4a1e09b44bda889958b33f8c"}, + {file = "matplotlib-3.9.2-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:5816b1e1fe8c192cbc013f8f3e3368ac56fbecf02fb41b8f8559303f24c5015e"}, + {file = "matplotlib-3.9.2-cp39-cp39-macosx_10_12_x86_64.whl", hash = "sha256:cef2a73d06601437be399908cf13aee74e86932a5ccc6ccdf173408ebc5f6bb2"}, + {file = "matplotlib-3.9.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:e0830e188029c14e891fadd99702fd90d317df294c3298aad682739c5533721a"}, + {file = "matplotlib-3.9.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:03ba9c1299c920964e8d3857ba27173b4dbb51ca4bab47ffc2c2ba0eb5e2cbc5"}, + {file = "matplotlib-3.9.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1cd93b91ab47a3616b4d3c42b52f8363b88ca021e340804c6ab2536344fad9ca"}, + {file = "matplotlib-3.9.2-cp39-cp39-musllinux_1_2_x86_64.whl", hash = "sha256:6d1ce5ed2aefcdce11904fc5bbea7d9c21fff3d5f543841edf3dea84451a09ea"}, + {file = "matplotlib-3.9.2-cp39-cp39-win_amd64.whl", hash = "sha256:b2696efdc08648536efd4e1601b5fd491fd47f4db97a5fbfd175549a7365c1b2"}, + {file = "matplotlib-3.9.2-pp39-pypy39_pp73-macosx_10_15_x86_64.whl", hash = "sha256:d52a3b618cb1cbb769ce2ee1dcdb333c3ab6e823944e9a2d36e37253815f9556"}, + {file = "matplotlib-3.9.2-pp39-pypy39_pp73-macosx_11_0_arm64.whl", hash = "sha256:039082812cacd6c6bec8e17a9c1e6baca230d4116d522e81e1f63a74d01d2e21"}, + {file = "matplotlib-3.9.2-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6758baae2ed64f2331d4fd19be38b7b4eae3ecec210049a26b6a4f3ae1c85dcc"}, + {file = "matplotlib-3.9.2-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:050598c2b29e0b9832cde72bcf97627bf00262adbc4a54e2b856426bb2ef0697"}, + {file = "matplotlib-3.9.2.tar.gz", hash = "sha256:96ab43906269ca64a6366934106fa01534454a69e471b7bf3d79083981aaab92"}, ] [package.dependencies] diff --git a/tests/test_documentation.py b/tests/test_reporting.py similarity index 65% rename from tests/test_documentation.py rename to tests/test_reporting.py index b3b1474..6f206ab 100644 --- a/tests/test_documentation.py +++ b/tests/test_reporting.py @@ -1,25 +1,25 @@ import tempfile from pathlib import Path -from trano.documentation.documentation import ( +from trano.reporting.reproting import ( ContentDocumentation, ContentModelDocumentation, ModelDocumentation, ResultFile, ) -from trano.documentation.docx import to_docx -from trano.documentation.html import to_html_documentation +from trano.reporting.docx import to_docx +from trano.reporting.html import to_html_reporting from trano.topology import Network -def test_documentation_buildings_two_rooms_with_storage( +def test_reporting_buildings_two_rooms_with_storage( buildings_two_rooms_with_storage: Network, ) -> None: - documentation = ModelDocumentation.from_network(buildings_two_rooms_with_storage) - assert documentation + reporting = ModelDocumentation.from_network(buildings_two_rooms_with_storage) + assert reporting -def test_documentation_generate_html( +def test_reporting_generate_html( buildings_two_rooms_with_storage: Network, ) -> None: content = ContentModelDocumentation( @@ -39,33 +39,33 @@ def test_documentation_generate_html( conclusions="results", ), ) - documentation = ModelDocumentation.from_network( + reporting = ModelDocumentation.from_network( buildings_two_rooms_with_storage, content ) - html = to_html_documentation(documentation) + html = to_html_reporting(reporting) assert html -def test_documentation_generate_docx( +def test_reporting_generate_docx( buildings_two_rooms_with_storage: Network, ) -> None: - documentation = ModelDocumentation.from_network(buildings_two_rooms_with_storage) + reporting = ModelDocumentation.from_network(buildings_two_rooms_with_storage) with tempfile.NamedTemporaryFile(suffix=".docx") as tmpfile: - document = to_docx(documentation, Path(tmpfile.name)) + document = to_docx(reporting, Path(tmpfile.name)) assert len(document.tables) == 6 assert len(document.inline_shapes) == 0 -def test_documentation_generate_docx_with_figures( +def test_reporting_generate_docx_with_figures( buildings_two_rooms_with_storage: Network, result_data_path: Path ) -> None: - documentation = ModelDocumentation.from_network( + reporting = ModelDocumentation.from_network( buildings_two_rooms_with_storage, result=ResultFile( path=result_data_path, ), ) with tempfile.NamedTemporaryFile(suffix=".docx") as tmpfile: - document = to_docx(documentation, Path(tmpfile.name)) + document = to_docx(reporting, Path(tmpfile.name)) assert len(document.tables) == 6 assert len(document.inline_shapes) == 13 diff --git a/trano/data_models/include.d/dummy_parameters.yaml b/trano/data_models/include.d/dummy_parameters.yaml deleted file mode 100644 index 961966f..0000000 --- a/trano/data_models/include.d/dummy_parameters.yaml +++ /dev/null @@ -1,22 +0,0 @@ -DummyParameters: - attributes: - m_flow_nominal: - description: Nominal mass flow rate for configuration of pressure curve - range: float - ifabsent: float(0.008) - dp_nominal: - description: Nominal pressure head for configuration of pressure curve - range: float - ifabsent: float(10000) - per: - description: Record with performance data - range: string - control_input_type: - description: Control input type - range: string - constant_input_set_point: - description: Constant input set point - range: float - vector_of_input_set_points_corresponding_to_stages: - description: Vector of input set points corresponding to stages - range: string diff --git a/trano/documentation/__init__.py b/trano/documentation/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/trano/elements/__init__.py b/trano/elements/__init__.py index 9544985..1e6d696 100644 --- a/trano/elements/__init__.py +++ b/trano/elements/__init__.py @@ -1,5 +1,5 @@ from trano.elements.base import param_from_config, BaseElement, BaseParameter, Connection, Control, \ - DynamicTemplateCategories, connect, Port + DynamicTemplateCategories, connect, Port, Figure from trano.elements.envelope import ( ExternalDoor, ExternalWall, @@ -24,5 +24,6 @@ Connection, Control, DynamicTemplateCategories, - connect, Port + connect, Port, +Figure ] diff --git a/trano/elements/base.py b/trano/elements/base.py index afd5b01..1fb6f59 100644 --- a/trano/elements/base.py +++ b/trano/elements/base.py @@ -30,12 +30,13 @@ ) from pydantic.fields import computed_field -from trano.controller.parser import ControllerBus -from trano.elements.types import Flow +from trano.elements.types import Flow +from trano.elements.controller_bus import ControllerBus if TYPE_CHECKING: from trano.library.library import Libraries + Boolean = Literal["true", "false"] diff --git a/trano/elements/bus.py b/trano/elements/bus.py index 2791898..625ddf7 100644 --- a/trano/elements/bus.py +++ b/trano/elements/bus.py @@ -4,8 +4,8 @@ import pandas as pd from pydantic import BaseModel, Field, computed_field -from trano.controller.parser import BaseInput from trano.elements.base import BaseElement +from trano.elements.inputs import BaseInput class ValidationData(BaseModel): @@ -42,3 +42,5 @@ def transform_csv_to_table( if data_str.endswith(";"): data_str = data_str[:-1] return ValidationData(data=data_str, columns=data.columns.tolist()) + + diff --git a/trano/controller/parser.py b/trano/elements/controller_bus.py similarity index 73% rename from trano/controller/parser.py rename to trano/elements/controller_bus.py index bab51ab..8874224 100644 --- a/trano/controller/parser.py +++ b/trano/elements/controller_bus.py @@ -1,75 +1,15 @@ import json from pathlib import Path -from typing import TYPE_CHECKING, Any, Dict, List +from typing import List, Dict, Any, TYPE_CHECKING -from pydantic import BaseModel, Field, computed_field - -if TYPE_CHECKING: - - from trano.elements import BaseElement - - -class BaseInput(BaseModel): - name: str - component: str - port: str - multi: bool = False - target: str - input_template: str - default: float | str | int - evaluated_element_name: str = "" - - def __hash__(self) -> int: - return hash((self.name, self.target)) - - def __eq__(self, other: object) -> bool: - return hash(self) == hash(other) - - @computed_field # type: ignore - @property - def input_model(self) -> str: - if self.evaluated_element_name: - return f"""{self.input_template} - {self.name}{self.evaluated_element_name.capitalize()} - (y={self.default});""" - return "" - - -class RealInput(BaseInput): - default: float = 0.0 - target: str = "Space" - input_template: str = "Modelica.Blocks.Sources.RealExpression" +from pydantic import BaseModel, Field -class IntegerInput(BaseInput): - default: int = 0 - target: str = "Space" - input_template: str = "Modelica.Blocks.Sources.IntegerExpression" - - -class BooleanInput(BaseInput): - default: str = "false" - target: str = "Space" - input_template: str = "Modelica.Blocks.Sources.BooleanExpression" - - -class BooleanOutput(BaseInput): - default: str = "false" - target: str = "Controlled" - input_template: str = "Modelica.Blocks.Sources.BooleanExpression" - - -class IntegerOutput(BaseInput): - default: int = 0 - target: str = "Controlled" - input_template: str = "Modelica.Blocks.Sources.IntegerExpression" - - -class RealOutput(BaseInput): - default: float = 0.0 - target: str = "Controlled" - input_template: str = "Modelica.Blocks.Sources.RealExpression" +from trano.elements.inputs import RealInput, RealOutput, IntegerInput, IntegerOutput, BooleanInput, BooleanOutput, \ + BaseInput +if TYPE_CHECKING: + from trano.elements import BaseElement class ControllerBus(BaseModel): template: str = """Controls.BaseClasses.DataBus dataBus @@ -95,7 +35,7 @@ def inputs( | RealOutput | RealInput | BooleanOutput - ]: + ]: return ( self.real_inputs + self.real_outputs diff --git a/trano/elements/inputs.py b/trano/elements/inputs.py new file mode 100644 index 0000000..cb2b871 --- /dev/null +++ b/trano/elements/inputs.py @@ -0,0 +1,63 @@ +from pydantic import BaseModel, computed_field + + +class BaseInput(BaseModel): + name: str + component: str + port: str + multi: bool = False + target: str + input_template: str + default: float | str | int + evaluated_element_name: str = "" + + def __hash__(self) -> int: + return hash((self.name, self.target)) + + def __eq__(self, other: object) -> bool: + return hash(self) == hash(other) + + @computed_field # type: ignore + @property + def input_model(self) -> str: + if self.evaluated_element_name: + return f"""{self.input_template} + {self.name}{self.evaluated_element_name.capitalize()} + (y={self.default});""" + return "" + + +class RealInput(BaseInput): + default: float = 0.0 + target: str = "Space" + input_template: str = "Modelica.Blocks.Sources.RealExpression" + + +class IntegerInput(BaseInput): + default: int = 0 + target: str = "Space" + input_template: str = "Modelica.Blocks.Sources.IntegerExpression" + + +class BooleanInput(BaseInput): + default: str = "false" + target: str = "Space" + input_template: str = "Modelica.Blocks.Sources.BooleanExpression" + + +class BooleanOutput(BaseInput): + default: str = "false" + target: str = "Controlled" + input_template: str = "Modelica.Blocks.Sources.BooleanExpression" + + +class IntegerOutput(BaseInput): + default: int = 0 + target: str = "Controlled" + input_template: str = "Modelica.Blocks.Sources.IntegerExpression" + + +class RealOutput(BaseInput): + default: float = 0.0 + target: str = "Controlled" + input_template: str = "Modelica.Blocks.Sources.RealExpression" diff --git a/trano/controller/__init__.py b/trano/reporting/__init__.py similarity index 100% rename from trano/controller/__init__.py rename to trano/reporting/__init__.py diff --git a/trano/documentation/docx.py b/trano/reporting/docx.py similarity index 97% rename from trano/documentation/docx.py rename to trano/reporting/docx.py index c2c94ce..9d4a9c1 100644 --- a/trano/documentation/docx.py +++ b/trano/reporting/docx.py @@ -10,7 +10,7 @@ from docx.shared import Pt from docx.table import _Cell -from trano.documentation.documentation import ModelDocumentation, Topic, get_description +from trano.reporting.reproting import ModelDocumentation, Topic, get_description from trano.plot.plot import add_element_figures COLUMN_SIZE_WITH_DESCRIPTION = 3 diff --git a/trano/documentation/html.py b/trano/reporting/html.py similarity index 94% rename from trano/documentation/html.py rename to trano/reporting/html.py index b74ee75..818a96e 100644 --- a/trano/documentation/html.py +++ b/trano/reporting/html.py @@ -4,7 +4,7 @@ from pydantic import BaseModel, ConfigDict, Field, model_validator from yattag import Doc, SimpleDoc -from trano.documentation.documentation import BaseDocumentation, ModelDocumentation +from trano.reporting.reproting import BaseDocumentation, ModelDocumentation class HtmlDoc(BaseModel): @@ -61,7 +61,7 @@ def to_html( return html_doc.doc.getvalue() -def to_html_documentation(documentation: ModelDocumentation) -> str: +def to_html_reporting(documentation: ModelDocumentation) -> str: html_doc = HtmlDoc() with html_doc.tag("html"): with html_doc.tag("head"), html_doc.tag("title"): diff --git a/trano/documentation/documentation.py b/trano/reporting/reproting.py similarity index 100% rename from trano/documentation/documentation.py rename to trano/reporting/reproting.py diff --git a/trano/topology.py b/trano/topology.py index 0f584ba..fedd36a 100644 --- a/trano/topology.py +++ b/trano/topology.py @@ -12,9 +12,9 @@ from pyvis.network import Network as PyvisNetwork # type: ignore from tests.constructions.constructions import Constructions -from trano.controller.parser import BaseInput -from trano.documentation.documentation import ModelDocumentation -from trano.documentation.html import to_html_documentation +from trano.elements.inputs import BaseInput +from trano.reporting.reproting import ModelDocumentation +from trano.reporting.html import to_html_reporting from trano.library.library import Library from trano.elements.types import Tilt from trano.elements import ( @@ -459,7 +459,7 @@ def model(self) -> str: library=self.library, databus=data_bus, dynamic_components=self.dynamic_components, - documentation=to_html_documentation(documentation), + documentation=to_html_reporting(documentation), diagram_size=diagram_size, )