Skip to content

Commit

Permalink
add payload property to all responses
Browse files Browse the repository at this point in the history
  • Loading branch information
TShapinsky committed Dec 7, 2023
1 parent d31b094 commit f692e1c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions alfalfa_client/alfalfa_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def status(self, run_id: Union[RunID, List[RunID]]) -> str:
:returns: status of run
"""
response = self._request(f"runs/{run_id}", method="GET").json()
return response["status"]
return response["payload"]["status"]

@parallelize
def get_error_log(self, run_id: Union[RunID, List[RunID]]) -> str:
Expand All @@ -109,7 +109,7 @@ def get_error_log(self, run_id: Union[RunID, List[RunID]]) -> str:
:returns: error log from run
"""
response = self._request(f"runs/{run_id}", method="GET").json()
return response["errorLog"]
return response["payload"]["errorLog"]

@parallelize
def wait(self, run_id: Union[RunID, List[RunID]], desired_status: str, timeout: float = 600) -> None:
Expand All @@ -130,7 +130,7 @@ def wait(self, run_id: Union[RunID, List[RunID]], desired_status: str, timeout:
if e.response.status_code != 404:
raise e

if current_status == "error":
if current_status == "ERROR":
error_log = self.get_error_log(run_id)
raise AlfalfaException(error_log)

Expand All @@ -154,7 +154,7 @@ def upload_model(self, model_path: os.PathLike) -> ModelID:
payload = {'modelName': filename}

response = self._request('models/upload', parameters=payload)
response_body = response.json()
response_body = response.json()["payload"]
post_url = response_body['url']

model_id = response_body['modelID']
Expand All @@ -176,7 +176,7 @@ def create_run_from_model(self, model_id: Union[ModelID, List[ModelID]], wait_fo
:returns: id of run created"""
response = self._request(f"models/{model_id}/createRun")
run_id = response.json()["runID"]
run_id = response.json()["payload"]["runID"]

if wait_for_status:
self.wait(run_id, "ready")
Expand Down Expand Up @@ -258,7 +258,7 @@ def get_inputs(self, run_id: str) -> List[str]:

response = self._request(f"runs/{run_id}/points", method="POST",
parameters={ "pointTypes": ["INPUT", "BIDIRECTIONAL"]})
response_body = response.json()
response_body = response.json()["payload"]
inputs = []
for point in response_body:
if point["name"] != "":
Expand All @@ -284,7 +284,7 @@ def get_outputs(self, run_id: str) -> dict:
:returns: dictionary of output names and values"""
response = self._request(f"runs/{run_id}/points/values", method="POST",
parameters={ "pointTypes": ["OUTPUT", "BIDIRECTIONAL"]})
response_body = response.json()
response_body = response.json()["payload"]
outputs = {}
for point in response_body:
name = self._get_point_translation(run_id, point["id"])
Expand All @@ -303,7 +303,7 @@ def get_sim_time(self, run_id: Union[RunID, List[RunID]]) -> datetime:
:returns: datetime of site
"""
response = self._request(f"runs/{run_id}/time", method="GET")
response_body = response.json()
response_body = response.json()["payload"]
return datetime.strptime(response_body["time"], '%Y-%m-%d %H:%M:%S')

def set_alias(self, alias: str, run_id: RunID) -> None:
Expand All @@ -321,7 +321,7 @@ def get_alias(self, alias: str) -> RunID:
:returns: Id of run associated with alias"""

response = self._request(f"aliases/{alias}", method="GET")
response_body = response.json()
response_body = response.json()["payload"]
return response_body

def _get_point_translation(self, *args):
Expand All @@ -335,6 +335,6 @@ def _get_point_translation(self, *args):

def _fetch_points(self, run_id):
response = self._request(f"runs/{run_id}/points", method = "GET")
for point in response.json():
for point in response.json()["payload"]:
self.point_translation_map[(run_id, point["name"])] = point["id"]
self.point_translation_map[(run_id, point["id"])] = point["name"]

0 comments on commit f692e1c

Please sign in to comment.