Skip to content

Commit 4e4af9f

Browse files
Fix post tests, add radians option and display custom scales in print_results
1 parent 8553b16 commit 4e4af9f

File tree

4 files changed

+79
-29
lines changed

4 files changed

+79
-29
lines changed

docs/examples/cracked_properties.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@
153153
"metadata": {},
154154
"outputs": [],
155155
"source": [
156-
"cracked_res_sag.print_results()\n",
157-
"cracked_res_hog.print_results()"
156+
"cracked_res_sag.print_results(radians=False)\n",
157+
"cracked_res_hog.print_results(radians=False)"
158158
]
159159
},
160160
{
@@ -177,8 +177,8 @@
177177
"cracked_res_sag.calculate_transformed_properties(elastic_modulus=32.8e3)\n",
178178
"cracked_res_hog.calculate_transformed_properties(elastic_modulus=32.8e3)\n",
179179
"\n",
180-
"cracked_res_sag.print_results()\n",
181-
"cracked_res_hog.print_results()"
180+
"cracked_res_sag.print_results(radians=False)\n",
181+
"cracked_res_hog.print_results(radians=False)"
182182
]
183183
},
184184
{

docs/examples/prestressed_section.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@
376376
"source": [
377377
"cr_p_serv = conc_sec_serv.calculate_cracked_properties(m_ext=0)\n",
378378
"cr_p_ult = conc_sec_ult.calculate_cracked_properties(m_ext=0)\n",
379-
"cr_p_serv.print_results()\n",
379+
"cr_p_serv.print_results(n_scale=1e-3, m_scale=1e-6)\n",
380380
"cr_stress_p_serv = conc_sec_serv.calculate_cracked_stress(cracked_results=cr_p_serv)\n",
381381
"cr_stress_p_serv.plot_stress()"
382382
]

src/concreteproperties/results.py

Lines changed: 71 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def print_results(
9696
self,
9797
eng: bool = True,
9898
prec: int = 3,
99+
radians: bool = True,
99100
) -> None:
100101
"""Prints the gross concrete section properties to the terminal.
101102
@@ -104,6 +105,8 @@ def print_results(
104105
``False``, formats with fixed notation. Defaults to ``True``.
105106
prec: The desired precision (i.e. one plus this value is the desired number
106107
of digits). Defaults to ``3``.
108+
radians: If set to ``True``, prints angles in radians, else converts angles
109+
to degrees. Defaults to ``True``.
107110
"""
108111
# setup table
109112
table = Table(title="Gross Concrete Section Properties")
@@ -181,9 +184,17 @@ def print_results(
181184
)
182185
table.add_row("E.I11", string_formatter(value=self.e_i11, eng=eng, prec=prec))
183186
table.add_row("E.I22", string_formatter(value=self.e_i22, eng=eng, prec=prec))
187+
188+
if radians:
189+
phi = self.phi
190+
ang_units = "rads"
191+
else:
192+
phi = self.phi * 180.0 / np.pi
193+
ang_units = "degs"
194+
184195
table.add_row(
185196
"Principal Axis Angle",
186-
string_formatter(value=self.phi, eng=eng, prec=prec),
197+
string_formatter(value=phi, eng=eng, prec=prec) + f" {ang_units}",
187198
end_section=True,
188199
)
189200
table.add_row(
@@ -471,8 +482,9 @@ def print_results(
471482
self,
472483
eng: bool = True,
473484
prec: int = 3,
474-
n_scale: float = 1.0,
475-
m_scale: float = 1.0,
485+
n_scale: float = 1,
486+
m_scale: float = 1,
487+
radians: bool = True,
476488
) -> None:
477489
"""Prints cracked concrete section properties to the terminal.
478490
@@ -483,14 +495,26 @@ def print_results(
483495
of digits). Defaults to ``3``.
484496
n_scale: Scale factor to apply to forces
485497
m_scale: Scale factor to apply to moments
498+
radians: If set to ``True``, prints angles in radians, else converts angles
499+
to degrees. Defaults to ``True``.
486500
"""
487501
# setup table
488-
table = Table(title="Cracked Concrete Section Properties")
502+
caption = f"{n_scale=}, {m_scale=}" if n_scale != 1 or m_scale != 1 else None
503+
table = Table(title="Cracked Concrete Section Properties", caption=caption)
489504
table.add_column("Property", justify="left", style="cyan", no_wrap=True)
490505
table.add_column("Value", justify="right", style="green")
491506

492507
# add table rows
493-
table.add_row("theta", string_formatter(value=self.theta, eng=eng, prec=prec))
508+
if radians:
509+
theta = self.theta
510+
ang_units = "rads"
511+
else:
512+
theta = self.theta * 180.0 / np.pi
513+
ang_units = "degs"
514+
515+
table.add_row(
516+
"theta", string_formatter(value=theta, eng=eng, prec=prec) + f" {ang_units}"
517+
)
494518

495519
# only show n & m if one is non-zero
496520
if self.n != 0 or self.m != 0:
@@ -626,7 +650,18 @@ def print_results(
626650
string_formatter(value=self.e_i22_cr, eng=eng, prec=prec),
627651
end_section=True,
628652
)
629-
table.add_row("phi_cr", string_formatter(value=self.phi_cr, eng=eng, prec=prec))
653+
654+
if radians:
655+
phi_cr = self.phi_cr
656+
ang_units = "rads"
657+
else:
658+
phi_cr = self.phi_cr * 180.0 / np.pi
659+
ang_units = "degs"
660+
661+
table.add_row(
662+
"phi_cr",
663+
string_formatter(value=phi_cr, eng=eng, prec=prec) + f" {ang_units}",
664+
)
630665

631666
console = Console()
632667
console.print(table)
@@ -686,7 +721,7 @@ def plot_results(
686721
Returns:
687722
Matplotlib axes object
688723
"""
689-
# scale moments
724+
# scale moments # TODO: add note re: n & m scales
690725
moments = np.array(self.m_xy) * m_scale
691726

692727
# create plot and setup the plot
@@ -722,7 +757,7 @@ def plot_multiple_results(
722757
Returns:
723758
Matplotlib axes object
724759
"""
725-
# create plot and setup the plot
760+
# create plot and setup the plot # TODO: add note re: n & m scales
726761
with plotting_context(title="Moment-Curvature", **kwargs) as (fig, ax):
727762
if ax is None:
728763
msg = "Plot failed."
@@ -834,8 +869,9 @@ def print_results(
834869
self,
835870
eng: bool = True,
836871
prec: int = 3,
837-
n_scale: float = 1.0,
838-
m_scale: float = 1.0,
872+
n_scale: float = 1,
873+
m_scale: float = 1,
874+
radians: bool = True,
839875
) -> None:
840876
"""Prints the ultimate bending results to the terminal.
841877
@@ -846,19 +882,30 @@ def print_results(
846882
of digits). Defaults to ``3``.
847883
n_scale: Scale factor to apply to forces
848884
m_scale: Scale factor to apply to moments
885+
radians: If set to ``True``, prints angles in radians, else converts angles
886+
to degrees. Defaults to ``True``.
849887
"""
850888
# setup table
851-
table = Table(title="Ultimate Bending Results")
889+
caption = f"{n_scale=}, {m_scale=}" if n_scale != 1 or m_scale != 1 else None
890+
891+
table = Table(title="Ultimate Bending Results", caption=caption)
852892
table.add_column("Property", justify="left", style="cyan", no_wrap=True)
853893
table.add_column("Value", justify="right", style="green")
854894

855895
# add table rows
856896
if self.label:
857897
table.add_row("Label", self.label, end_section=True)
858898

899+
if radians:
900+
theta = self.theta
901+
ang_units = "rads"
902+
else:
903+
theta = self.theta * 180.0 / np.pi
904+
ang_units = "degs"
905+
859906
table.add_row(
860907
"Bending Angle - theta",
861-
string_formatter(value=self.theta, eng=eng, prec=prec),
908+
string_formatter(value=theta, eng=eng, prec=prec) + f" {ang_units}",
862909
)
863910
table.add_row(
864911
"Neutral Axis Depth - d_n",
@@ -869,18 +916,21 @@ def print_results(
869916
string_formatter(value=self.k_u, eng=eng, prec=prec),
870917
end_section=True,
871918
)
872-
table.add_row("Axial Force", string_formatter(value=self.n, eng=eng, prec=prec))
919+
table.add_row(
920+
"Axial Force",
921+
string_formatter(value=self.n, eng=eng, prec=prec, scale=n_scale),
922+
)
873923
table.add_row(
874924
"Bending Capacity - m_x",
875-
string_formatter(value=self.m_x, eng=eng, prec=prec),
925+
string_formatter(value=self.m_x, eng=eng, prec=prec, scale=m_scale),
876926
)
877927
table.add_row(
878928
"Bending Capacity - m_y",
879-
string_formatter(value=self.m_y, eng=eng, prec=prec),
929+
string_formatter(value=self.m_y, eng=eng, prec=prec, scale=m_scale),
880930
)
881931
table.add_row(
882932
"Bending Capacity - m_xy",
883-
string_formatter(value=self.m_xy, eng=eng, prec=prec),
933+
string_formatter(value=self.m_xy, eng=eng, prec=prec, scale=m_scale),
884934
)
885935

886936
console = Console()
@@ -974,7 +1024,7 @@ def plot_diagram(
9741024
Returns:
9751025
Matplotlib axes object
9761026
"""
977-
# create plot and setup the plot
1027+
# create plot and setup the plot # TODO: add note re: n & m scales
9781028
with plotting_context(title="Moment Interaction Diagram", **kwargs) as (
9791029
fig,
9801030
ax,
@@ -1068,7 +1118,7 @@ def plot_multiple_diagrams(
10681118
Returns:
10691119
Matplotlib axes object
10701120
"""
1071-
# create plot and setup the plot
1121+
# create plot and setup the plot # TODO: add note re: n & m scales
10721122
with plotting_context(title="Moment Interaction Diagram", **kwargs) as (
10731123
fig,
10741124
ax,
@@ -1179,7 +1229,7 @@ def plot_diagram(
11791229
"""
11801230
m_x_list, m_y_list = self.get_results_lists()
11811231

1182-
# create plot and setup the plot
1232+
# create plot and setup the plot # TODO: add note re: n & m scales
11831233
with plotting_context(
11841234
title=f"Biaxial Bending Diagram, $N = {self.n:.3e}$", **kwargs
11851235
) as (fig, ax):
@@ -1220,7 +1270,7 @@ def plot_multiple_diagrams_2d(
12201270
Returns:
12211271
Matplotlib axes object
12221272
"""
1223-
# create plot and setup the plot
1273+
# create plot and setup the plot # TODO: add note re: n & m scales
12241274
with plotting_context(title="Biaxial Bending Diagram", **kwargs) as (fig, ax):
12251275
if ax is None:
12261276
msg = "Plot failed."
@@ -1277,7 +1327,7 @@ def plot_multiple_diagrams_3d(
12771327
Returns:
12781328
Matplotlib axes object
12791329
"""
1280-
# make 3d plot
1330+
# make 3d plot # TODO: add note re: n & m scales
12811331
plt.figure()
12821332
ax = plt.axes(projection="3d")
12831333

tests/test_post.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ def test_string_formatter():
77
"""Tests the string formatter."""
88
assert string_formatter(value=2704.897111, eng=False, prec=3) == "2704.897"
99
assert string_formatter(value=2704.897111, eng=False, prec=0) == "2705"
10-
assert string_formatter(value=2704.897111, eng=False, prec=10) == "2704.897111"
11-
assert string_formatter(value=0, eng=True, prec=2) == "0"
10+
assert string_formatter(value=2704.897111, eng=False, prec=10) == "2704.8971110000"
11+
assert string_formatter(value=0, eng=True, prec=2) == "0.00"
1212
assert string_formatter(value=2704.897111, eng=True, prec=4) == "2.7049 x 10^3"
1313
assert string_formatter(value=0.0034563, eng=True, prec=2) == "3.46 x 10^-3"
1414
assert string_formatter(value=0.034563, eng=True, prec=3) == "34.56 x 10^-3"
15-
assert string_formatter(value=15, eng=True, prec=2) == "15"
15+
assert string_formatter(value=15, eng=True, prec=2) == "15.0"
1616
assert string_formatter(value=14435.654, eng=True, prec=4) == "14.436 x 10^3"
1717
assert (
1818
string_formatter(value=14435.654, eng=True, prec=4, scale=10) == "144.36 x 10^3"

0 commit comments

Comments
 (0)