-
Notifications
You must be signed in to change notification settings - Fork 0
Feat model blueprint #129
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
Merged
Merged
Feat model blueprint #129
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8461b4a
feat(models blueprint & test): New blueprint models, json schema, test
SpliiT f58f296
add uuid dict logic
SpliiT e9732fb
edit models' blueprint & test
SpliiT 7d91011
rv prints
SpliiT 831d358
change routes' names & schemas + rv output.og_tsf3d
SpliiT d48beb1
wip
SpliiT 38a57c2
Merge branch 'next' of https://github.com/Geode-solutions/OpenGeodeWe…
SpliiT a2614b2
fix test models_routes & requirements
SpliiT b21928d
rv src from app.py
SpliiT 6fc40f4
update
SpliiT bbffdbd
rm print
SpliiT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import json | ||
| import os | ||
| import xml.etree.ElementTree as ET | ||
| import flask | ||
| from ... import geode_functions, utils_functions | ||
|
|
||
| routes = flask.Blueprint("models", __name__, url_prefix="/models") | ||
|
|
||
|
|
||
| schemas = os.path.join(os.path.dirname(__file__), "schemas") | ||
|
|
||
| with open(os.path.join(schemas, "vtm_component_indices.json"), "r") as file: | ||
| vtm_component_indices_json = json.load(file) | ||
|
|
||
|
|
||
| @routes.route( | ||
| vtm_component_indices_json["route"], methods=vtm_component_indices_json["methods"] | ||
| ) | ||
| def uuid_to_flat_index(): | ||
|
|
||
| print(f"uuid_to_flat_index : {flask.request=}", flush=True) | ||
| utils_functions.validate_request(flask.request, vtm_component_indices_json) | ||
| vtm_file_path = os.path.join( | ||
| flask.current_app.config["DATA_FOLDER_PATH"], flask.request.json["id"] + ".vtm" | ||
| ) | ||
|
|
||
| tree = ET.parse(vtm_file_path) | ||
| root = tree.getroot() | ||
| uuid_to_flat_index = {} | ||
| current_index = 1 | ||
|
|
||
| for elem in root.iter(): | ||
| if "uuid" in elem.attrib and elem.tag == "DataSet": | ||
| uuid_to_flat_index[elem.attrib["uuid"]] = current_index | ||
| current_index += 1 | ||
|
|
||
| return flask.make_response( | ||
| {"uuid_to_flat_index": uuid_to_flat_index}, | ||
| 200, | ||
| ) | ||
|
|
||
|
|
||
| def extract_model_uuids(geode_object, file_path): | ||
| model = geode_functions.load(geode_object, file_path) | ||
| mesh_components = model.mesh_components() | ||
|
|
||
| uuid_dict = {} | ||
|
|
||
| for mesh_component, ids in mesh_components.items(): | ||
| component_name = mesh_component.get() | ||
| uuid_dict[component_name] = [id.string() for id in ids] | ||
|
|
||
| return uuid_dict | ||
|
|
||
|
|
||
| with open(os.path.join(schemas, "mesh_components.json"), "r") as file: | ||
| mesh_components_json = json.load(file) | ||
|
|
||
|
|
||
| @routes.route(mesh_components_json["route"], methods=mesh_components_json["methods"]) | ||
| def extract_uuids_endpoint(): | ||
| print(f"extract_uuids_endpoint : {flask.request=}", flush=True) | ||
|
|
||
| utils_functions.validate_request(flask.request, mesh_components_json) | ||
|
|
||
| file_path = os.path.join( | ||
| flask.current_app.config["DATA_FOLDER_PATH"], flask.request.json["filename"] | ||
| ) | ||
|
|
||
| if not os.path.exists(file_path): | ||
| return flask.make_response({"error": "File not found"}, 404) | ||
|
|
||
| uuid_dict = extract_model_uuids(flask.request.json["geode_object"], file_path) | ||
| return flask.make_response({"uuid_dict": uuid_dict}, 200) |
20 changes: 20 additions & 0 deletions
20
src/opengeodeweb_back/routes/models/schemas/mesh_components.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "route": "/mesh_components", | ||
| "methods": [ | ||
| "POST" | ||
| ], | ||
| "type": "object", | ||
| "properties": { | ||
| "filename": { | ||
| "type": "string" | ||
| }, | ||
| "geode_object": { | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "required": [ | ||
| "filename", | ||
| "geode_object" | ||
| ], | ||
| "additionalProperties": false | ||
| } |
16 changes: 16 additions & 0 deletions
16
src/opengeodeweb_back/routes/models/schemas/vtm_component_indices.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "route": "/vtm_component_indices", | ||
| "methods": [ | ||
| "POST" | ||
| ], | ||
| "type": "object", | ||
| "properties": { | ||
| "id": { | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "required": [ | ||
| "id" | ||
| ], | ||
| "additionalProperties": false | ||
| } |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| <?xml version="1.0"?> | ||
| <VTKFile type="vtkMultiBlockDataSet" version="1.0" byte_order="LittleEndian" header_type="UInt32" compressor="vtkZLibDataCompressor"> | ||
| <vtkMultiBlockDataSet> | ||
| <Block name="corners" index="0"> | ||
| <DataSet index="0" name="default_name" uuid="00000000-3bf3-4551-8000-000064de2fdd" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Corner_00000000-3bf3-4551-8000-000064de2fdd.vtp" /> | ||
| <DataSet index="1" name="default_name" uuid="00000000-4629-412b-8000-0000edfff497" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Corner_00000000-4629-412b-8000-0000edfff497.vtp" /> | ||
| <DataSet index="2" name="default_name" uuid="00000000-7dc7-495b-8000-000052017dae" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Corner_00000000-7dc7-495b-8000-000052017dae.vtp" /> | ||
| <DataSet index="3" name="default_name" uuid="00000000-8a73-4f55-8000-00002bf05d8e" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Corner_00000000-8a73-4f55-8000-00002bf05d8e.vtp" /> | ||
| <DataSet index="4" name="default_name" uuid="00000000-96bd-4157-8000-0000213ddb29" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Corner_00000000-96bd-4157-8000-0000213ddb29.vtp" /> | ||
| <DataSet index="5" name="default_name" uuid="00000000-ecd6-40de-8000-0000f7ed1e32" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Corner_00000000-ecd6-40de-8000-0000f7ed1e32.vtp" /> | ||
| <DataSet index="6" name="default_name" uuid="00000000-f9e9-4ddd-8000-0000f19cf8cb" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Corner_00000000-f9e9-4ddd-8000-0000f19cf8cb.vtp" /> | ||
| <DataSet index="7" name="default_name" uuid="00000000-fc1e-4e5f-8000-00000af3f679" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Corner_00000000-fc1e-4e5f-8000-00000af3f679.vtp" /> | ||
| </Block> | ||
| <Block name="lines" index="1"> | ||
| <DataSet index="0" name="default_name" uuid="00000000-15ab-453c-8000-0000beee33c6" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Line_00000000-15ab-453c-8000-0000beee33c6.vtp" /> | ||
| <DataSet index="1" name="default_name" uuid="00000000-1bd9-41e4-8000-000055e171a2" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Line_00000000-1bd9-41e4-8000-000055e171a2.vtp" /> | ||
| <DataSet index="2" name="default_name" uuid="00000000-2326-4c21-8000-000054a373c7" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Line_00000000-2326-4c21-8000-000054a373c7.vtp" /> | ||
| <DataSet index="3" name="default_name" uuid="00000000-304e-44a7-8000-0000c72260c1" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Line_00000000-304e-44a7-8000-0000c72260c1.vtp" /> | ||
| <DataSet index="4" name="default_name" uuid="00000000-4755-4dfa-8000-000055999885" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Line_00000000-4755-4dfa-8000-000055999885.vtp" /> | ||
| <DataSet index="5" name="default_name" uuid="00000000-57cf-41f4-8000-00006a4349dc" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Line_00000000-57cf-41f4-8000-00006a4349dc.vtp" /> | ||
| <DataSet index="6" name="default_name" uuid="00000000-5a6b-45b2-8000-000004be554e" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Line_00000000-5a6b-45b2-8000-000004be554e.vtp" /> | ||
| <DataSet index="7" name="default_name" uuid="00000000-93f2-437a-8000-00001b2727be" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Line_00000000-93f2-437a-8000-00001b2727be.vtp" /> | ||
| <DataSet index="8" name="default_name" uuid="00000000-98f6-4012-8000-0000eb927a96" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Line_00000000-98f6-4012-8000-0000eb927a96.vtp" /> | ||
| <DataSet index="9" name="default_name" uuid="00000000-9ca0-4e51-8000-00005b81d027" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Line_00000000-9ca0-4e51-8000-00005b81d027.vtp" /> | ||
| <DataSet index="10" name="default_name" uuid="00000000-d720-47c9-8000-0000e54053cc" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Line_00000000-d720-47c9-8000-0000e54053cc.vtp" /> | ||
| <DataSet index="11" name="default_name" uuid="00000000-f3ec-4765-8000-0000d74e506d" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Line_00000000-f3ec-4765-8000-0000d74e506d.vtp" /> | ||
| </Block> | ||
| <Block name="surfaces" index="2"> | ||
| <DataSet index="0" name="default_name" uuid="00000000-1702-4d26-8000-000004d7ea39" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Surface_00000000-1702-4d26-8000-000004d7ea39.vtp" /> | ||
| <DataSet index="1" name="default_name" uuid="00000000-6732-4f29-8000-00002f66bc93" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Surface_00000000-6732-4f29-8000-00002f66bc93.vtp" /> | ||
| <DataSet index="2" name="default_name" uuid="00000000-8afd-4969-8000-000092a43747" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Surface_00000000-8afd-4969-8000-000092a43747.vtp" /> | ||
| <DataSet index="3" name="default_name" uuid="00000000-cddf-4c1c-8000-00005ebbcaeb" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Surface_00000000-cddf-4c1c-8000-00005ebbcaeb.vtp" /> | ||
| <DataSet index="4" name="default_name" uuid="00000000-dc1c-420d-8000-000070dcfff5" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Surface_00000000-dc1c-420d-8000-000070dcfff5.vtp" /> | ||
| <DataSet index="5" name="default_name" uuid="00000000-dcfe-400a-8000-0000a72c4f30" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Surface_00000000-dcfe-400a-8000-0000a72c4f30.vtp" /> | ||
| </Block> | ||
| <Block name="blocks" index="3"> | ||
| <DataSet index="0" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Block_00000000-4335-411d-8000-000079b34fe5.vtu" name="default_name" uuid="00000000-4335-411d-8000-000079b34fe5" /> | ||
| </Block> | ||
| </vtkMultiBlockDataSet> | ||
| </VTKFile> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| def test_model_mesh_components(client): | ||
| route = f"/models/vtm_component_indices" | ||
| get_full_data = lambda: {"id": "cube"} | ||
| json = get_full_data() | ||
| response = client.post(route, json=json) | ||
| assert response.status_code == 200 | ||
| uuid_dict = response.json["uuid_to_flat_index"] | ||
| assert type(uuid_dict) is dict | ||
|
|
||
| indices = list(uuid_dict.values()) | ||
| indices.sort() | ||
| assert indices[0] == 1 | ||
| assert all(indices[i] == indices[i - 1] + 1 for i in range(1, len(indices))) | ||
|
|
||
|
|
||
| def test_extract_brep_uuids(client): | ||
| route = "/models/mesh_components" | ||
| json_data = {"filename": "cube.og_brep", "geode_object": "BRep"} | ||
|
|
||
| response = client.post(route, json=json_data) | ||
|
|
||
| assert response.status_code == 200 | ||
| uuid_dict = response.json["uuid_dict"] | ||
| assert isinstance(uuid_dict, dict) | ||
| assert ( | ||
| "Block" in uuid_dict | ||
| or "Line" in uuid_dict | ||
| or "Surface" in uuid_dict | ||
| or "Corner" in uuid_dict | ||
| ) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.