Skip to content

Commit

Permalink
feat: add data model.
Browse files Browse the repository at this point in the history
  • Loading branch information
andoludo committed Aug 6, 2024
1 parent fc2dcba commit 666da2e
Show file tree
Hide file tree
Showing 15 changed files with 3,130 additions and 170 deletions.
1,658 changes: 1,561 additions & 97 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ plotly = "^5.22.0"
json2html = "^1.3.0"
yattag = "^1.15.2"
python-docx = "^1.1.2"
linkml = "^1.8.1"
cruft = "^2.15.0"
rdflib = "^7.0.0"
owlready2 = "^0.46"


[tool.poetry.group.dev.dependencies]
Expand Down
60 changes: 60 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import re
from pathlib import Path
from typing import Set

import docker
import pytest
Expand Down Expand Up @@ -54,6 +56,8 @@
from trano.models.elements.weather import Weather
from trano.topology import Network

OVERWRITE_MODELS = False


def is_success(results: docker.models.containers.ExecResult) -> bool:
return "The simulation finished successfully" in results.output.decode()
Expand Down Expand Up @@ -799,3 +803,59 @@ def building_multiple_internal_walls_ideas() -> Network:
@pytest.fixture
def house_model() -> Network:
return house_model_fixture()


def remove_annotation(model: str) -> str:
for documentation in re.findall(r"Documentation(.*?)</html>", model, re.DOTALL):
model = model.replace(documentation, "").replace("Documentation", "")

model = model.replace(" ", "").replace("\n", "")
for annotation in re.findall(r"annotation(.*?);", model):
model = model.replace(annotation, "").replace("annotation", "")

return model


def remove_common_package(model: str) -> str:
for annotation in re.findall(r"package Common(.*?)end Common;", model, re.DOTALL):
model = (
model.replace(annotation, "")
.replace("package Common", "")
.replace("end Common;", "")
)
return model


def clean_model(model: str, model_name: str) -> set:
if OVERWRITE_MODELS:
path_file = Path(__file__).parent.joinpath("data", f"{model_name}.mo")
with path_file.open("w") as f:
f.write(model)
model = remove_common_package(model)
model_ = remove_annotation(model)
return {
line
for line in set(
model_.replace("record", ";").replace(f"model{model_name}", "").split(";")
)
if "ReaderTMY3weather" not in line
}


def _read(file_name: str) -> Set:
return {
line
for line in set(
remove_annotation(
remove_common_package(
Path(__file__)
.parent.joinpath("data", f"{file_name}.mo")
.read_text()
)
)
.replace("record", ";")
.replace(f"model{file_name}", "")
.split(";")
)
if "ReaderTMY3weather" not in line
}
Loading

0 comments on commit 666da2e

Please sign in to comment.