Skip to content

Commit

Permalink
Merge pull request #227 from dianakolusheva/api
Browse files Browse the repository at this point in the history
REST API
  • Loading branch information
bgyori committed Jun 4, 2021
2 parents f3ff08e + 478fac5 commit b695f7c
Show file tree
Hide file tree
Showing 4 changed files with 812 additions and 374 deletions.
18 changes: 11 additions & 7 deletions emmaa/model_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def answer_path_query(self, query):
else:
return [('', self.hash_response_list(
RESULT_CODES['QUERY_NOT_APPLICABLE']),
RESULT_CODES['QUERY_NOT_APPLICABLE'])]
[{'fail_reason': RESULT_CODES['QUERY_NOT_APPLICABLE']}])]

def answer_dynamic_query(self, query, bucket=EMMAA_BUCKET_NAME):
"""Answer user query by simulating a PySB model."""
Expand All @@ -366,9 +366,11 @@ def answer_dynamic_query(self, query, bucket=EMMAA_BUCKET_NAME):
fig_path = s3_path
resp_json = {'sat_rate': sat_rate, 'num_sim': num_sim,
'kpat': kpat, 'fig_path': fig_path}
return [('pysb', self.hash_response_list(resp_json),resp_json)]
except (MissingMonomerError, MissingMonomerSiteError):
resp_json = RESULT_CODES['QUERY_NOT_APPLICABLE']
return [('pysb', self.hash_response_list(resp_json), resp_json)]
return [('pysb', self.hash_response_list(resp_json),
{'fail_reason': RESULT_CODES['QUERY_NOT_APPLICABLE']})]

def answer_intervention_query(self, query, bucket=EMMAA_BUCKET_NAME):
"""Answer user intervention query by simulating a PySB model."""
Expand All @@ -392,9 +394,11 @@ def answer_intervention_query(self, query, bucket=EMMAA_BUCKET_NAME):
client.upload_file(fig_path, Bucket=bucket, Key=s3_key)
fig_path = s3_path
resp_json = {'result': res, 'fig_path': fig_path}
return [('pysb', self.hash_response_list(resp_json), resp_json)]
except (MissingMonomerError, MissingMonomerSiteError):
resp_json = RESULT_CODES['QUERY_NOT_APPLICABLE']
return [('pysb', self.hash_response_list(resp_json), resp_json)]
return [('pysb', self.hash_response_list(resp_json),
{'fail_reason': RESULT_CODES['QUERY_NOT_APPLICABLE']})]

def answer_open_query(self, query):
"""Answer user open search query with found paths."""
Expand All @@ -417,15 +421,15 @@ def answer_open_query(self, query):
else:
return [('', self.hash_response_list(
RESULT_CODES['QUERY_NOT_APPLICABLE']),
RESULT_CODES['QUERY_NOT_APPLICABLE'])]
[{'fail_reason': RESULT_CODES['QUERY_NOT_APPLICABLE']}])]

def open_query_per_mc(self, mc_type, mc, query, max_path_length,
max_paths):
g = mc.get_graph()
subj_nodes, obj_nodes, res_code = mc.process_statement(query.path_stmt)
if res_code:
return self.hash_response_list(RESULT_CODES[res_code]), \
RESULT_CODES[res_code]
[{'fail_reason': RESULT_CODES[res_code]}]
else:
if query.entity_role == 'subject':
reverse = False
Expand Down Expand Up @@ -603,15 +607,15 @@ def process_response(self, mc_type, result):
return self.hash_response_list(response), path_lines
else:
response = self.make_result_code(result)
return self.hash_response_list(response), response
return self.hash_response_list(response), [{'fail_reason': response}]

def process_open_query_response(self, mc_type, paths):
if paths:
response, path_lines = self.make_path_json(mc_type, paths)
return self.hash_response_list(response), path_lines
else:
response = 'No paths found that satisfy this query'
return self.hash_response_list(response), response
return self.hash_response_list(response), [{'fail_reason': response}]

def hash_response_list(self, response):
"""Return a dictionary mapping a hash with a response in a response
Expand Down

0 comments on commit b695f7c

Please sign in to comment.