Skip to content

Commit

Permalink
BLD: Added perf handling
Browse files Browse the repository at this point in the history
  • Loading branch information
AvishaiW committed Jul 22, 2018
1 parent 0ddc6c4 commit 51c97dd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 19 deletions.
3 changes: 1 addition & 2 deletions catalyst/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ def live(ctx,
@click.option(
'-o',
'--output',
default='-',
metavar='FILENAME',
show_default=True,
help="The location to write the perf data. If this is '-' the perf"
Expand Down Expand Up @@ -699,8 +700,6 @@ def run(ctx,

if output == '-':
click.echo(str(perf), sys.stdout)
elif output is None:
pass
elif output != os.devnull: # make the catalyst magic not write any data
perf.to_pickle(output)

Expand Down
53 changes: 36 additions & 17 deletions catalyst/utils/run_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,40 @@ def convert_date(date):
return date.__str__()


def handle_response(response):
"""
handles the response given by the server according to it's status code
:param response: the format returned from a request
:return: DataFrame/ str
"""
if response.status_code == 500:
raise Exception("issues with cloud connections, "
"unable to run catalyst on the cloud")
elif response.status_code == 502:
raise Exception("The server is down at the moment, please contact "
"Catalyst support to fix this issue at "
"https://github.com/enigmampc/catalyst/issues/")
elif response.status_code == 202 or response.status_code == 400:
return response.json()['error'] if response.json()['error'] else None

else: # if the run was successful
return json_to_df(response.json())


def json_to_df(json):
"""
converts the data returned from the algorithm run from base64 to DF
:param json: the response in a json format
:return: data_perf: the data in a DataFrame format
"""
data_perf_compressed = base64.b64decode(json["data"])
data_perf_pickled = zlib.decompress(data_perf_compressed)
data_perf = pickle.loads(data_perf_pickled)
return data_perf


def run_server(
initialize,
handle_data,
Expand Down Expand Up @@ -76,7 +110,7 @@ def run_server(
):

# address to send
url = 'http://34.202.72.107:5000/api/catalyst/serve'
url = 'https://34.202.72.107/api/catalyst/serve'
# url = 'http://127.0.0.1:5000/api/catalyst/serve'

# argument preparation - encode the file for transfer
Expand Down Expand Up @@ -126,19 +160,4 @@ def run_server(
controller.stop()
subscriber.close()

if response.status_code == 500:
raise Exception("issues with cloud connections, "
"unable to run catalyst on the cloud")
elif response.status_code == 502:
raise Exception("The server is down at the moment, please contact "
"Catalyst support to fix this issue at "
"https://github.com/enigmampc/catalyst/issues/")
elif response.status_code == 202 or response.status_code == 400:
print(response.json()['error']) if response.json()['error'] else None

else: # if the run was successful
received_data = response.json()
data_perf_compressed = base64.b64decode(received_data["data"])
data_perf_pickled = zlib.decompress(data_perf_compressed)
data_perf = pickle.loads(data_perf_pickled)
print(data_perf)
return handle_response(response)

0 comments on commit 51c97dd

Please sign in to comment.