Network¶
pyconvexity.models.network
¶
Network management operations for PyConvexity.
Provides operations for creating, managing, and querying energy system networks including time periods, carriers, and network configuration.
create_network(conn: sqlite3.Connection, request: CreateNetworkRequest) -> None
¶
Create network metadata (single network per database).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
Database connection |
required |
request
|
CreateNetworkRequest
|
Network creation request |
required |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If required fields are missing |
DatabaseError
|
If creation fails |
get_network_info(conn: sqlite3.Connection) -> Dict[str, Any]
¶
Get network information (single network per database).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
Database connection |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary with network information |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If network metadata doesn't exist |
get_network_time_periods(conn: sqlite3.Connection) -> List[TimePeriod]
¶
Get network time periods using optimized storage (single network per database).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
Database connection |
required |
Returns:
| Type | Description |
|---|---|
List[TimePeriod]
|
List of TimePeriod objects ordered by period_index |
list_networks(conn: sqlite3.Connection) -> List[Dict[str, Any]]
¶
Get network information (returns single network in list for backward compatibility).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
Database connection |
required |
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List with single network dictionary (for backward compatibility) |
get_first_network(conn: sqlite3.Connection) -> Optional[Dict[str, Any]]
¶
Get network (for backward compatibility with single-network-per-database).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
Database connection |
required |
Returns:
| Type | Description |
|---|---|
Optional[Dict[str, Any]]
|
Network dictionary or None if no network exists |
get_network_by_name(conn: sqlite3.Connection, name: str) -> Optional[Dict[str, Any]]
¶
Get network by name (for backward compatibility - checks if name matches).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
Database connection |
required |
name
|
str
|
Network name to match |
required |
Returns:
| Type | Description |
|---|---|
Optional[Dict[str, Any]]
|
Network dictionary if name matches, None otherwise |
create_carrier(conn: sqlite3.Connection, name: str, co2_emissions: float = 0.0, color: Optional[str] = None, nice_name: Optional[str] = None) -> int
¶
Create a carrier record and return carrier ID (single network per database).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
Database connection |
required |
name
|
str
|
Carrier name |
required |
co2_emissions
|
float
|
CO2 emissions factor |
0.0
|
color
|
Optional[str]
|
Display color |
None
|
nice_name
|
Optional[str]
|
Human-readable name |
None
|
Returns:
| Type | Description |
|---|---|
int
|
ID of the newly created carrier |
list_carriers(conn: sqlite3.Connection) -> List[Dict[str, Any]]
¶
List all carriers (single network per database).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
Database connection |
required |
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List of carrier dictionaries |
get_network_config(conn: sqlite3.Connection, scenario_id: Optional[int] = None) -> Dict[str, Any]
¶
Get network configuration with scenario-aware fallback (single network per database).
Priority order: 1. Scenario-specific config (network_config WHERE scenario_id = X) 2. Network default config (network_config WHERE scenario_id IS NULL) 3. System default value
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
Database connection |
required |
scenario_id
|
Optional[int]
|
Optional scenario ID |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary with network configuration |
set_network_config(conn: sqlite3.Connection, param_name: str, param_value: Any, param_type: str, scenario_id: Optional[int] = None, description: Optional[str] = None) -> None
¶
Set network configuration parameter (single network per database).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
Database connection |
required |
param_name
|
str
|
Parameter name |
required |
param_value
|
Any
|
Parameter value |
required |
param_type
|
str
|
Parameter type ('boolean', 'real', 'integer', 'string', 'json') |
required |
scenario_id
|
Optional[int]
|
Optional scenario ID (NULL for base network) |
None
|
description
|
Optional[str]
|
Optional parameter description |
None
|
Raises:
| Type | Description |
|---|---|
ValidationError
|
If parameter type is invalid or serialization fails |
get_component_counts(conn: sqlite3.Connection) -> Dict[str, int]
¶
Get component counts by type (single network per database).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
Database connection |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, int]
|
Dictionary mapping component types to counts |