Skip to content
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

Feat/check res table #848

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/pymapdl.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions ansys/mapdl/core/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,54 @@ def wrapper(*args, **kwargs):
func(*args, **kwargs)

return wrapper


# Function to build main
def check_res_table(row_names=None, simulation_res=None, target_res=None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add docstring here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these parameters are always required, then should be using arg and not kwarg.


# If someone did not identify inputs at all,
# it represents default data frame example.
if row_names is None:
print("No Inputs")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't print, raise:

raise ValueError('missing row_names')

row_names = ["row1", "row2"]
simulation_res = [1, 2]
target_res = [10, 20]

# If the quantity of the rows does not equal to the quantity.
if len(row_names) != len(target_res) or len(row_names) != len(target_res):
raise TypeError("Not the same quantity of the rows and filled data")

# Import Pandas and Numpy.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to top, specify why you're doing a lazy import.

import pandas as pd

# Define column names with corresponding inputs.
main_columns = {
"Target": target_res,
"Mechanical APDL": simulation_res,
"Ratio": list(np.divide(simulation_res, target_res))
}

# Create a Data Frame with Pandas.
df = pd.DataFrame(main_columns, index=row_names)

# Define setting of the Data Frame Style.
df2 = df.style.set_table_styles([
{
"selector": "th",
"props": [('font-size', '16px')]
},
{
"selector": "td",
"props": [('font-size', '16px')]
},
{
"selector": "td:hover",
"props": [("background-color", "#FFF8DC")]
}],
).set_properties(**
{
"color": "black",
"text-align": "center"
}).format("{:.2f}")

return df2