Fetching Network Hierarchy
This tutorial demonstrates how to use the SyncNetworkConsumerClient
to connect to a gRPC service and fetch information about a network hierarchy from the EWB server.
The code is organized to demonstrate how to establish a connection, retrieve the network hierarchy, and print the information in a structured manner.
Getting Started
Ensure that you have imported necessary modules from the Zepben library.
from zepben.evolve import SyncNetworkConsumerClient, connect_insecure
Establish Connection
Ensure that you have connected to the EWB Server. In this example, the connect_insecure
function is used to connect to the EWB Server.
channel = connect_insecure(host="EWB Hostname", rpc_port=1234)
You will need to replace the host and port with the appropriate values for your environment. More information about connecting to the EWB Server using different methods can be found in the Connecting to the EWB Server guide.
Create a Consumer Client
After establishing the connection, create a SyncNetworkConsumerClient
using the provided channel.
client = SyncNetworkConsumerClient(channel=channel)
Fetch and Display Network Hierarchy
You can fetch the network hierarchy by calling the get_network_hierarchy
method on the SyncNetworkConsumerClient
instance.
Once you have fetched the network hierarchy, you can iterate through the hierarchical structure and print information about each level (that is the geographical regions, sub-geographical regions, substations, and feeders).
In this example, indentation is used to help represent the hierarchical relationships clearly.
network_hierarchy = client.get_network_hierarchy()
print("Network hierarchy:")
for gr in network_hierarchy.result.geographical_regions.values():
print(f"- {gr.name}")
for sgr in gr.sub_geographical_regions:
print(f" - {sgr.name}")
for sub in sgr.substations:
print(f" - {sub.name}")
for fdr in sub.feeders:
print(f" - {fdr.name}")
Sample Output: