Skip to content

Commit 179b582

Browse files
committed
more changes for suggestions
1 parent ccd7d4a commit 179b582

File tree

3 files changed

+38
-34
lines changed

3 files changed

+38
-34
lines changed

qiita_pet/handlers/study_handlers/listing_handlers.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ def _build_single_study_info(study, info, study_proc, proc_samples):
5252
The study to build information for
5353
info : dict
5454
Information from Study.get_info
55+
study_proc : dict of lists
56+
Dictionary keyed on study_id that lists all processed data associated
57+
with that study.
58+
proc_samples : dict of lists
59+
Dictionary keyed on proc_data_id that lists all samples associated with
60+
that processed data.
5561
5662
Returns
5763
-------
@@ -76,20 +82,18 @@ def _build_single_study_info(study, info, study_proc, proc_samples):
7682
del info["principal_investigator_id"]
7783
del info["email"]
7884
# Build the proc data info list for the child row in datatable
79-
info["proc_data_info"] = _build_single_proc_data_info(
80-
study, study_proc, proc_samples)
85+
info["proc_data_info"] = [
86+
_build_single_proc_data_info(pd_id, proc_samples[pd_id])
87+
for pd_id in study_proc[study.id]]
8188
return info
8289

8390

84-
def _build_single_proc_data_info(study, study_proc, proc_samples):
91+
def _build_single_proc_data_info(proc_data_id, samples):
8592
"""Build the proc data info list for the child row in datatable
8693
87-
8894
Parameters
8995
----------
90-
study : Study object
91-
The study to build information for
92-
study_proc : dict of lists
96+
proc_data_id : int
9397
The processed data attached to he study, in the form
9498
{study_id: [proc_data_id, proc_data_id, ...], ...}
9599
proc_samples : dict of lists
@@ -98,24 +102,20 @@ def _build_single_proc_data_info(study, study_proc, proc_samples):
98102
99103
Returns
100104
-------
101-
dict of dicts
102-
The information for the processed data, in the form
103-
{proc_data_id: {info: value, ...}, ...}
105+
dict
106+
The information for the processed data, in the form {info: value, ...}
104107
"""
105-
proc_data_info = []
106-
for pid in study_proc[study.id]:
107-
proc_data = ProcessedData(pid)
108-
proc_info = proc_data.processing_info
109-
proc_info['pid'] = pid
110-
proc_info['data_type'] = proc_data.data_type()
111-
proc_info['samples'] = sorted(proc_samples[pid])
112-
proc_info['processed_date'] = str(proc_info['processed_date'])
113-
proc_data_info.append(proc_info)
114-
return proc_data_info
108+
proc_data = ProcessedData(proc_data_id)
109+
proc_info = proc_data.processing_info
110+
proc_info['pid'] = proc_data_id
111+
proc_info['data_type'] = proc_data.data_type()
112+
proc_info['samples'] = sorted(samples)
113+
proc_info['processed_date'] = str(proc_info['processed_date'])
114+
return proc_info
115115

116116

117117
def _build_study_info(user, study_proc=None, proc_samples=None):
118-
"""builds list of dicts for studies table, with all html formatted
118+
"""Builds list of dicts for studies table, with all HTML formatted
119119
120120
Parameters
121121
----------
@@ -171,11 +171,11 @@ def _build_study_info(user, study_proc=None, proc_samples=None):
171171
study = Study(info['study_id'])
172172
# Build the processed data info for the study if none passed
173173
if build_samples:
174-
proc_data = study.processed_data()
175-
proc_samples = {}
176-
study_proc = {study.id: proc_data}
177-
for pid in proc_data:
178-
proc_samples[pid] = ProcessedData(pid).samples
174+
proc_data = study.processed_data()
175+
proc_samples = {}
176+
study_proc = {study.id: proc_data}
177+
for pid in proc_data:
178+
proc_samples[pid] = ProcessedData(pid).samples
179179

180180
study_info = _build_single_study_info(study, info, study_proc,
181181
proc_samples)

qiita_pet/templates/list_studies.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
});
8282
// Add event listener for opening and closing details
8383
$('#studies-table tbody').on('click', 'td.details-control', function () {
84-
var table = $('#studies-table').DataTable();
84+
var table = $('#studies-table').DataTable();
8585
var tr = $(this).closest('tr');
8686
var row = table.row( tr );
8787

qiita_pet/test/test_study_handlers.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from json import loads
33

44
from qiita_pet.test.tornado_test_base import TestHandlerBase
5+
from qiita_core.exceptions import IncompetentQiitaDeveloperError
56
from qiita_db.study import StudyPerson, Study
67
from qiita_db.util import get_count, check_count
78
from qiita_db.user import User
@@ -14,7 +15,7 @@ class TestHelpers(TestHandlerBase):
1415
database = True
1516

1617
def setUp(self):
17-
self.proc_data_exp = [{
18+
self.proc_data_exp = {
1819
'pid': 1,
1920
'processed_date': '2012-10-01 09:30:27',
2021
'data_type': '18S',
@@ -36,7 +37,7 @@ def setUp(self):
3637
'1.SKM1.640183', '1.SKM2.640199', '1.SKM3.640197',
3738
'1.SKM4.640180', '1.SKM5.640177', '1.SKM6.640187',
3839
'1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192']
39-
}]
40+
}
4041
self.single_exp = {
4142
'study_id': 1,
4243
'status': 'private',
@@ -64,7 +65,7 @@ def setUp(self):
6465
'//www.ncbi.nlm.nih.gov/pubmed/7891011">7891011</a>',
6566
'pi': '<a target="_blank" href="mailto:PI_dude@foo.bar">'
6667
'PIDude</a>',
67-
'proc_data_info': self.proc_data_exp
68+
'proc_data_info': [self.proc_data_exp]
6869
}
6970
self.exp = [self.single_exp]
7071
super(TestHelpers, self).setUp()
@@ -76,7 +77,7 @@ def test_get_shared_links_for_study(self):
7677

7778
def test_build_single_study_info(self):
7879
study_proc = {1: [1]}
79-
proc_samples = {1: self.proc_data_exp[0]['samples']}
80+
proc_samples = {1: self.proc_data_exp['samples']}
8081
study_info = {
8182
'study_id': 1,
8283
'email': 'test@foo.bar',
@@ -104,15 +105,18 @@ def test_build_single_study_info(self):
104105
self.assertEqual(obs, self.single_exp)
105106

106107
def test_build_single_proc_data_info(self):
107-
study_proc = {1: [1]}
108-
proc_samples = {1: self.proc_data_exp[0]['samples']}
109-
obs = _build_single_proc_data_info(Study(1), study_proc, proc_samples)
108+
obs = _build_single_proc_data_info(1, self.proc_data_exp['samples'])
110109
self.assertEqual(obs, self.proc_data_exp)
111110

112111
def test_build_study_info(self):
113112
obs = _build_study_info(User('test@foo.bar'))
114113
self.assertEqual(obs, self.exp)
115114

115+
with self.assertRaises(IncompetentQiitaDeveloperError):
116+
obs = _build_study_info(User('test@foo.bar'), study_proc={})
117+
with self.assertRaises(IncompetentQiitaDeveloperError):
118+
obs = _build_study_info(User('test@foo.bar'), proc_samples={})
119+
116120
def test_build_study_info_new_study(self):
117121
info = {
118122
'timeseries_type_id': 1,

0 commit comments

Comments
 (0)