Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Added support for `ctPrimScalingFactor` which is required when calculating new `ctPrim` value when feeder proxy loads are not in use.

### Enhancements
* None.
* Supports passing a list of feeders to `run_hosting_capacity_calibration` to perform calibration on a subset of the network.

### Fixes
* None.
Expand Down
27 changes: 16 additions & 11 deletions src/zepben/eas/client/eas_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from hashlib import sha256
from http import HTTPStatus
from json import dumps
from typing import Optional
from typing import Optional, List

import aiohttp
from aiohttp import ClientSession
Expand Down Expand Up @@ -880,36 +880,39 @@ async def async_upload_study(self, study: Study):
response = await response.text()
return response

def run_hosting_capacity_calibration(self, calibration_name: str, local_calibration_time: Optional[str] = None):
def run_hosting_capacity_calibration(self, calibration_name: str, local_calibration_time: Optional[str] = None, feeders: Optional[List[str]] = None):
"""
Send request to run hosting capacity calibration
:param calibration_name: A string representation of the calibration name
:param local_calibration_time: A string representation of the calibration time, in model time.
:param feeders: A list of feeder ID's to run the calibration over. If not supplied then the calibration is run over all feeders in the network.
:return: The HTTP response received from the Evolve App Server after attempting to run the calibration
"""
return get_event_loop().run_until_complete(
self.async_run_hosting_capacity_calibration(calibration_name, local_calibration_time))
self.async_run_hosting_capacity_calibration(calibration_name, local_calibration_time, feeders))

async def async_run_hosting_capacity_calibration(self, calibration_name: str,
calibration_time_local: Optional[str] = None):
calibration_time_local: Optional[str] = None, feeders: Optional[List[str]] = None):
"""
Send asynchronous request to run hosting capacity calibration
:param calibration_name: A string representation of the calibration name
:param calibration_time_local: A string representation of the calibration time, in model time.
:param feeders: A list of feeder ID's to run the calibration over. If not supplied then the calibration is run over all feeders in the network.
:return: The HTTP response received from the Evolve App Server after attempting to run the calibration
"""
with warnings.catch_warnings():
if not self._verify_certificate:
warnings.filterwarnings("ignore", category=InsecureRequestWarning)
json = {
"query": """
mutation runCalibration($calibrationName: String!, $calibrationTimeLocal: LocalDateTime) {
runCalibration(calibrationName: $calibrationName, calibrationTimeLocal: $calibrationTimeLocal)
mutation runCalibration($calibrationName: String!, $calibrationTimeLocal: LocalDateTime, $feeders: [String!]) {
runCalibration(calibrationName: $calibrationName, calibrationTimeLocal: $calibrationTimeLocal, feeders: $feeders)
}
""",
"variables": {
"calibrationName": calibration_name,
"calibrationTimeLocal": calibration_time_local
"calibrationTimeLocal": calibration_time_local,
"feeders": feeders
}
}

Expand Down Expand Up @@ -957,6 +960,8 @@ async def async_get_hosting_capacity_calibration_run(self, id: str):
startAt
completedAt
status
feeders
calibrationWorkPackageConfig
}
}
""",
Expand Down Expand Up @@ -1399,16 +1404,16 @@ async def async_get_opendss_model_download_url(self, run_id: int):

def get_opendss_model(self, model_id: int):
"""
Retrieve information of a hosting capacity calibration run
:param model_id: The openDss model export ID
Retrieve information of a OpenDss model export
:param model_id: The OpenDss model export ID
:return: The HTTP response received from the Evolve App Server after requesting the openDss model info
"""
return get_event_loop().run_until_complete(self.async_get_opendss_model(model_id))

async def async_get_opendss_model(self, model_id: int):
"""
Retrieve information of a hosting capacity calibration run
:param model_id: The openDss model export ID
Retrieve information of a OpenDss model export
:param model_id: The OpenDss model export ID
:return: The HTTP response received from the Evolve App Server after requesting the openDss model info
"""

Expand Down
13 changes: 7 additions & 6 deletions test/test_eas_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,8 @@ def hosting_capacity_run_calibration_request_handler(request):
actual_body = json.loads(request.data.decode())
query = " ".join(actual_body['query'].split())

assert query == "mutation runCalibration($calibrationName: String!, $calibrationTimeLocal: LocalDateTime) { runCalibration(calibrationName: $calibrationName, calibrationTimeLocal: $calibrationTimeLocal) }"
assert actual_body['variables'] == {"calibrationName": "TEST CALIBRATION", "calibrationTimeLocal": None}
assert query == "mutation runCalibration($calibrationName: String!, $calibrationTimeLocal: LocalDateTime, $feeders: [String!]) { runCalibration(calibrationName: $calibrationName, calibrationTimeLocal: $calibrationTimeLocal, feeders: $feeders) }"
assert actual_body['variables'] == {"calibrationName": "TEST CALIBRATION", "calibrationTimeLocal": None, "feeders": None}

return Response(json.dumps({"result": "success"}), status=200, content_type="application/json")

Expand Down Expand Up @@ -663,7 +663,7 @@ def get_hosting_capacity_run_calibration_request_handler(request):
actual_body = json.loads(request.data.decode())
query = " ".join(actual_body['query'].split())

assert query == "query getCalibrationRun($id: ID!) { getCalibrationRun(id: $id) { id name workflowId runId calibrationTimeLocal startAt completedAt status } }"
assert query == "query getCalibrationRun($id: ID!) { getCalibrationRun(id: $id) { id name workflowId runId calibrationTimeLocal startAt completedAt status feeders calibrationWorkPackageConfig } }"
assert actual_body['variables'] == {"id": "calibration-id"}

return Response(json.dumps({"result": "success"}), status=200, content_type="application/json")
Expand Down Expand Up @@ -717,9 +717,10 @@ def hosting_capacity_run_calibration_with_calibration_time_request_handler(reque
actual_body = json.loads(request.data.decode())
query = " ".join(actual_body['query'].split())

assert query == "mutation runCalibration($calibrationName: String!, $calibrationTimeLocal: LocalDateTime) { runCalibration(calibrationName: $calibrationName, calibrationTimeLocal: $calibrationTimeLocal) }"
assert query == "mutation runCalibration($calibrationName: String!, $calibrationTimeLocal: LocalDateTime, $feeders: [String!]) { runCalibration(calibrationName: $calibrationName, calibrationTimeLocal: $calibrationTimeLocal, feeders: $feeders) }"
assert actual_body['variables'] == {"calibrationName": "TEST CALIBRATION",
"calibrationTimeLocal": "1992-01-28T00:00:20"}
"calibrationTimeLocal": "1992-01-28T00:00:20",
"feeders": ["one", "two"]}

return Response(json.dumps({"result": "success"}), status=200, content_type="application/json")

Expand All @@ -733,7 +734,7 @@ def test_run_hosting_capacity_calibration_with_calibration_time_no_verify_succes

httpserver.expect_oneshot_request("/api/graphql").respond_with_handler(
hosting_capacity_run_calibration_with_calibration_time_request_handler)
res = eas_client.run_hosting_capacity_calibration("TEST CALIBRATION", "1992-01-28T00:00:20")
res = eas_client.run_hosting_capacity_calibration("TEST CALIBRATION", "1992-01-28T00:00:20", ["one", "two"])
httpserver.check_assertions()
assert res == {"result": "success"}

Expand Down