From 564b4a8012815c176cabcb8aef3da02b1e101b86 Mon Sep 17 00:00:00 2001 From: Jonathon Broughton Date: Mon, 13 Nov 2023 04:39:51 +0000 Subject: [PATCH] fixes --- .devcontainer/devcontainer.json | 2 +- .dockerignore | 2 -- .gitignore | 0 Dockerfile | 4 ++- Geometry/clash.py | 20 ++++++------ main.py | 55 ++++++++++++++------------------- poetry.lock | 16 +++++++++- pyproject.toml | 1 + 8 files changed, 54 insertions(+), 46 deletions(-) mode change 100644 => 100755 .gitignore diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 2c79eeb..238d91e 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -6,7 +6,7 @@ "dockerFile": "../Dockerfile", // Use 'postCreateCommand' to run commands after the container is created. - // "postCreateCommand": "poetry install --no-root", + "postCreateCommand": "poetry install --no-root", // Configure tool-specific properties. "customizations": { diff --git a/.dockerignore b/.dockerignore index d44a32f..f5ba8f8 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,8 +4,6 @@ dist/ *.egg-info/ .cache/ *.log -.ruff_cache/ -.venv/ .env/ .git/ Dockerfile copy* \ No newline at end of file diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/Dockerfile b/Dockerfile index bf8dfde..37ff7eb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -246,4 +246,6 @@ COPY . /home/speckle # Using poetry, we generate a list of requirements, save them to requirements.txt, and then use pip to install them RUN poetry export --format requirements.txt --output /home/speckle/requirements.txt --without-hashes && \ - pip install --requirement /home/speckle/requirements.txt \ No newline at end of file + pip install --requirement /home/speckle/requirements.txt + +RUN poetry install --no-root \ No newline at end of file diff --git a/Geometry/clash.py b/Geometry/clash.py index 0cb1e75..1f74562 100644 --- a/Geometry/clash.py +++ b/Geometry/clash.py @@ -15,7 +15,7 @@ from Geometry.mesh import cast def detect_clashes_old( - reference_elements: List[Element], latest_elements: List[Element], _tolerance: float + reference_elements: List[Element], latest_elements: List[Element], _tolerance: float ) -> list[tuple[str, str, float]]: """ Detect clashes between two sets of mesh elements using Pymesh. @@ -46,11 +46,11 @@ def detect_clashes_old( continue intersection = pymesh.boolean( - latest_pymesh, operation="intersection" + latest_pymesh, ref_pymesh, operation="intersection" ) if ( - intersection and intersection.volume > 0 + intersection and intersection.volume > 0 ): # TODO: could tolerance relate to this? severity = intersection.volume / min( ref_pymesh.volume, latest_pymesh.volume @@ -62,7 +62,7 @@ def detect_clashes_old( def check_for_clash( - ref_element: Element, latest_element: Element + ref_element: Element, latest_element: Element ) -> Optional[tuple[Any, Any, Any]]: """ Check for a clash between two elements and calculate the severity of the clash. @@ -82,7 +82,7 @@ def check_for_clash( if not ref_pymesh or not latest_pymesh: continue - intersection = pymesh.boolean(latest_pymesh, operation="intersection") + intersection = pymesh.boolean(latest_pymesh, ref_pymesh, operation="intersection") if intersection and intersection.volume > 0: severity = intersection.volume / min( ref_pymesh.volume, latest_pymesh.volume @@ -92,7 +92,7 @@ def check_for_clash( def detect_clashes( - reference_elements: List[Element], latest_elements: List[Element], _tolerance: float + reference_elements: List[Element], latest_elements: List[Element], _tolerance: float ) -> List[Tuple[str, str, float]]: """ Detect clashes between two sets of mesh elements using parallel processing. @@ -121,10 +121,10 @@ def detect_clashes( def detect_and_report_clashes( - reference_elements: list[Element], - latest_elements: list[Element], - tolerance: float, - automate_context: AutomationContext, + reference_elements: list[Element], + latest_elements: list[Element], + tolerance: float, + automate_context: AutomationContext, ) -> list[tuple[str, str, float]]: clashes = detect_clashes(reference_elements, latest_elements, tolerance) diff --git a/main.py b/main.py index 42d850a..2fe6c64 100644 --- a/main.py +++ b/main.py @@ -36,27 +36,25 @@ class FunctionInputs(AutomateBase): title="Static Model Name", description="Name of the static structural model.", ) - - -tolerance: float = Field( - default=25.0, - title="Tolerance", - description="Specify the tolerance value for the analysis. \ - Negative values relaxes the test, positive values make it more strict.", - readonly=True, -) -tolerance_unit: str = Field( # Using the SpecklePy Units enum here - default=Units.mm, - json_schema_extra={"examples": ["mm", "cm", "m"]}, - title="Tolerance Unit", - description="Unit of the tolerance value.", - readonly=True, -) + tolerance: float = Field( + default=25.0, + title="Tolerance", + description="Specify the tolerance value for the analysis. \ + Negative values relaxes the test, positive values make it more strict.", + readonly=True, + ) + tolerance_unit: str = Field( # Using the SpecklePy Units enum here + default=Units.mm, + json_schema_extra={"examples": ["mm", "cm", "m"]}, + title="Tolerance Unit", + description="Unit of the tolerance value.", + readonly=True, + ) def automate_function( - automate_context: AutomationContext, - function_inputs: FunctionInputs, + automate_context: AutomationContext, + function_inputs: FunctionInputs, ) -> None: """This is an example Speckle Automate function. @@ -129,26 +127,21 @@ def automate_function( speckle_to_element(obj) for obj in latest_displayable_objects ] - # using trimesh library process all these meshes in the form of A vs B - # and get the clashes + tolerance = function_inputs.tolerance clashes = detect_and_report_clashes( reference_mesh_elements, latest_mesh_elements, tolerance, automate_context ) - # all object count - # all reference objects count - # all latest objects count - percentage_reference_objects_clashing = ( - len(set([ref_id for ref_id, latest_id, severity in clashes])) - / len(reference_mesh_elements) - * 100 + len(set([ref_id for ref_id, latest_id, severity in clashes])) + / len(reference_mesh_elements) + * 100 ) percentage_latest_objects_clashing = ( - len(set([latest_id for ref_id, latest_id, severity in clashes])) - / len(latest_mesh_elements) - * 100 + len(set([latest_id for ref_id, latest_id, severity in clashes])) + / len(latest_mesh_elements) + * 100 ) # all clashes count @@ -170,7 +163,7 @@ def automate_function( def get_reference_model( - automate_context: AutomationContext, static_model_name: str + automate_context: AutomationContext, static_model_name: str ) -> Base: # the static reference model will be retrieved from the project using model name stored in the inputs speckle_client = automate_context.speckle_client diff --git a/poetry.lock b/poetry.lock index fe871b5..35a51d6 100644 --- a/poetry.lock +++ b/poetry.lock @@ -796,6 +796,20 @@ tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""} [package.extras] testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] +[[package]] +name = "python-dotenv" +version = "1.0.0" +description = "Read key-value pairs from a .env file and set them as environment variables" +optional = false +python-versions = ">=3.8" +files = [ + {file = "python-dotenv-1.0.0.tar.gz", hash = "sha256:a8df96034aae6d2d50a4ebe8216326c61c3eb64836776504fcca410e5937a3ba"}, + {file = "python_dotenv-1.0.0-py3-none-any.whl", hash = "sha256:f5971a9226b701070a4bf2c38c89e5a3f0d64de8debda981d1db98583009122a"}, +] + +[package.extras] +cli = ["click (>=5.0)"] + [[package]] name = "requests" version = "2.31.0" @@ -1274,4 +1288,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "3abedc1c21df21ba5ab28f1ea6dc49c8a84c768e0f8f155e5c619ca3fd023765" +content-hash = "e4e56818583a9f0fad2adbfbc4dcb2ebaa1fc8f917004477f0e1574237b7850a" diff --git a/pyproject.toml b/pyproject.toml index ff104e3..16cb34b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,6 +15,7 @@ black = "^23.3.0" mypy = "^1.3.0" ruff = "^0.0.271" pytest = "^7.4.2" +python-dotenv = "^1.0.0" [build-system] requires = ["poetry-core"]