Rules¶
pyconvexity.validation.rules
¶
Validation rules and operations for PyConvexity.
Provides validation logic for component attributes, data types, and timeseries alignment.
get_validation_rule(conn: sqlite3.Connection, component_type: str, attribute_name: str) -> ValidationRule
¶
Get validation rule for a specific component type and attribute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
Database connection |
required |
component_type
|
str
|
Type of component (e.g., "BUS", "GENERATOR") |
required |
attribute_name
|
str
|
Name of the attribute |
required |
Returns:
| Type | Description |
|---|---|
ValidationRule
|
ValidationRule object with all validation information |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If no validation rule is found |
list_validation_rules(conn: sqlite3.Connection, component_type: str) -> List[ValidationRule]
¶
List validation rules for a component type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
Database connection |
required |
component_type
|
str
|
Type of component |
required |
Returns:
| Type | Description |
|---|---|
List[ValidationRule]
|
List of ValidationRule objects |
get_all_validation_rules(conn: sqlite3.Connection) -> Dict[str, Any]
¶
Get all validation rules from the database. This replaces the need to load the entire JSON file into memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
Database connection |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary mapping component types to their validation rules |
validate_static_value(value: StaticValue, rule: ValidationRule) -> None
¶
Validate static value against rule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
StaticValue
|
StaticValue to validate |
required |
rule
|
ValidationRule
|
ValidationRule to validate against |
required |
Raises:
| Type | Description |
|---|---|
InvalidDataType
|
If value type doesn't match rule |
validate_timeseries_alignment(conn: sqlite3.Connection, timeseries: List[float]) -> TimeseriesValidationResult
¶
Validate timeseries alignment with network periods (single network per database).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
Database connection |
required |
timeseries
|
List[float]
|
List of timeseries points to validate |
required |
Returns:
| Type | Description |
|---|---|
TimeseriesValidationResult
|
TimeseriesValidationResult with validation details |
parse_default_value(s: str) -> Optional[StaticValue]
¶
Parse default value string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s
|
str
|
String representation of default value |
required |
Returns:
| Type | Description |
|---|---|
Optional[StaticValue]
|
StaticValue object or None if parsing fails |
get_attribute_setter_info(conn: sqlite3.Connection, component_type: str, attribute_name: str) -> Dict[str, Any]
¶
Get the appropriate function name for setting an attribute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
Database connection |
required |
component_type
|
str
|
Type of component |
required |
attribute_name
|
str
|
Name of the attribute |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary with setter function information |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If attribute or data type is unknown |