Skip to content

Commit

Permalink
Merge pull request #37 from NREL/update-response-text
Browse files Browse the repository at this point in the history
Use run_id and update response text format
  • Loading branch information
TShapinsky authored Sep 30, 2022
2 parents a8b589b + 4bdee17 commit b6c3083
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
15 changes: 7 additions & 8 deletions alfalfa_client/alfalfa_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
****************************************************************************************************
"""

import json
from multiprocessing import Pool

import requests
Expand Down Expand Up @@ -154,7 +153,7 @@ def outputs(self, site_id):
payload = {'query': query}
response = requests.post(self.url + '/graphql', json=payload)

j = json.loads(response.text)
j = response.json()
points = j["data"]["viewer"]["sites"][0]["points"]
result = {}

Expand All @@ -176,7 +175,7 @@ def all_cur_points(self, site_id):
payload = {'query': query}
response = requests.post(self.url + '/graphql', json=payload)

j = json.loads(response.text)
j = response.json()
points = j["data"]["viewer"]["sites"][0]["points"]
result = []

Expand All @@ -196,7 +195,7 @@ def all_cur_points_with_units(self, site_id):
payload = {'query': query}
response = requests.post(self.url + '/graphql', json=payload)

j = json.loads(response.text)
j = response.json()
points = j["data"]["viewer"]["sites"][0]["points"]
result = {}

Expand All @@ -216,7 +215,7 @@ def get_sim_time(self, site_id):
payload = {'query': query}
response = requests.post(self.url + '/graphql', json=payload)

j = json.loads(response.text)
j = response.json()
dt = j["data"]["viewer"]["runs"]["sim_time"]
return dt

Expand All @@ -229,7 +228,7 @@ def all_writable_points(self, site_id):
payload = {'query': query}
response = requests.post(self.url + '/graphql', json=payload)

j = json.loads(response.text)
j = response.json()
points = j["data"]["viewer"]["sites"][0]["points"]
result = []

Expand All @@ -247,7 +246,7 @@ def all_cur_writable_points(self, site_id):
payload = {'query': query}
response = requests.post(self.url + '/graphql', json=payload)

j = json.loads(response.text)
j = response.json()
points = j["data"]["viewer"]["sites"][0]["points"]
result = []

Expand Down Expand Up @@ -323,7 +322,7 @@ def inputs(self, site_id):
payload = {'query': query}
response = requests.post(self.url + '/graphql', json=payload)

j = json.loads(response.text)
j = response.json()
points = j["data"]["viewer"]["sites"][0]["points"]
result = {}

Expand Down
11 changes: 6 additions & 5 deletions alfalfa_client/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
****************************************************************************************************
"""

import json
import os
import time
import uuid
Expand Down Expand Up @@ -70,7 +69,7 @@ def status(url, run_id):
if response.status_code != 200:
print("Could not get status")

j = json.loads(response.text)
j = response.json()
runs = j["data"]["viewer"]["runs"]
if runs:
status = runs["status"]
Expand All @@ -89,7 +88,7 @@ def get_error_log(url, run_id):
if response.status_code != 200:
print("Could not get error log")

j = json.loads(response.text)
j = response.json()
runs = j["data"]["viewer"]["runs"]
if runs:
error_log = runs["error_log"]
Expand Down Expand Up @@ -155,16 +154,18 @@ def submit_one(args):
# After the file has been uploaded, then tell BOPTEST to process the site
# This is done not via the haystack api, but through a graphql api
mutation = 'mutation { addSite(modelName: "%s", uploadID: "%s") }' % (filename, uid)
run_id = None
for _ in range(3):
response = requests.post(url + '/graphql', json={'query': mutation})
if response.status_code == 200:
run_id = response.json()['data']['addSite']
break
if response.status_code != 200:
print("Could not addSite")

wait(url, uid, "READY")
wait(url, run_id, "READY")

return uid
return run_id


def start_one(args):
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ envlist = python3.7, python3.8, python3.9
whitelist_externals = poetry
commands =
poetry install -v
poetry run pytest tests/
poetry run pytest tests
poetry run pre-commit run -a

0 comments on commit b6c3083

Please sign in to comment.