Skip to content

Commit a5c9abe

Browse files
author
MichalO
committed
min/max functions added
1 parent 08bb5d2 commit a5c9abe

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

RFEM/Results/resultTables.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from cmath import inf
12
import enum
23
from RFEM.initModel import Model
34
from RFEM.enums import CaseObjectType
5+
from RFEM.dataTypes import inf
46

57
# We can't extract lines with description: Extremes, Total, and Average. Those are language dependent.
68
# To do it set_settings_program_language() has to be called before calculation and the program needs to be restarted.
@@ -78,6 +80,46 @@ def ConvertResultsToListOfDct(results, includeBase = False):
7880

7981
return lstOfDct
8082

83+
def GetMinValue(structured_results, parameter):
84+
85+
'''
86+
Args:
87+
structured_results(list of dicts): Result of ConvertResultsToListOfDct() function
88+
parameter(str, mandatory): The parameter for which the minimum is sought.
89+
'''
90+
91+
min_val = inf
92+
for i in structured_results:
93+
# Sometimes there is text where the float should be
94+
try:
95+
min_val = min(float(i[parameter]), min_val)
96+
except:
97+
pass
98+
99+
assert min_val < inf, 'Check if the parameter is in the table.'
100+
101+
return min_val
102+
103+
def GetMaxValue(structured_results, parameter):
104+
105+
'''
106+
Args:
107+
structured_results(list of dicts): Result of ConvertResultsToListOfDct() function
108+
parameter(str, mandatory): The parameter for which the maximum is sought.
109+
'''
110+
111+
max_val = -inf
112+
for i in structured_results:
113+
# Sometimes there is text where the float should be
114+
try:
115+
max_val = max(float(i[parameter]), max_val)
116+
except:
117+
pass
118+
119+
assert max_val > -inf, 'Check if the parameter is in the table.'
120+
121+
return max_val
122+
81123
class ResultTables():
82124

83125
@staticmethod

UnitTests/test_ResultTables.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
sys.path.append(PROJECT_ROOT)
88
from RFEM.initModel import Model, CheckIfMethodOrTypeExists
99
from RFEM.enums import CaseObjectType
10-
from RFEM.Results.resultTables import ResultTables
10+
from RFEM.Results.resultTables import ResultTables, GetMaxValue, GetMinValue
1111
import pytest
1212

1313
if Model.clientModel is None:
@@ -60,4 +60,8 @@ def test_result_tables():
6060
assert ResultTables.SurfacesMaximumTotalStrains(CaseObjectType.E_OBJECT_TYPE_DESIGN_SITUATION, 1, 2)
6161
assert ResultTables.SurfacesPrincipalInternalForces(CaseObjectType.E_OBJECT_TYPE_DESIGN_SITUATION, 1, 3)
6262
assert ResultTables.SurfacesPrincipalStresses(CaseObjectType.E_OBJECT_TYPE_DESIGN_SITUATION, 1, 4)
63-
assert ResultTables.SurfacesPrincipalTotalStrains(CaseObjectType.E_OBJECT_TYPE_DESIGN_SITUATION, 1, 1)
63+
64+
table = ResultTables.SurfacesPrincipalTotalStrains(CaseObjectType.E_OBJECT_TYPE_DESIGN_SITUATION, 1, 1)
65+
assert table
66+
assert round(GetMinValue(table,'principal_strain_epsilon_2_minus'), 7) == -0.0001299
67+
assert round(GetMaxValue(table,'principal_strain_epsilon_2_minus'), 7) == 0.0000115

0 commit comments

Comments
 (0)