Skip to content

Commit f4c95bd

Browse files
authored
[DEV 3374] Add example for feeder load analysis (#22)
Signed-off-by: Jimmy Tung <jimmy.tung@zepben.com>
1 parent 3cb9e37 commit f4c95bd

File tree

5 files changed

+105
-12
lines changed

5 files changed

+105
-12
lines changed

changelog.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,17 @@
5151
* Translating a CIM network model into a pandapower model
5252
* Requesting a PowerFactory model through the SDK
5353
* Manipulating the current state of the network, including swapping a zone open point.
54+
* Added Example for requesting feeder load analysis study through EAS client.
5455

5556
### Enhancements
5657
* Limited power factory demo to 1 job at a time.
5758
* Added model download function to power factory demo
5859
* restrict installation to supported Python versions from 3.9 to 3.11
60+
* update request power factory models to use new authentication method
5961

6062
### Fixes
6163
* None.
6264

6365
### Notes
64-
* Support `zepben.eas` up to 0.16.0.
65-
* Support `zepben.evolve` up to 0.44.0.
66+
* Support `zepben.eas` up to 0.19.0.
67+
* Support `zepben.evolve` up to 0.48.0.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright 2025 Zeppelin Bend Pty Ltd
2+
#
3+
# This Source Code Form is subject to the terms of the Mozilla Public
4+
# License, v. 2.0. If a copy of the MPL was not distributed with this
5+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
6+
import asyncio
7+
import sys
8+
9+
from zepben.eas.client.feeder_load_analysis_input import FeederLoadAnalysisInput
10+
11+
from zepben.examples.utils import get_config_dir, get_client
12+
13+
14+
async def main(argv):
15+
# See connecting_to_grpc_service.py for examples of each connect function
16+
config_dir = get_config_dir(argv)
17+
print("Connecting to EAS..")
18+
eas_client = get_client(config_dir)
19+
print("Connection established..")
20+
# Fire off a feeder load analysis study
21+
feeder_load_analysis_token = await eas_client.async_run_feeder_load_analysis_report(
22+
FeederLoadAnalysisInput(
23+
feeders=["feeder1", "feeder2"],
24+
substations=None,
25+
sub_geographical_regions=None,
26+
geographical_regions=None,
27+
start_date="2022-04-01",
28+
end_date="2022-12-31",
29+
fetch_lv_network=True,
30+
process_feeder_loads=True,
31+
process_coincident_loads=True,
32+
aggregate_at_feeder_level=False,
33+
output="Test"
34+
)
35+
)
36+
37+
print(f"Feeder Load Analysis study: {feeder_load_analysis_token['data']['runFeederLoadAnalysis']}")
38+
39+
# Feeder Load Analysis Study results can be retrieved from back end storage set up with EAS.
40+
41+
await eas_client.aclose()
42+
43+
44+
if __name__ == "__main__":
45+
loop = asyncio.get_event_loop()
46+
loop.run_until_complete(main(sys.argv))

src/zepben/examples/request_power_factory_models.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,8 @@
3434
# graphQL endpoint access settings
3535
network_endpoint = 'https://{url}/api/network/graphql'
3636
api_endpoint = 'https://{url}/api/graphql'
37-
audience = "https://{url}/"
38-
issuer = "issuer_domain"
39-
client_id = 'client_id'
40-
username = 'username'
41-
password = 'password'
37+
#Generate a personal access token from the energy work bench UI and replace <Token>.
38+
token = 'Bearer <Token>'
4239

4340
### EXAMPLE QUERY ONLY ###
4441
# This is an example GraphQL query for the full network hierarchy. This is not used as part of this
@@ -70,10 +67,8 @@
7067
}
7168
}
7269
'''
73-
token_fetcher = get_token_fetcher(audience=audience, issuer=issuer, client_id=client_id, username=username, password=password)
74-
tft = token_fetcher.fetch_token()
75-
network_transport = RequestsHTTPTransport(url=network_endpoint, headers={'Authorization': tft})
76-
api_transport = RequestsHTTPTransport(url=api_endpoint, headers={'Authorization': tft})
70+
network_transport = RequestsHTTPTransport(url=network_endpoint, headers={'Authorization': token})
71+
api_transport = RequestsHTTPTransport(url=api_endpoint, headers={'Authorization': token})
7772

7873
network_client = Client(transport=network_transport)
7974
api_client = Client(transport=api_transport)
@@ -261,7 +256,7 @@ def download_model(model_number):
261256
model_status = result['powerFactoryModelById']['state']
262257
match model_status:
263258
case 'COMPLETED':
264-
model = requests.get(model_url, headers={'Authorization': tft})
259+
model = requests.get(model_url, headers={'Authorization': token})
265260
open(os.path.join(output_dir, file_name) + ".pfd", 'wb').write(model.content)
266261
print(file_name + ".pfd saved at " + output_dir)
267262
case "CREATION":
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"eas_server": {
3+
"host": "<URL>",
4+
"port": 1234,
5+
"protocol": "https",
6+
"client_id": "<EAS Client ID>",
7+
"access_token": "<Access Token>",
8+
"verify_certificate": false,
9+
"ca_filename": null
10+
}
11+
}

src/zepben/examples/utils.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright 2025 Zeppelin Bend Pty Ltd
2+
#
3+
# This Source Code Form is subject to the terms of the Mozilla Public
4+
# License, v. 2.0. If a copy of the MPL was not distributed with this
5+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
6+
import json
7+
from typing import Dict
8+
9+
from zepben.eas.client.eas_client import EasClient
10+
11+
import logging
12+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s: %(message)s')
13+
logger = logging.getLogger()
14+
15+
16+
# Default config dir is where the sample_auth_config sits.
17+
def get_config_dir(argv):
18+
return argv[1] if len(argv) > 1 else "."
19+
20+
21+
def read_json_config(config_file_path: str) -> Dict:
22+
file = open(config_file_path)
23+
config_dict = json.load(file)
24+
file.close()
25+
return config_dict
26+
27+
28+
def get_client(config_dir):
29+
# Change sample_auth_config.json to any other file name
30+
auth_config = read_json_config(f"{config_dir}/sample_auth_config.json")
31+
32+
return EasClient(
33+
host=auth_config["eas_server"]["host"],
34+
port=auth_config["eas_server"]["port"],
35+
protocol=auth_config["eas_server"]["protocol"],
36+
access_token=auth_config["eas_server"]["access_token"],
37+
verify_certificate=auth_config["eas_server"].get("verify_certificate", True),
38+
ca_filename=auth_config["eas_server"].get("ca_filename")
39+
)

0 commit comments

Comments
 (0)