Skip to content

Commit

Permalink
FEAT: CreateReportFromTemplate inside create_report_from_configuration (
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuelopez-ansys authored Aug 29, 2024
1 parent c53c711 commit babac26
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
17 changes: 10 additions & 7 deletions _unittest/test_12_PostProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,18 @@ def test_09_manipulate_report_B(self, field_test):
)
new_report4.report_type = "Data Table"
assert new_report4.create()

local_path = os.path.dirname(os.path.realpath(__file__))
template = os.path.join(local_path, "example_models", test_subfolder, "template.rpt")
if not config["NonGraphical"]:
local_path = os.path.dirname(os.path.realpath(__file__))
template = os.path.join(local_path, "example_models", test_subfolder, "template.rpt")
assert new_report4.apply_report_template(template)
template = os.path.join(local_path, "example_models", test_subfolder, "template_invented.rpt")
assert not new_report4.apply_report_template(template)
template = os.path.join(local_path, "example_models", test_subfolder, "template.csv")
assert not new_report4.apply_report_template(template)
assert not new_report4.apply_report_template(template, property_type="Dummy")
template2 = os.path.join(local_path, "example_models", test_subfolder, "template_invented.rpt")
assert not new_report4.apply_report_template(template2)
template3 = os.path.join(local_path, "example_models", test_subfolder, "template.csv")
assert not new_report4.apply_report_template(template3)
assert not new_report4.apply_report_template(template3, property_type="Dummy")

assert field_test.post.create_report_from_configuration(template)

def test_09_manipulate_report_C(self, field_test):
variations = field_test.available_variations.nominal_w_values_dict
Expand Down
39 changes: 34 additions & 5 deletions src/ansys/aedt/core/modules/post_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2258,12 +2258,12 @@ def get_solution_data(

@pyaedt_function_handler(input_dict="report_settings")
def create_report_from_configuration(self, input_file=None, report_settings=None, solution_name=None):
"""Create a report based on a JSON file, TOML file, or dictionary of properties.
"""Create a report based on a JSON file, TOML file, RPT file, or dictionary of properties.
Parameters
----------
input_file : str, optional
Path to the JSON or TOML file containing report settings.
Path to the JSON, TOML, or RPT file containing report settings.
report_settings : dict, optional
Dictionary containing report settings.
solution_name : str, optional
Expand All @@ -2277,18 +2277,47 @@ def create_report_from_configuration(self, input_file=None, report_settings=None
Examples
--------
Create report from JSON file.
>>> from ansys.aedt.core import Hfss
>>> hfss = Hfss()
>>> hfss.post.create_report_from_configuration(r'C:\\temp\\my_report.json',
>>> solution_name="Setup1 : LastAdpative")
... solution_name="Setup1 : LastAdpative")
Create report from RPT file.
>>> from ansys.aedt.core import Hfss
>>> hfss = Hfss()
>>> hfss.post.create_report_from_configuration(r'C:\\temp\\my_report.rpt')
Create report from dictionary.
>>> from ansys.aedt.core import Hfss
>>> from ansys.aedt.core.generic.general_methods import read_json
>>> hfss = Hfss()
>>> dict_vals = read_json("Report_Simple.json")
>>> hfss.post.create_report_from_configuration(report_settings=dict_vals)
"""
if not report_settings and not input_file: # pragma: no cover
self.logger.error("Either a JSON file or a dictionary must be passed as input.")
self.logger.error("Either a file or a dictionary must be passed as input.")
return False
if input_file:
props = read_configuration_file(input_file)
_, file_extension = os.path.splitext(input_file)
if file_extension == ".rpt":
old_expressions = self.all_report_names
self.oreportsetup.CreateReportFromTemplate(input_file)
new_expressions = [item for item in self.all_report_names if item not in old_expressions]
if new_expressions:
report_name = new_expressions[0]
self.plots = self._get_plot_inputs()
report = None
for plot in self.plots:
if plot.plot_name == report_name:
report = plot
break
return report
else:
props = read_configuration_file(input_file)
else:
props = report_settings

if (
isinstance(props.get("expressions", {}), list)
and props["expressions"]
Expand Down

0 comments on commit babac26

Please sign in to comment.