Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions .github/prompts/comparison_formula.prompt.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ class Form5Dot17CompressionCheckZProfilesClass1And2(ComparisonFormula):
},
False,
)
_intermediate_result: str = rf"\left( {self.unity_check:.{n}f} \leq 0.1 \right)"
return LatexFormula(
return_symbol=r"CHECK",
result="OK" if bool(self) else r"\text{Not OK}",
intermediate_result=_intermediate_result,
equation=_equation,
numeric_equation=_numeric_equation,
comparison_operator_label=r"\to",
Expand Down
2 changes: 1 addition & 1 deletion .github/prompts/comparison_tests.prompt.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class TestForm5Dot17CompressionCheckZProfilesClass1And2:
[
(
"complete",
r"CHECK \to \frac{N_{Ed}}{N_{pl,Rd}} \leq 0.1 \to \frac{12.000}{200.000} \leq 0.1 \to OK",
r"CHECK \to \frac{N_{Ed}}{N_{pl,Rd}} \leq 0.1 \to \frac{12.000}{200.000} \leq 0.1 \to \frac 0.06 \leq 0.1 \to OK",
),
("short", r"CHECK \to OK"),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def _evaluate(
def latex(self, n: int = 2) -> LatexFormula:
"""Returns a LatexFormula representation of the formula."""
return LatexFormula(
return_symbol="",
return_symbol=r"\alpha_2 \alpha_3 \alpha_5",
result=f"{self:.{n}f}",
equation=r"\alpha_2 \cdot \alpha_3 \cdot \alpha_5 \ge 0.7",
numeric_equation=rf"{self.alpha_2} \cdot {self.alpha_3} \cdot {self.alpha_5} \ge 0.7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ def _evaluate(
raise_if_negative(n_ed=n_ed)
return (n_ed / n_t_rd) <= 1

@staticmethod
def _unity_check(
n_ed: N,
n_t_rd: N,
) -> float:
"""Evaluates the intermediate result N_Ed / N_t,Rd."""
raise_if_less_or_equal_to_zero(n_t_rd=n_t_rd)
raise_if_negative(n_ed=n_ed)
return n_ed / n_t_rd

def latex(self, n: int = 3) -> LatexFormula:
"""Returns LatexFormula object for formula 6.5."""
_equation: str = r"\left( \frac{N_{Ed}}{N_{t,Rd}} \leq 1 \right)"
Expand All @@ -54,9 +64,12 @@ def latex(self, n: int = 3) -> LatexFormula:
},
False,
)
_intermediate_result: str = rf"\left( {self._unity_check(self.n_ed, self.n_t_rd):.{n}f} \leq 1 \right)"

return LatexFormula(
return_symbol=r"CHECK",
result="OK" if self.__bool__() else "\\text{Not OK}",
intermediate_result=_intermediate_result,
equation=_equation,
numeric_equation=_numeric_equation,
comparison_operator_label="\\to",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from blueprints.codes.eurocode.en_1993_1_1_2005 import EN_1993_1_1_2005
from blueprints.codes.formula import Formula
from blueprints.codes.latex_formula import LatexFormula, latex_replace_symbols
from blueprints.type_alias import N
from blueprints.type_alias import DIMENSIONLESS, N
from blueprints.validations import raise_if_less_or_equal_to_zero, raise_if_negative


Expand Down Expand Up @@ -44,6 +44,17 @@ def _evaluate(

return n_ed / n_c_rd <= 1

@staticmethod
def _unity_check(
n_ed: N,
n_c_rd: N,
) -> DIMENSIONLESS:
"""Evaluates the intermediate result N_Ed / N_c,Rd."""
raise_if_less_or_equal_to_zero(n_c_rd=n_c_rd)
raise_if_negative(n_ed=n_ed)

return n_ed / n_c_rd

def latex(self, n: int = 3) -> LatexFormula:
"""Returns LatexFormula object for formula 6.9."""
_equation: str = r"\left( \frac{N_{Ed}}{N_{c,Rd}} \leq 1 \right)"
Expand All @@ -55,9 +66,11 @@ def latex(self, n: int = 3) -> LatexFormula:
},
False,
)
_intermediate_result: str = rf"\left( {self._unity_check(self.n_ed, self.n_c_rd):.{n}f} \leq 1 \right)"
return LatexFormula(
return_symbol=r"CHECK",
result="OK" if self.__bool__() else "\\text{Not OK}",
intermediate_result=_intermediate_result,
equation=_equation,
numeric_equation=_numeric_equation,
comparison_operator_label="\\to",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __str__(self) -> str:
def latex(self, n: int = 2) -> LatexFormula:
"""Returns LatexFormula object for formula 2.4."""
return LatexFormula(
return_symbol="",
return_symbol="CHECK",
equation="E_{dst;d} \\leq E_{stb;d} + T_d",
result="OK" if self.__bool__() else "\\text{Not OK}",
numeric_equation=f"{self.e_dst_d:.{n}f} \\leq {self.e_stb_d:.{n}f} + {self.t_d:.{n}f} \\to {self.e_dst_d:.{n}f} \\leq "
Expand Down
15 changes: 10 additions & 5 deletions blueprints/codes/latex_formula.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class LatexFormula:
The symbol to return
result: str
The result of the formula
intermediate_result: str, default ""
An intermediate result of the formula
equation: str, default ""
The formula with symbols
numeric_equation: str, default ""
Expand All @@ -30,6 +32,7 @@ class LatexFormula:

return_symbol: str
result: str
intermediate_result: str = ""
equation: str = ""
numeric_equation: str = ""
numeric_equation_with_units: str = ""
Expand All @@ -43,10 +46,10 @@ def complete(self) -> str:
Returns
-------
str
Return symbol = equation = numeric_equation = result
Return symbol = equation = numeric_equation = intermediate_result = result

"""
all_sub_equations = [self.return_symbol, self.equation, self.numeric_equation, f"{self.result}"]
all_sub_equations = [self.return_symbol, self.equation, self.numeric_equation, self.intermediate_result, self.result]
long_formula = f" {self.comparison_operator_label} ".join([eq for eq in all_sub_equations if eq != ""])
return long_formula + rf" \ {self.unit}" if self.unit else long_formula

Expand All @@ -57,13 +60,13 @@ def complete_with_units(self) -> str:
Returns
-------
str
Return symbol = equation = numeric_equation_with_units = result
Return symbol = equation = numeric_equation_with_units = intermediate_result = result

"""
# If numeric_equation_with_units is not provided, use numeric_equation
numeric_equation_with_units = self.numeric_equation_with_units or self.numeric_equation

all_sub_equations = [self.return_symbol, self.equation, numeric_equation_with_units, f"{self.result}"]
all_sub_equations = [self.return_symbol, self.equation, numeric_equation_with_units, self.intermediate_result, self.result]
long_formula = f" {self.comparison_operator_label} ".join([eq for eq in all_sub_equations if eq != ""])
return long_formula + rf" \ {self.unit}" if self.unit else long_formula

Expand All @@ -77,7 +80,9 @@ def short(self) -> str:
Return symbol = result

"""
short_formula = f"{self.return_symbol} {self.comparison_operator_label} {self.result}"
all_sub_equations = [self.return_symbol, self.result]
short_formula = f" {self.comparison_operator_label} ".join([eq for eq in all_sub_equations if eq != ""])

return short_formula + rf" \ {self.unit}" if self.unit else short_formula

def __str__(self) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def test_negative_alpha(self, alpha_2: float, alpha_3: float, alpha_5: float) ->
@pytest.mark.parametrize(
("representation", "expected_result"),
[
("complete", r"\alpha_2 \cdot \alpha_3 \cdot \alpha_5 \ge 0.7 \to 1 \cdot 1 \cdot 1 \ge 0.7 \to 1.00"),
("short", " \\to 1.00"),
("complete", r"\alpha_2 \alpha_3 \alpha_5 \to \alpha_2 \cdot \alpha_3 \cdot \alpha_5 \ge 0.7 \to 1 \cdot 1 \cdot 1 \ge 0.7 \to 1.00"),
("short", r"\alpha_2 \alpha_3 \alpha_5 \to 1.00"),
],
)
def test_latex(self, representation: str, expected_result: str) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_raise_error_when_negative_or_zero_n_t_rd_is_given(self, n_ed: float, n_
(
"complete",
r"CHECK \to \left( \frac{N_{Ed}}{N_{t,Rd}} \leq 1 \right) \to "
r"\left( \frac{7.000}{10.000} \leq 1 \right) \to OK",
r"\left( \frac{7.000}{10.000} \leq 1 \right) \to \left( 0.700 \leq 1 \right) \to OK",
),
("short", r"CHECK \to OK"),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_raise_error_when_invalid_values_are_given(self, n_ed: float, n_c_rd: fl
(
"complete",
r"CHECK \to \left( \frac{N_{Ed}}{N_{c,Rd}} \leq 1 \right) \to "
r"\left( \frac{100.000}{150.000} \leq 1 \right) \to OK",
r"\left( \frac{100.000}{150.000} \leq 1 \right) \to \left( 0.667 \leq 1 \right) \to OK",
),
("short", r"CHECK \to OK"),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def test_str(self) -> None:
@pytest.mark.parametrize(
("representation", "expected_result"),
[
("complete", r"E_{dst;d} \leq E_{stb;d} + T_d \to 2.01 \leq 1.00 + 1.00 \to 2.01 \leq 2.00 \to \text{Not OK}"),
("short", r" \to \text{Not OK}"),
("complete", r"CHECK \to E_{dst;d} \leq E_{stb;d} + T_d \to 2.01 \leq 1.00 + 1.00 \to 2.01 \leq 2.00 \to \text{Not OK}"),
("short", r"CHECK \to \text{Not OK}"),
],
)
def test_latex(self, representation: str, expected_result: str) -> None:
Expand Down