Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
add results counts on phenotype api
Browse files Browse the repository at this point in the history
  • Loading branch information
charhart committed Aug 14, 2018
1 parent 86f739b commit 75f1314
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
20 changes: 18 additions & 2 deletions nlp/apis/phenotype_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,24 @@ def get_paged_phenotype_results(job_id: int, phenotype_final_str: str):
if phenotype_final_str == 't' or phenotype_final_str == 'true' or phenotype_final_str == 'yes':
phenotype_final = True
last_id = request.args.get('last_id', '')
results = paged_phenotype_results(str(job_id), phenotype_final, last_id)
res = paged_phenotype_results(str(job_id), phenotype_final, last_id)

return json.dumps(results, indent=4, default=str)
return json.dumps(res, indent=4, default=str)
except Exception as e:
return "Failed to get job status" + str(e)


@phenotype_app.route('/phenotype_subjects/<int:job_id>/<string:phenotype_final_str>', methods=['GET'])
@auto.doc(groups=['public', 'private', 'phenotypes'])
def get_phenotype_subjects(job_id: int, phenotype_final_str: str):
"""GET phenotype_subjects"""
try:
phenotype_final = False
phenotype_final_str = phenotype_final_str.strip().lower()
if phenotype_final_str == 't' or phenotype_final_str == 'true' or phenotype_final_str == 'yes':
phenotype_final = True
res = phenotype_subjects(str(job_id), phenotype_final)

return json.dumps(res, indent=4, default=str)
except Exception as e:
return "Failed to get job status" + str(e)
2 changes: 1 addition & 1 deletion nlp/data_access/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
from .jobs import *
from .pipeline_config import get_pipeline_config, PipelineConfig, insert_pipeline_config
from .base_model import *
from .results import job_results, paged_phenotype_results
from .results import job_results, paged_phenotype_results, phenotype_subjects
from .phenotype import *
from .measurement_model import *
35 changes: 35 additions & 0 deletions nlp/data_access/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,41 @@ def paged_phenotype_results(job_id: str, phenotype_final: bool, last_id: str = '
return obj


def phenotype_subjects(job_id: str, phenotype_final: bool):
client = MongoClient(util.mongo_host, util.mongo_port)
db = client[util.mongo_db]
results = []
# db.phenotype_results.aggregate([ {"$match":{"job_id":{"$eq":10201}, "phenotype_final":{"$eq":true}}},
# {"$group" : {_id:"$subject", count:{$sum:1}}} ])
try:
q = [
{
"$match": {
"phenotype_final": {
"$eq": phenotype_final
},
"job_id": {
"$eq": int(job_id)
}
}},
{
"$group": {
"_id": "$subject",
"count": {
"$sum": 1
}
}
}
]
results = list(db.phenotype_results.aggregate(q))
except Exception as e:
traceback.print_exc(file=sys.stdout)
finally:
client.close()

return results


def remove_tmp_file(filename):
if filename:
os.remove(filename)
Expand Down

0 comments on commit 75f1314

Please sign in to comment.