Skip to content

formula

codes.formula

Module for the abstract base class Formula.

Classes:

codes.formula.ComparisonFormula

ComparisonFormula(*args, **kwargs)

Bases: Formula

Base class for comparison formulas used in the codes.

Source code in blueprints/codes/formula.py
21
22
23
24
def __init__(self, *args, **kwargs) -> None:
    """Method for initializing a new instance of the class."""
    super().__init__(*args, **kwargs)
    self._initialized = True

codes.formula.ComparisonFormula.lhs property

lhs: float

Property for getting the left-hand side of the comparison.

Returns:

  • float

    The left-hand side value of the comparison.

codes.formula.ComparisonFormula.rhs property

rhs: float

Property for getting the right-hand side of the comparison.

Returns:

  • float

    The right-hand side value of the comparison.

codes.formula.ComparisonFormula.unity_check property

unity_check: float

Property to present the unity check of the formula.

A unity check is the ratio between the left-hand side (lhs) and right-hand side (rhs) of a comparison formula. The calculation is operator-dependent to ensure a unity check less than 1 always indicates the condition is satisfied:

  • For le (<=) and lt (<): unity_check = lhs / rhs
  • For ge (>=) and gt (>): unity_check = rhs / lhs
  • For eq (==) and other operators: unity_check = lhs / rhs

A unity check < 1 indicates the condition is satisfied. A unity check >= 1 indicates the condition is not satisfied.

Examples:

lhs = 0.11, rhs = 0.1, Formula: lhs <= rhs, unity_check = 1.1 # NOT satisfied lhs = 0.09, rhs = 0.1, Formula: lhs <= rhs, unity_check = 0.9 # satisfied lhs = 0.2, rhs = 0.1, Formula: lhs >= rhs, unity_check = 0.5 # satisfied lhs = 0.05, rhs = 0.1, Formula: lhs >= rhs, unity_check = 2.0 # NOT satisfied

Returns:

  • float

    The unity check ratio.

codes.formula.DoubleComparisonFormula

DoubleComparisonFormula(*args, **kwargs)

Bases: Formula

Base class for double comparison formulas used in the codes. Examples: angle_min < angle < angle_max or angle_min > angle > angle_max.

Note that the comparison operators must point in the same direction for both sides: - Ascending: operator.lt (<) or operator.le (<=) - Descending: operator.gt (>) or operator.ge (>=) Mixed directions (e.g., < and >) are not allowed.

Source code in blueprints/codes/formula.py
21
22
23
24
def __init__(self, *args, **kwargs) -> None:
    """Method for initializing a new instance of the class."""
    super().__init__(*args, **kwargs)
    self._initialized = True

codes.formula.DoubleComparisonFormula.lhs property

lhs: float

Property for getting the left-hand side of the double comparison.

Returns:

  • float

    The left-hand side value of the comparison.

codes.formula.DoubleComparisonFormula.rhs property

rhs: float

Property for getting the right-hand side of the double comparison.

Returns:

  • float

    The right-hand side value of the comparison.

codes.formula.DoubleComparisonFormula.val property

val: float

Property for getting the middle value of the double comparison to be checked against the bounds.

Returns:

  • float

    The left-hand side value of the comparison.

codes.formula.Formula

Formula(*args, **kwargs)

Bases: float, ABC

Abstract base class for formulas used in the codes.

Method for initializing a new instance of the class.

Source code in blueprints/codes/formula.py
21
22
23
24
def __init__(self, *args, **kwargs) -> None:
    """Method for initializing a new instance of the class."""
    super().__init__(*args, **kwargs)
    self._initialized = True

codes.formula.Formula.detailed_result property

detailed_result: dict

Property for providing the detailed result of the formula.

Returns:

  • dict

    The detailed result of the formula. Keys are strings representing the name of the partial or intermediate result. Values types will depend on the specific implementation, but must be a serializable type.

codes.formula.Formula.label abstractmethod property

label: str

Property for the formula label.

For example, "5.2" for formula 5.2.

Returns:

  • str

    The label/number associated with the formula. This is an abstract method and must be implemented in all subclasses.

codes.formula.Formula.source_document abstractmethod property

source_document: str

Property for the source document.

For example, "EN 1992-1-1:2004" Try to use the official and complete name of the document including publishing year, if possible.

Returns:

  • str

    The reference to the document where the formula originates. This is an abstract method and must be implemented in all subclasses.

codes.formula.Formula.latex abstractmethod

latex(n: int = 3) -> LatexFormula

Abstract method for the latex representation of the formula, given in math mode.

Parameters:

  • n (int, default: 3 ) –

    The number of decimal places to round the result to.

Returns:

  • LatexFormula

    The latex representation of the formula, given in math mode. This is an abstract method and must be implemented in all subclasses.

Source code in blueprints/codes/formula.py
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
@abstractmethod
def latex(self, n: int = 3) -> LatexFormula:
    """Abstract method for the latex representation of the formula, given in math mode.

    Parameters
    ----------
    n : int, optional
        The number of decimal places to round the result to.

    Returns
    -------
    LatexFormula
        The latex representation of the formula, given in math mode.
        This is an abstract method and must be implemented in all subclasses.
    """