Skip to content

Commit 26a1a62

Browse files
authored
Adding time estimation for batches
1 parent 5d6fc86 commit 26a1a62

1 file changed

Lines changed: 39 additions & 1 deletion

File tree

Utilities/ProcessMultipleExcelTables_FromAivia.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828
from pathlib import Path
2929
from magicgui import magicgui
3030
import re
31+
from datetime import datetime
3132

3233
# Folder to quickly run the script on all Excel files in it
33-
DEFAULT_FOLDER = '' # r"D:\..."
34+
DEFAULT_FOLDER = ''
3435

3536
# Collect scenario
3637
scenario_descriptions = ['A: Select multiple xlsx tables to create a combined table.\n'
@@ -220,11 +221,19 @@ def run(params):
220221
temp_tab = [] # Used to store tabs from the same well
221222
well_ref = ''
222223

224+
# Evaluate time if number of file is > 10
225+
if len(final_input_list[:]) > 10:
226+
t1 = datetime.now()
227+
223228
# Main LOOP -----------------------------------------------------------------------------------------------
224229
for file_index, input_file in enumerate(final_input_list):
225230
if len(final_input_list) > 1:
226231
indiv_path_list = [input_file] # List of tables is trimmed down to one item to invoke scenario D
227232

233+
# Evaluate time if number of file is > 10
234+
if len(indiv_path_list[:]) > 10:
235+
t1 = datetime.now()
236+
228237
print('Processing: ', input_file)
229238

230239
# Reading first file to collect info
@@ -322,6 +331,10 @@ def run(params):
322331
else:
323332
print('WARNING: {} table was excluded because table tabs are different from first table'.format(f))
324333

334+
# Evaluate time for the processing of one table
335+
if len(indiv_path_list[:]) > 10 and f_index == 0:
336+
show_estimated_time(t1, len(indiv_path_list[:]))
337+
325338
# Push the latest stacked column in the final table (in case of multiwell)
326339
for t in tab_names:
327340
if process_wells:
@@ -350,6 +363,10 @@ def run(params):
350363
# Merging to previous grouped data
351364
df_grouped[t] = pd.concat([df_grouped[t], df_raw[t]], axis=0)
352365

366+
# Evaluate time for the processing of one table
367+
if len(indiv_path_list[:]) > 10 and f == indiv_path_list[1]:
368+
show_estimated_time(t1, len(indiv_path_list[1:]))
369+
353370
# --- COMBINE TABS into one if no timepoints in data (scenario A-D...) ------------------------------
354371
if not contains_tps and (do_combine_meas_tabs or do_multiple_files_as_cols):
355372
# Init
@@ -577,6 +594,10 @@ def run(params):
577594

578595
# --- / FINAL SUMMARY ----------------------------------------------------------------------------------------
579596

597+
# Evaluate time for one table if a list of table is processed individually
598+
if len(final_input_list[:]) > 10 and file_index == 0:
599+
show_estimated_time(t1, len(final_input_list[:]))
600+
580601
# Main LOOP -----------------------------------------------------------------------------------------------
581602

582603
final_mess = '{} table(s) got saved here:\n{}'.format(len(final_input_list), output_folder)
@@ -737,6 +758,21 @@ def is_multiwell(folder_name):
737758
return ans
738759

739760

761+
def show_estimated_time(t1, nb_of_tables):
762+
t2 = datetime.now()
763+
duration = round((t2 - t1).total_seconds())
764+
mess = 'Estimated time for one table: {} seconds.\n\nEstimated time for {} tables: {} minutes.\n\n' \
765+
'Extra time is expected for the processing of the data.' \
766+
''.format(duration, nb_of_tables, round(duration * nb_of_tables / 60))
767+
768+
with concurrent.futures.ThreadPoolExecutor() as executor:
769+
future = executor.submit(Mbox, 'Estimated reading time', mess, 1)
770+
ans = future.result()
771+
772+
if ans == 2:
773+
sys.exit('Process terminated by user')
774+
775+
740776
def Mbox(title, text, style):
741777
return ctypes.windll.user32.MessageBoxW(0, text, title, style)
742778

@@ -761,3 +797,5 @@ def Mbox(title, text, style):
761797
# - Adding a magicGui for the selection of the scenario
762798
# v1.50: - Adding scenario F
763799
# - Renaming main summary as 'Analysis_Summary'
800+
# v1.51: - Providing estimation on how long it takes to read one table if more than 10 tables are selected
801+
# TODO: progress bar with file in Recipes folder: '_progress_bar_file 1_from 10_'

0 commit comments

Comments
 (0)