diff --git a/changelog.md b/changelog.md index dc84a02..ea9c604 100644 --- a/changelog.md +++ b/changelog.md @@ -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. diff --git a/src/zepben/eas/client/eas_client.py b/src/zepben/eas/client/eas_client.py index 029b08d..eaee23d 100644 --- a/src/zepben/eas/client/eas_client.py +++ b/src/zepben/eas/client/eas_client.py @@ -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 @@ -880,22 +880,24 @@ 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(): @@ -903,13 +905,14 @@ async def async_run_hosting_capacity_calibration(self, calibration_name: str, 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 } } @@ -957,6 +960,8 @@ async def async_get_hosting_capacity_calibration_run(self, id: str): startAt completedAt status + feeders + calibrationWorkPackageConfig } } """, @@ -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 """ diff --git a/test/test_eas_client.py b/test/test_eas_client.py index 9ad38e5..bdd8ad0 100644 --- a/test/test_eas_client.py +++ b/test/test_eas_client.py @@ -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") @@ -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") @@ -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") @@ -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"}