.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/25-intermediate/01-queries.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_25-intermediate_01-queries.py: .. _ref_queries_example: Item queries ============ The Ansys Dynamic Reporting database can contain any number of items, from a few to tens of thousands. To handle all this data, the :func:`queryansys.dynamicreporting.core.Service.query>` method allows you to quickly slice the database to select a subset of items. .. note:: This example assumes that you have a local Ansys installation. .. GENERATED FROM PYTHON SOURCE LINES 17-21 Start an Ansys Dynamic Reporting service ---------------------------------------- Start an Ansys Dynamic Reporting service with a new database. The path for the database directory must be to an empty directory. .. GENERATED FROM PYTHON SOURCE LINES 21-30 .. code-block:: Python import ansys.dynamicreporting.core as adr import ansys.dynamicreporting.core.examples as examples ansys_loc = r"C:\Program Files\ANSYS Inc\v232" db_dir = r"C:\tmp\new_database" adr_service = adr.Service(ansys_installation=ansys_loc, db_directory=db_dir) session_guid = adr_service.start(create_db=True) .. GENERATED FROM PYTHON SOURCE LINES 31-38 Create items ------------ Now that an Ansys Dynamic Reporting service is running on top of a new database, you can populate it. We will download and push to the database 14 images.We will then set some different names, sources, and tags based on the image names .. GENERATED FROM PYTHON SOURCE LINES 38-58 .. code-block:: Python variables = ["enthalpy", "statictemperature"] for v in variables: for i in range(7): if i % 3 == 0: new_image = adr_service.create_item( obj_name=f"Image {str(i + 1)}", source="Application X" ) elif i % 3 == 1: new_image = adr_service.create_item( obj_name=f"Image {str(i + 1)}", source="Application Y" ) elif i % 3 == 2: new_image = adr_service.create_item( obj_name=f"Image {str(i + 1)}", source="Application Z" ) filename = f"{v}_{str(i + 1).zfill(3)}.png" new_image.item_image = examples.download_file(filename, "input_data") new_image.set_tags(f"var={v} clip=-{float(i) * 0.01}") .. GENERATED FROM PYTHON SOURCE LINES 59-69 Query the database ------------------ Now that the database is populated with a few items with different names, sources, and tags, query the database, beginning with an empty query that returns the entire set (all 14 items). Next, query on the source name, which results in three different lists, with 6, 4, and 4 items respectively. Query on the ``var`` and ``clip`` taga. See that the lists have the expected length. You can try different queries using other attributes. # .. GENERATED FROM PYTHON SOURCE LINES 69-84 .. code-block:: Python all_items = adr_service.query() test_one = len(all_items) == 14 app_x = adr_service.query(item_filter="A|i_src|cont|Application X") app_y = adr_service.query(item_filter="A|i_src|cont|Application Y") app_z = adr_service.query(item_filter="A|i_src|cont|Application Z") test_two = len(app_x) == 6 test_three = len(app_y) == len(app_z) == 4 enthalpy_items = adr_service.query(item_filter="A|i_tags|cont|var=enthalpy") statictemperature_items = adr_service.query(item_filter="A|i_tags|cont|var=statictemperature") test_four = len(enthalpy_items) == len(statictemperature_items) == 7 clip3_items = adr_service.query(item_filter="A|i_tags|cont|clip=-0.03") clip5_items = adr_service.query(item_filter="A|i_tags|cont|clip=-0.05") test_five = len(clip3_items) == len(clip5_items) == 2 .. GENERATED FROM PYTHON SOURCE LINES 85-90 Close the service ----------------- Close the Ansys Dynamic Reporting service. The database with the items that were created remains on disk. .. GENERATED FROM PYTHON SOURCE LINES 90-93 .. code-block:: Python # sphinx_gallery_thumbnail_path = '_static/default_thumb.png' adr_service.stop() .. _sphx_glr_download_examples_25-intermediate_01-queries.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 01-queries.ipynb <01-queries.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 01-queries.py <01-queries.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 01-queries.zip <01-queries.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_