Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jsdbroughton committed Nov 13, 2023
1 parent 564b4a8 commit 2396810
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 25 deletions.
3 changes: 3 additions & 0 deletions Geometry/clash.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def check_for_clash(
continue

intersection = pymesh.boolean(latest_pymesh, ref_pymesh, operation="intersection")

print(f"intersection: {intersection}")

if intersection and intersection.volume > 0:
severity = intersection.volume / min(
ref_pymesh.volume, latest_pymesh.volume
Expand Down
6 changes: 5 additions & 1 deletion Geometry/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ def volume(self):
return 0

@staticmethod
def boolean(_other, _operation):
def boolean(mesh_a, mesh_b, operation):
return mypymesh.Mesh([], [])

@staticmethod
def form_mesh(vertices, faces):
return mypymesh.Mesh(vertices, faces)
8 changes: 3 additions & 5 deletions Rules/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,20 @@ def is_displayable_rule() -> Callable[[Base], bool]:
"""Rule: Check if a parameter is displayable."""
return (
lambda parameter: parameter.displayValue
and parameter.displayValue is not None
and parameter.displayValue is not None
)

@staticmethod
def speckle_type_rule(
desired_type: Union[str, List[str]]
desired_type: Union[str, List[str]]
) -> Callable[[Base], bool]:
"""Rule: Check if a parameter's speckle_type matches the desired type."""

# Convert single string to list for consistent handling
if isinstance(desired_type, str):
desired_type = [desired_type]

print(desired_type)

return (
lambda speckle_object: getattr(speckle_object, "speckle_type", None)
in desired_type
in desired_type
)
13 changes: 10 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ class FunctionInputs(AutomateBase):
title="Tolerance",
description="Specify the tolerance value for the analysis. \
Negative values relaxes the test, positive values make it more strict.",
readonly=True,
json_schema_extra={
"readOnly": True,
}
)
tolerance_unit: str = Field( # Using the SpecklePy Units enum here
default=Units.mm,
json_schema_extra={"examples": ["mm", "cm", "m"]},
json_schema_extra={"examples": ["mm", "cm", "m"], "readOnly": True},
title="Tolerance Unit",
description="Unit of the tolerance value.",
readonly=True,
)


Expand Down Expand Up @@ -114,6 +115,7 @@ def automate_function(
for base_obj, id, transform in reference_objects
if visible_beams_rule(base_obj)
]

latest_displayable_objects = [
(base_obj, id, transform)
for base_obj, id, transform in latest_objects
Expand Down Expand Up @@ -148,6 +150,11 @@ def automate_function(
all_objects_count = len(reference_mesh_elements) + len(latest_mesh_elements)
all_clashes_count = len(clashes)

print(f"Clash detection report: {all_clashes_count} clashes found between {all_objects_count} objects.")

print(f"Reference objects: {len([x for x in reference_objects])}.")
print(f"Latest objects: {len([x for x in latest_objects])}.")

clash_report_message = (
f"Clash detection report: {all_clashes_count} clashes found "
f"between {all_objects_count} objects. "
Expand Down
32 changes: 16 additions & 16 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ def crypto_random_string(length: int) -> str:


def register_new_automation(
project_id: str,
model_id: str,
speckle_client: SpeckleClient,
automation_id: str,
automation_name: str,
automation_revision_id: str,
project_id: str,
model_id: str,
speckle_client: SpeckleClient,
automation_id: str,
automation_name: str,
automation_revision_id: str,
):
"""Register a new automation in the speckle server."""
query = gql(
Expand Down Expand Up @@ -97,8 +97,8 @@ def test_object() -> Base:
# fixture to mock the AutomationRunData that would be generated by a full Automation Run
def fake_automation_run_data(request, test_client: SpeckleClient) -> AutomationRunData:
server_url = request.config.SPECKLE_SERVER_URL
project_id = "4f064f09e6"
model_id = "5a16cf52af"
project_id = "7d8e96669a"
model_id = "efeb71387b"

function_name = "Clash Test"

Expand All @@ -119,7 +119,7 @@ def fake_automation_run_data(request, test_client: SpeckleClient) -> AutomationR
project_id=project_id,
model_id=model_id,
branch_name="main",
version_id="2b16327448",
version_id="3f13306ed2",
speckle_server_url=server_url,
# These ids would be available with a valid registered Automation definition.
automation_id=automation_id,
Expand All @@ -142,7 +142,7 @@ def test_function_run(fake_automation_run_data: AutomationRunData, speckle_token
context,
automate_function,
FunctionInputs(
tolerance=0.1, tolerance_unit="mm", static_model_name="structural"
tolerance=0.1, tolerance_unit="mm", static_model_name="simple beams"
),
)

Expand All @@ -156,26 +156,26 @@ def context(fake_automation_run_data: AutomationRunData, speckle_token: str):

def test_non_existent_model(context, test_client: SpeckleClient):
with pytest.raises(
Exception, match="The static model named does not exist, skipping the function."
Exception, match="The static model named does not exist, skipping the function."
):
get_reference_model(context, "Fake Name")


def test_model_with_no_versions(context, test_client: SpeckleClient):
with pytest.raises(
Exception, match="The static model has no versions, skipping the function."
Exception, match="The static model has no versions, skipping the function."
):
get_reference_model(context, "blank")


def test_same_as_changed_model(context, test_client: SpeckleClient):
with pytest.raises(
Exception,
match="The static model is the same as the changed model, skipping the function.",
Exception,
match="The static model is the same as the changed model, skipping the function.",
):
get_reference_model(context, "hvac")
get_reference_model(context, "clash simple")


def test_valid_reference_model(context, test_client: SpeckleClient):
reference_model = get_reference_model(context, "structural")
reference_model = get_reference_model(context, "simple beams")
assert reference_model is not None

0 comments on commit 2396810

Please sign in to comment.