Scripting#

Classes for Rhai scripting integration and criteria verification.

Script Engine#

class ScriptEngine#

Rhai script execution engine.

run_script_file(path, context)#

Run a Rhai script from file.

Parameters:
  • path (str) – Path to .rhai script file

  • context (CriteriaContext) – Data context for the script

Returns:

Verification result

Return type:

CriteriaResult

Raises:

ValueError – If script execution fails

run_script(script, context)#

Run a Rhai script from string.

Parameters:
  • script (str) – Rhai script content

  • context (CriteriaContext) – Data context for the script

Returns:

Verification result

Return type:

CriteriaResult

Criteria Context#

class CriteriaContext#

Context for Rhai scripts, wrapping stability results.

static from_result(result, vessel_name, loading_condition)#

Create a context from a CompleteStabilityResult.

Parameters:
  • result (CompleteStabilityResult) – The stability calculation result

  • vessel_name (str) – Name of the vessel

  • loading_condition (str) – Description of loading condition

Return type:

CriteriaContext

set_param(key, value)#

Set a parameter accessible to the script.

Parameters:
  • key (str) – Parameter name

  • value (Union[str, float, bool]) – Parameter value (str, float, or bool)

get_first_flooding_angle()#

Get the first angle where downflooding occurs.

Returns:

Angle in degrees or None

Return type:

Optional[float]

find_equilibrium_angle(heeling_arm)#

Find the first stable equilibrium angle (where GZ = heeling_arm).

Parameters:

heeling_arm (float) – Heeling arm lever in meters

Returns:

Angle in degrees or None

Return type:

Optional[float]

find_second_intercept(heeling_arm)#

Find the second intercept angle (unstable equilibrium).

Parameters:

heeling_arm (float) – Heeling arm lever in meters

Returns:

Angle in degrees or None

Return type:

Optional[float]

Criteria Result#

class CriteriaResult#

Result of a criteria verification script.

overall_pass: bool#

Whether all criteria passed.

pass_count: int#

Number of passing criteria.

fail_count: int#

Number of failing criteria.

criteria: list[CriterionResult]#

List of individual criterion results.

plots: list[str]#

List of plots data as JSON strings.

Criterion Result#

class CriterionResult#

Result of a single criterion check.

name: str#
status: str#

‘PASS’, ‘FAIL’, ‘WARN’, or ‘N/A’.

actual_value: float#
required_value: float#
unit: str#
margin: float#
notes: str#
plot_id: str#

ID of the associated plot, if any.