diff --git a/qiita_pet/handlers/api_proxy/studies.py b/qiita_pet/handlers/api_proxy/studies.py index 58af3f0ac..94ea0bc69 100644 --- a/qiita_pet/handlers/api_proxy/studies.py +++ b/qiita_pet/handlers/api_proxy/studies.py @@ -206,6 +206,7 @@ def study_prep_get_req(study_id, user_id): prep_info = defaultdict(list) editable = study.can_edit(User(user_id)) for dtype in study.data_types: + dtype_infos = list() for prep in study.prep_templates(dtype): if prep.status != 'public' and not editable: continue @@ -214,11 +215,18 @@ def study_prep_get_req(study_id, user_id): 'name': prep.name, 'id': prep.id, 'status': prep.status, + 'total_samples': len(prep), + 'creation_timestamp': prep.creation_timestamp, + 'modification_timestamp': prep.modification_timestamp } if start_artifact is not None: youngest_artifact = prep.artifact.youngest_artifact info['start_artifact'] = start_artifact.artifact_type info['start_artifact_id'] = start_artifact.id + info['num_artifact_children'] = len(start_artifact.children) + info['youngest_artifact_name'] = youngest_artifact.name + info['youngest_artifact_type'] = \ + youngest_artifact.artifact_type info['youngest_artifact'] = '%s - %s' % ( youngest_artifact.name, youngest_artifact.artifact_type) info['ebi_experiment'] = len( @@ -228,9 +236,15 @@ def study_prep_get_req(study_id, user_id): info['start_artifact'] = None info['start_artifact_id'] = None info['youngest_artifact'] = None - info['ebi_experiment'] = False + info['ebi_experiment'] = 0 - prep_info[dtype].append(info) + dtype_infos.append(info) + + # default sort is in ascending order of creation timestamp + sorted_info = sorted(dtype_infos, + key=lambda k: k['creation_timestamp'], + reverse=False) + prep_info[dtype] = sorted_info return {'status': 'success', 'message': '', diff --git a/qiita_pet/handlers/api_proxy/tests/test_studies.py b/qiita_pet/handlers/api_proxy/tests/test_studies.py index 7adc7ac81..74826ab47 100644 --- a/qiita_pet/handlers/api_proxy/tests/test_studies.py +++ b/qiita_pet/handlers/api_proxy/tests/test_studies.py @@ -11,6 +11,7 @@ from os import remove from shutil import rmtree from tempfile import mkdtemp +from collections import defaultdict import pandas as pd import numpy.testing as npt @@ -228,15 +229,19 @@ def test_study_prep_get_req_failed_EBI(self): # actual test obs = study_prep_get_req(study.id, user_email) + temp_info = defaultdict(list) + temp_info['16S'] = [ + {"status": 'sandbox', + 'name': 'Prep information %d' % pt.id, + 'start_artifact': None, 'youngest_artifact': None, + 'ebi_experiment': False, 'id': pt.id, + 'start_artifact_id': None, + 'creation_timestamp': pt.creation_timestamp, + 'modification_timestamp': pt.modification_timestamp, + 'total_samples': 3}] + exp = { - 'info': { - '16S': [ - {'status': 'sandbox', - 'name': 'Prep information %d' % pt.id, - 'start_artifact': None, 'youngest_artifact': None, - 'ebi_experiment': False, 'id': pt.id, - 'start_artifact_id': None}] - }, + 'info': temp_info, 'message': '', 'status': 'success'} self.assertEqual(obs, exp) @@ -516,24 +521,43 @@ class TestStudyAPI2(TestStudyAPI): # This test expects a clean DB so creating it's own class def test_study_prep_get_req(self): obs = study_prep_get_req(1, 'test@foo.bar') + obs_info = obs['info']['18S'] + temp_info = defaultdict(list) + temp_info['18S'] = [{ + 'id': 1, + 'status': 'private', + 'name': 'Prep information 1', + 'start_artifact_id': 1, + 'start_artifact': 'FASTQ', + 'youngest_artifact': 'BIOM - BIOM', + 'youngest_artifact_name': 'BIOM', + 'youngest_artifact_type': 'BIOM', + 'num_artifact_children': 2, + 'total_samples': 27, + 'ebi_experiment': 27, + 'modification_timestamp': + obs_info[0]['modification_timestamp'], + 'creation_timestamp': + obs_info[0]['creation_timestamp']}, { + 'id': 2, + 'status': 'private', + 'name': 'Prep information 2', + 'start_artifact': 'BIOM', + 'youngest_artifact': 'BIOM - BIOM', + 'youngest_artifact_name': 'BIOM', + 'youngest_artifact_type': 'BIOM', + 'total_samples': 27, + 'num_artifact_children': 0, + 'ebi_experiment': 27, + 'start_artifact_id': 7, + 'modification_timestamp': + obs_info[1]['modification_timestamp'], + 'creation_timestamp': + obs_info[1]['creation_timestamp'] + }] exp = {'status': 'success', 'message': '', - 'info': { - '18S': [{ - 'id': 1, - 'status': 'private', - 'name': 'Prep information 1', - 'start_artifact_id': 1, - 'start_artifact': 'FASTQ', - 'youngest_artifact': 'BIOM - BIOM', - 'ebi_experiment': 27}, { - 'id': 2, - 'status': 'private', - 'name': 'Prep information 2', - 'start_artifact': 'BIOM', - 'youngest_artifact': 'BIOM - BIOM', - 'ebi_experiment': 27, - 'start_artifact_id': 7}]}} + 'info': temp_info} self.assertEqual(obs, exp) # Add a new prep template @@ -543,30 +567,20 @@ def test_study_prep_get_req(self): pd.DataFrame({'new_col': {'1.SKD6.640190': 1}}), qdb.study.Study(1), '16S') obs = study_prep_get_req(1, 'test@foo.bar') + temp_info['16S'] = [{'id': pt.id, + 'status': 'sandbox', + 'name': 'Prep information %d' % pt.id, + 'creation_timestamp': pt.creation_timestamp, + 'modification_timestamp': + pt.modification_timestamp, + 'total_samples': 1, + 'start_artifact_id': None, + 'start_artifact': None, + 'youngest_artifact': None, + 'ebi_experiment': 0}] exp = {'status': 'success', 'message': '', - 'info': { - '18S': [{'id': 1, - 'status': 'private', - 'name': 'Prep information 1', - 'start_artifact_id': 1, - 'start_artifact': 'FASTQ', - 'youngest_artifact': 'BIOM - BIOM', - 'ebi_experiment': 27}, - {'id': 2, - 'status': 'private', - 'name': 'Prep information 2', - 'start_artifact_id': 7, - 'start_artifact': 'BIOM', - 'youngest_artifact': 'BIOM - BIOM', - 'ebi_experiment': 27}], - '16S': [{'id': pt.id, - 'status': 'sandbox', - 'name': 'Prep information %d' % pt.id, - 'start_artifact_id': None, - 'start_artifact': None, - 'youngest_artifact': None, - 'ebi_experiment': 0}]}} + 'info': temp_info} self.assertEqual(obs, exp) obs = study_prep_get_req(1, 'admin@foo.bar') @@ -574,16 +588,27 @@ def test_study_prep_get_req(self): qdb.artifact.Artifact(1).visibility = 'public' obs = study_prep_get_req(1, 'demo@microbio.me') + temp_info = defaultdict(list) + temp_info['18S'] = [{ + 'id': 1, + 'status': 'public', + 'name': 'Prep information 1', + 'start_artifact_id': 1, + 'start_artifact': 'FASTQ', + 'youngest_artifact': 'BIOM - BIOM', + 'youngest_artifact_name': 'BIOM', + 'youngest_artifact_type': 'BIOM', + 'num_artifact_children': 2, + 'total_samples': 27, + 'ebi_experiment': 27, + 'modification_timestamp': + obs_info[0]['modification_timestamp'], + 'creation_timestamp': + obs_info[0]['creation_timestamp']}] + temp_info['16S'] = [] exp = {'status': 'success', 'message': '', - 'info': { - '18S': [{'id': 1, - 'status': 'public', - 'name': 'Prep information 1', - 'start_artifact_id': 1, - 'start_artifact': 'FASTQ', - 'youngest_artifact': 'BIOM - BIOM', - 'ebi_experiment': 27}]}} + 'info': temp_info} self.assertEqual(obs, exp) # Reset visibility of the artifacts for i in range(4, 0, -1): diff --git a/qiita_pet/templates/study_ajax/data_type_menu.html b/qiita_pet/templates/study_ajax/data_type_menu.html index 706cfb85b..bf42b39c2 100644 --- a/qiita_pet/templates/study_ajax/data_type_menu.html +++ b/qiita_pet/templates/study_ajax/data_type_menu.html @@ -1,5 +1,16 @@ {% from qiita_core.qiita_settings import qiita_config %} + + + + + {% if prep_info %}
({{prep['ebi_experiment']}})
- {% end %}
+ Samples: {{ prep['total_samples'] }}{% if prep['ebi_experiment'] %},
{{prep['ebi_experiment']}} {% end %}
- {{prep['name']}} - ID {{prep['id']}} - {{prep['status']}}
+ {{prep['name']}} - ID: {{prep['id']}} - {{prep['status']}}