app.conversion.validation_utils

Validation utilities for conversion operations.

This module contains validation functions that are commonly used across different conversion classes to ensure data integrity and proper error handling.

handle_time_bounds(actual_time, pulp_var, variable_name='variable')

Handle time bounds checking for time-indexed variables with proper warnings.

Parameters:

actual_time : int The requested time index pulp_var : Any The PuLP variable (usually a list or dict-like object) variable_name : str Name of the variable for warning messages

Returns:

int The adjusted time index within valid bounds

validate_and_normalize_time_set(time_set, default_size=10)

Validate and normalize time_set parameter to a range object.

Parameters

time_set : Optional[Union[int, range]] The time set to validate and normalize. Can be: - None: uses default_size - int: converted to range(time_set) - range: returned as-is default_size : int, default=10 Default size to use if time_set is None

Returns

range Normalized time set as a range object

Raises

ValueError If time_set is not a valid type or if int time_set is negative

Examples

validate_and_normalize_time_set(5) range(0, 5) validate_and_normalize_time_set(None, 3) range(0, 3)

validate_entity_exists(entity_id, entity_dict)

Validate that an entity exists in the provided dictionary.

Parameters

entity_id : str The entity ID to validate entity_dict : dict Dictionary containing entity mappings

Raises

ValueError If entity_id is not found in entity_dict

Examples

entities = {'battery': [1, 2, 3], 'solar': [4, 5, 6]} validate_entity_exists('battery', entities) # No error validate_entity_exists('wind', entities) # Raises ValueError

validate_linear_programming_constraint(left_operand, right_operand, operation)

Validate that an operation maintains linear programming constraints.

Parameters:

left_operand : Any Left side of the operation right_operand : Any Right side of the operation operation : str Type of operation ("multiplication" or "division")

Raises:

ValueError If the operation violates linear programming constraints