across.tools.visibility.constraints_constructor

Constraint JSON serialization and deserialization utilities.

This module provides functions for converting between Constraint objects and their JSON string representations. It handles the serialization and deserialization of constraint data for storage, transmission, or configuration purposes.

Functions

constraint_from_jsonfunction

Load constraints from a JSON string into Constraint objects.

constraint_to_jsonfunction

Convert Constraint objects to a JSON string representation.

Dependencies

  • json : Standard library JSON handling

  • .constraints : Local module containing Constraint and Constraints classes

Examples

>>> constraints_json = '[{"short_name": "Sun", "name": "Sun Angle", "min_angle": 45.0}]'
>>> constraints = constraint_from_json(constraints_json)
>>> json_output = constraint_to_json(constraints)

Attributes

Constraints

Classes

Constraint

Model for deserializing a single constraint.

Functions

constraints_from_json(input)

Load constraints from a JSON string.

constraints_to_json(constraints)

Convert constraints to a JSON string.

Module Contents

Constraints: pydantic.TypeAdapter[list[across.tools.visibility.constraints.AllConstraint]][source]
class Constraint(/, **data)[source]

Bases: pydantic.BaseModel

Model for deserializing a single constraint.

root: across.tools.visibility.constraints.AllConstraint[source]
classmethod unwrap_input(data)[source]

Unwrap input data to extract constraint.

serialize_constraint()[source]

Serialize the constraint to a dictionary.

constraints_from_json(input)[source]

Load constraints from a JSON string.

Parameters:

input (str) – JSON string containing the constraints.

Returns:

Single Constraint object or list of Constraint objects loaded from the JSON string.

Return type:

AllConstraint | list[AllConstraint]

constraints_to_json(constraints)[source]

Convert constraints to a JSON string.

Parameters:

constraints (AllConstraint | list[AllConstraint]) – Single Constraint object or list of Constraint objects to convert.

Returns:

JSON string representation of the constraints.

Return type:

str