@@ -131,15 +131,16 @@ def turnaround(self, max_days=30):
131131 sample_type = details .get ("sample_type" )
132132 if details .get ("type" ) == "Production" and aborted is None :
133133
134- # Projects TaT
135134 try :
136- proj_dates = self .project_dates [[proj_key ]].rows [0 ]. value
135+ proj_dates = self .project_dates [[proj_key ]].rows [0 ][ " value" ]
137136 except :
138- proj_dates = None
137+ proj_dates = {}
138+ seq_date = proj_dates .get ("sequencing_start_date" )
139+ prep_date = proj_dates .get ("library_prep_start" )
140+ prep_finished = proj_dates .get ("qc_library_finished" )
139141
142+ # Projects TaT
140143 try :
141- seq_date = proj_dates .get ("sequencing_start_date" )
142- prep_date = proj_dates .get ("library_prep_start" )
143144 proj_end = datetime .strptime (close_date , "%Y-%m-%d" )
144145 if proj_end > start_date :
145146 if sample_type == "Finished Library" :
@@ -148,11 +149,19 @@ def turnaround(self, max_days=30):
148149 finlib_projs .append (finlib_days )
149150 else :
150151 prep_start = datetime .strptime (prep_date , "%Y-%m-%d" )
151- prepped_days = (proj_end - prep_start ).days
152- prep_projs .append (prepped_days )
152+ proj_days = (proj_end - prep_start ).days
153+ prep_projs .append (proj_days )
153154 except TypeError :
154155 pass
155- except AttributeError :
156+
157+ # Library prep TaT
158+ try :
159+ prep_start = datetime .strptime (prep_date , "%Y-%m-%d" )
160+ prep_end = datetime .strptime (prep_finished , "%Y-%m-%d" )
161+ prep_days = (prep_end - prep_start ).days
162+ if prep_end > start_date and prep_days >= 0 :
163+ libprep_list .append (prep_days )
164+ except TypeError :
156165 pass
157166
158167 # Intial QC TaT
@@ -164,42 +173,7 @@ def turnaround(self, max_days=30):
164173 qc_list .append (qc_days )
165174 except TypeError :
166175 pass
167- except ValueError :
168- pass
169-
170- # Library prep TaT
171- try :
172- samples = self .project_samples [proj_key ].rows [0 ].value
173- except IndexError :
174- continue
175176
176- if samples is None :
177- continue
178-
179- for sample_key , sample in samples .items ():
180- # TODO: Replace with library pooling information when available
181- first_prep_start = sample .get ("first_prep_start_date" )
182- if sample .get ("library_prep" ) is None or first_prep_start is None :
183- continue
184-
185- prep_re = re .compile ('^[A-Z]$' )
186- preps = sorted ([m for m in sample ["library_prep" ].keys () if prep_re .match (m )])
187- for prep in preps :
188- final_prep_ends = []
189- if sample ["library_prep" ][preps [- 1 ]].get ("prep_status" ) == "PASSED" :
190- for val_key , lib_val in sample ["library_prep" ][preps [- 1 ]].get ("library_validation" , {}).items ():
191- final_prep_ends .append (lib_val .get ("finish_date" ))
192- try :
193- valid_preps = [datetime .strptime (i , "%Y-%m-%d" ) for i in final_prep_ends if i is not None ]
194- prep_end = max (valid_preps )
195- prep_start = datetime .strptime (first_prep_start , "%Y-%m-%d" )
196- prep_days = (prep_end - prep_start ).days
197- if prep_end > start_date and prep_days >= 0 :
198- libprep_list .append (prep_days )
199- except TypeError :
200- continue
201- except ValueError :
202- continue
203177 return ({
204178 "library_prep" : self ._get_percentile (libprep_list , 90 ),
205179 "initial_qc" : self ._get_percentile (qc_list , 90 ),
0 commit comments