Optimising your calculations

Tips and tricks on how to optimise your calculation pages.

To ensure your pages are fast, responsive, and easy to maintain, we recommend the following best practices when building calculations and reports:

Keep Page Size Manageable

Avoid building a single, oversized page that includes all aspects of your project. Instead:

  • Break your work into multiple pages (e.g. input summary, structural checks, charts/reporting).

  • Link pages together using subpages or workspace structure for modularity and clarity. [Cross page linking of parameter feature is coming soon].

Use Native Math Where Possible

Where you can, stick to native math notation and parameter definitions (i.e. mathjs formulas) in the page. These run faster and allow you to build dynamic, pretty, math notation.

Keep Python Code Sources Lightweight

If you're using Python for more complex functions, data manipulation or charting:

Avoid loading large libraries

For example, if you’re just reading and using table data, you likely don’t need pandas. It adds load time and memory use—especially for small files or simple logic. Instead, use Python’s built-in csv module:

import csv

def read_csv_native(filename):
    with open(ct.page_files[filename], mode='r', encoding='utf-8-sig') as f:
        reader = csv.DictReader(f)
        return [row for row in reader]

Example: Pulling Dimensions from a Section Table

def get_section_dims(section_name):
    rows = read_csv_native("sections.csv")
    for row in rows:
        if row["section"] == section_name:
            return float(row["b"]), float(row["d"])
    return None, None

Then assign it to variables ready to be referenced in the pafe.

[b, d] = get_section_dims("360UB56.7")

Keep code short

Keep and focused on a specific task (e.g. chart generation, table parsing). Create a new code source for different tasks.

Use Functions in Python

Where appropriate, move logic into Python functions to reduce clutter. Instead of defining several math variables which aren't all needed in your page, like this:

b = 300 mm
d = 500 mm
f_c = 32 MPa
phi = 0.9
alpha_2 = 0.85
M_u = phi * alpha_2 * f_c * b * d^2

You can wrap the logic into a Python function:

def design_moment_capacity(b, d, f_c, phi=0.9, alpha_2=0.85):
    """
    Calculates the ultimate moment capacity of a rectangular concrete section.
    Units should be consistent (e.g. mm and MPa).
    """
    M_u = phi * alpha_2 * f_c * b * d**2
    return M_u

Then define a single variable, which you can reference from page parameters:

M_u = design_moment_capacity(300 mm, 500 mm, 32 MPa)

Why This Helps

  • You hide complexity in the Python code, keeping your page cleaner.

  • You reduce the number of intermediate parameters (e.g. phi, alpha_2) cluttering your UI.

  • You can re-use the same function across multiple pages or checks (e.g. for T-beams, doubly reinforced sections, etc.).

  • You maintain flexibility to edit formulas in one place.

Last updated