-
Notifications
You must be signed in to change notification settings - Fork 0
/
Experiment.py
1683 lines (1501 loc) · 91.5 KB
/
Experiment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import csv
import itertools
import os
import random
import tkinter as tk
from tkinter import messagebox, ttk
import threading
import cv2
import pandas as pd
import numpy as np
import databases_utils as db
import ExperimentRecorder as erc
import ExperimentPreProcessor as epp
import ExperimentReplayer as erp
import ExperimentAnalyser as ea
from config import SESSION_OPTIONS, MODES
def get_row_and_column_index_from_index(index, nb_items_total):
# get the number of rows and columns, knowing that the number of columns and rows should be as close as possible
nb_rows = int(np.sqrt(nb_items_total))
if nb_rows == 0:
nb_rows = 1
nb_columns = int(np.ceil(nb_items_total / nb_rows))
if nb_columns == 0:
nb_columns = 1
row_index = index // nb_columns
column_index = index % nb_columns
return row_index, column_index
class Experiment:
#TODO : move option verbose in session class
def __init__(self, name = None, win = None, mode=None) -> None:
if mode not in MODES:
raise ValueError(f"Mode {mode} not supported. Supported modes are {MODES}")
else:
self.mode = mode
self.name = name
self.running = False
self.path = None
self.selected_session = None
self.win = win
def set_path(self, path):
path_exists = os.path.exists(path)
if not path_exists:
messagebox.showinfo("Experiment folder not found", f"Experiment folder not found in {path}, please check the path you wrote.")
else:
self.path = path
return path_exists
def fetch_sessions(self):
if self.mode == 'Recording':
self.sessions_indexes = range(1, len(SESSION_OPTIONS)+1)
return SESSION_OPTIONS
else:
# list all folders from the experiment folder, directories only, begining with "Session_"
self.session_folders = [f for f in os.listdir(self.path) if os.path.isdir(os.path.join(self.path, f)) and f.startswith("Session_")]
self.session_folders.sort()
# get the list of session indexes, e.g. [1, 2, 3]
self.sessions_indexes = []
self.sessions_options = []
for session_folder in self.session_folders:
try:
session_index = int(session_folder.split("_")[1])
self.sessions_indexes.append(session_index)
self.sessions_options.append(SESSION_OPTIONS[session_index - 1])
except:
print(f"Session folder {session_folder} does not follow the naming convention 'Session_X', with X an integer")
#TODO : return only sessions with participants
# self.sessions = [Session(self.path, index, mode = self.mode) for index in self.sessions_indexes]
return self.sessions_options
def set_session(self, selected_session):
#find the index of the selected session in SESSION_OPTIONS
index = SESSION_OPTIONS.index(selected_session)
# self.selected_session = self.sessions[index]
self.selected_session = Session(self.path, self.sessions_indexes[index], mode = self.mode)
return self.selected_session
def select_participant(self, pseudo):
return self.selected_session.select_participant(pseudo)
def process_selected_participants(self, process_labels):
if process_labels['Name'] == 'Replay':
self.selected_session.replay_selected_participants()
elif process_labels['Name'] == 'Pre-processing':
self.selected_session.pre_process_selected_participants()
elif process_labels['Name'] == 'Analysis':
self.selected_session.analyse_selected_participants()
else:
print(f"Process {process_labels['Name']} not supported")
# def get_participants(self):
# return self.selected_session.get_participants()
def get_session_label(self):
return self.selected_session.label
def get_session_path(self):
return self.selected_session.path
def get_session_experimental_parameters(self):
return self.selected_session.get_experimental_parameters()
def set_session_experimental_parameters(self, parameters):
self.selected_session.set_experimental_parameters(parameters)
def get_session_recording_parameters(self):
return self.selected_session.get_recording_parameters()
def set_session_recording_parameters(self, parameters):
self.selected_session.set_recording_parameters(parameters)
self.selected_session.save_recording_parameters()
def save_session_experimental_parameters(self):
self.selected_session.save_experimental_parameters()
def get_session_participants(self):
return self.selected_session.get_participants()
def get_session_processing_monitoring(self):
return self.selected_session.get_processing_monitoring()
def get_pseudo(self, participant_firstname, participant_surname, location):
return self.selected_session.get_pseudo(participant_firstname, participant_surname, location)
def refresh_session(self):
self.selected_session.import_participants_database()
self.selected_session.import_pseudos_participants_database()
def close(self):
if self.selected_session is not None:
self.selected_session.close()
class Session:
_PARTICIPANTS_DATABASE_FILE_SUFFIX = "_participants_database.csv"
_PARTICIPANTS_PSEUDOS_DATABASE_FILE_SUFFIX = "_participants_pseudos_database.csv"
_EXPERIMENTAL_PARAMETERS_SUFFIX = "_experimental_parameters.csv"
_RECORDING_PARAMETERS_SUFFIX = "_recording_parameters.csv"
_INSTRUCTIONS_LANGUAGES_SUFFIX = "_instructions_languages.csv"
_PROCESSING_MONITORING_SUFFIX = "_processing_monitoring.csv"
_PARTICIPANTS_DATABASE_HEADER = ["Pseudo", "Date", "Handedness", "Location", "Number of trials"]
_PROCESSING_MONITORING_HEADER = ["Pseudo", "Recording date", "Pre-processing date", "Replay date", "Analysis date", "Status", "Number of trials", "Number of trials pre-processed", "Number of trials replayed", "Number of trials analysed"]
_PARTICIPANTS_PSEUDOS_DATABASE_HEADER = ["FirstName", "Surname", "Pseudo"]
_SUPPORTED_LANGUAGES = ["French", "English"]
_INSTRUCTIONS_LANGUAGES_HEADER = ["Label"] + _SUPPORTED_LANGUAGES
def __init__(self, experiment_path, index, mode = 'Recording') -> None:
self.index = index
self.label = f"Session {self.index}"
self.folder = f"Session_{self.index}"
self.path = os.path.join(experiment_path, self.folder)
self.processing_path = os.path.join(experiment_path, f"{self.folder}_processing")
self.pre_processing_path = os.path.join(self.processing_path, "Pre_processing")
self.replay_path = os.path.join(self.processing_path, "Replay")
self.analysis_path = os.path.join(self.processing_path, "Analysis")
self.mode = mode
if mode in ['Pre-processing', 'Replay', 'Analysis']:
if not os.path.exists(self.processing_path):
answer = messagebox.askyesno(f"Processing folder not found", f"Processing folder not found at {self.processing_path}, please check the session folder. Do you want to create a new one?")
if answer :
os.makedirs(self.processing_path)
print(f"New processing folder created")
if self.mode == 'Pre-processing':
if not os.path.exists(self.processing_path):
answer = messagebox.askyesno(f"Processing folder not found", f"Processing folder not found at {self.processing_path}, please check the session folder. Do you want to create a new one?")
if answer :
os.makedirs(self.processing_path)
print(f"New pre-processing folder created")
if self.mode == 'Replay':
if not os.path.exists(self.replay_path):
answer = messagebox.askyesno(f"Replay folder not found", f"Replay folder not found at {self.replay_path}, please check the session folder. Do you want to create a new one?")
if answer :
os.makedirs(self.replay_path)
print(f"New replay folder created")
if self.mode == 'Analysis':
if not os.path.exists(self.analysis_path):
answer = messagebox.askyesno(f"Analysis folder not found", f"Analysis folder not found at {self.analysis_path}, please check the session folder. Do you want to create a new one?")
if answer :
os.makedirs(self.analysis_path)
print(f"New analysis folder created")
self.all_participants = []
self.current_participant = None
self.participants_to_process = []
self.continue_processing = True
self.all_data_available = True
self.missing_data = []
self.preselect_all_participants = False
self.is_new = not os.path.exists(self.path)
self.experimental_parameters = None
self.params_separator = ';' #separator used in the experiment parameters csv file
self.parameters_list = ["Objects", "Hands", "Grips", "Movement Types", "Number of repetitions"]
if self.is_new :
if self.mode != 'Recording':
messagebox.showinfo("Session folder not found", f"Session {self.label} folder not found in {experiment_path}, please check the main folder.")
return False
os.makedirs(self.path)
self.participants_database = pd.DataFrame(columns=self._PARTICIPANTS_DATABASE_HEADER)
self.participants_pseudos_database = pd.DataFrame(columns=self._PARTICIPANTS_PSEUDOS_DATABASE_HEADER)
self.processing_monitoring_database = pd.DataFrame(columns=self._PROCESSING_MONITORING_HEADER)
else:
print(f"Reading session {self.label} folder at {self.path}")
self.import_participants_database()
if self.participants_database is not None and self.mode != 'Recording':
self.import_processing_monitoring()
self.scan_participants_basic_data()
self.import_pseudos_participants_database()
self.import_instructions_languages()
self.read_experimental_parameters()
print(f"Selected session: {self.label}")
if self.mode != 'Recording':
self.extract_devices_data()
if not self.all_data_available:
print(f"Session {self.label} incomplete. Missing data: {self.missing_data}")
self.experiment_pre_processor = None
self.experiment_replayer = None
self.experiment_analyser = None
def build_progress_display(self):
name = "Processing..."
self.progress_window = tk.Toplevel()
self.progress_window.geometry("750x450")
self.progress_window.title(name)
label = ttk.Label(self.progress_window, text=name)
label.pack()
label = ttk.Label(self.progress_window, text="Please wait until the end of the process.")
label.pack()
messagebox.showinfo("Processing", "Processing started, please wait until the end of the process.")
self.devices_progress_display = ProgressDisplay(len(self.devices_data), "devices", parent=self.progress_window, title="Devices")
self.devices_progress_display.pack(padx=10, pady=10)
self.participants_progress_display= ProgressDisplay(len(self.participants_to_process), "participants pre-processed", parent=self.devices_progress_display, title = "Participants")
self.participants_progress_display.pack(padx=10, pady=10)
self.trials_progress_display= ProgressDisplay(self.participants_to_process[0].get_number_of_trials(), "trials pre-processed", parent=self.participants_progress_display, title = "Trials")
self.trials_progress_display.pack(padx=10, pady=10)
self.current_trial_progress_display= ProgressDisplay(self.participants_to_process[0].get_number_of_trials(), "trials pre-processed", parent=self.trials_progress_display, title = "Current Trial")
self.current_trial_progress_display.pack(padx=10, pady=10)
interrupt_button = ttk.Button(self.progress_window, text="Interrupt", command=self.interrupt_processing)
interrupt_button.pack(padx=10, pady=10)
self.progress_window.update()
def read_experimental_parameters_new(self):
#read the experiment parameters from the csv file
parameters_path = os.path.join(self.path, f'{self.folder}{self._EXPERIMENTAL_PARAMETERS_SUFFIX}')
if not os.path.exists(parameters_path):
self.experimental_parameters = None
print(f"Parameters file not found in {parameters_path}, please check the session folder.")
messagebox.showinfo("Parameters file not found", f"{self.label} parameters file not found in {self.path}, please check the session folder.")
self.all_data_available = False
self.missing_data.append('experimental parameters')
else:
self.experimental_parameters = pd.read_csv(parameters_path)
print(f"Experiment parameters read from '{parameters_path}'")
def read_experimental_parameters(self):
csv_path = os.path.join(self.path, f'{self.folder}{self._EXPERIMENTAL_PARAMETERS_SUFFIX}')
if not os.path.exists(csv_path):
self.experimental_parameters = None
print(f"Experimental parameters file not found in {csv_path}, please check the session folder.")
messagebox.showinfo("Experimental parameters file not found", f"{self.label} experimental parameters file not found in {self.path}, please check the session folder.")
self.all_data_available = False
self.missing_data.append('experimental parameters')
else:
self.experimental_parameters = {}
with open(csv_path, "r") as csvfile:
reader = csv.reader(csvfile)
self.parameters_list = []
for row in reader:
param_type = row[0]
param_list = row[1:]
self.experimental_parameters[param_type] = param_list
self.parameters_list.append(param_type)
print(f"Experimental parameters read from '{csv_path}'")
print(f"Experimental parameters: \n{self.experimental_parameters}")
def set_experimental_parameters(self, parameters):
self.experimental_parameters = parameters
save_instructions = False
for param_list in self.experimental_parameters.values():
for param in param_list:
#check if param is a blank string
if param == '':
continue
if param not in self.instructions_languages['Label'].values:
print(self.instructions_languages)
self.instructions_languages.loc[len(self.instructions_languages)] = [param]+[None for l in self._SUPPORTED_LANGUAGES]
for language in self._SUPPORTED_LANGUAGES:
self.ask_param_instructions(param, language)
save_instructions = True
if save_instructions:
self.save_instructions_languages()
def ask_param_instructions(self, param, language):
self.instructions_window = tk.Toplevel()
size = "700x200"
self.instructions_window.geometry(size)
requirements_label = ttk.Label(self.instructions_window, text=f"Parameter '{param}' was not found in our database {self.instructions_languages_csv_path}. \n Please enter the corresponding instructions for the language {language}")
requirements_label.pack()
instructions_entry = ttk.Entry(self.instructions_window)
instructions_entry.pack()
validate_button = ttk.Button(self.instructions_window, text="Validate", command=lambda: self.add_instructions(param, language, instructions_entry.get()))
validate_button.pack()
self.instructions_window.wait_window()
def add_instructions(self, param, language, instructions):
self.instructions_languages.loc[len(self.instructions_languages)] = [param, language, instructions]
self.instructions_window.destroy()
def read_recording_parameters(self):
csv_path = os.path.join(self.path, f'{self.folder}{self._RECORDING_PARAMETERS_SUFFIX}')
if not os.path.exists(csv_path):
self.recording_parameters = None
print(f"Recording parameters file not found in {csv_path}, please check the session folder.")
messagebox.showinfo("Recording parameters file not found", f"{self.folder} recording parameters file not found in {self.path}, please check the session folder.")
self.all_data_available = False
self.missing_data.append('recording parameters')
else:
self.recording_parameters = {}
with open(csv_path, "r") as csvfile:
reader = csv.reader(csvfile)
for row in reader:
param_type = row[0]
param_list = row[1:]
self.recording_parameters[param_type] = param_list
print(f"Recording parameters read from '{csv_path}'")
def set_recording_parameters(self, recording_parameters):
self.recording_parameters = recording_parameters
def import_pseudos_participants_database(self):
pseudos_csv_path = os.path.join(self.path, f"{self.folder}{self._PARTICIPANTS_PSEUDOS_DATABASE_FILE_SUFFIX}")
if not os.path.exists(pseudos_csv_path):
self.participants_pseudos_database = None
print(f"No Pseudos-participant database found in {self.path}")
answer = messagebox.askyesno(f"Pseudos-participants database not found", "Pseudos-participants not found, please check the session folder. Do you want to create a new one?")
if answer :
self.participants_pseudos_database = pd.DataFrame(columns=self._PARTICIPANTS_PSEUDOS_DATABASE_HEADER)
self.participants_pseudos_database.to_csv(os.path.join(self.path, f"{self.folder}{self._PARTICIPANTS_PSEUDOS_DATABASE_FILE_SUFFIX}"), index=False)
print(f"New Pseudos-participants database created")
else:
self.missing_data.append('pseudo-participant database')
self.all_data_available = False
else:
self.participants_pseudos_database = pd.read_csv(pseudos_csv_path)
print(f"Pseudos-participants database imported from '{pseudos_csv_path}'")
print(f"Pseudos-participants database: \n{self.participants_pseudos_database}")
def import_participants_database(self):
participants_csv_path = os.path.join(self.path, f"{self.folder}{self._PARTICIPANTS_DATABASE_FILE_SUFFIX}")
if not os.path.exists(participants_csv_path):
self.participants_database = None
print(f"No participant database found in {self.path}")
answer = messagebox.askyesno(f"Participants database not found", "Participants database not found, please check the session folder. Do you want to create a new one?")
if answer :
self.participants_database = pd.DataFrame(columns=self._PARTICIPANTS_DATABASE_HEADER)
self.participants_database.to_csv(os.path.join(self.path, f"{self.folder}{self._PARTICIPANTS_DATABASE_FILE_SUFFIX}"), index=False)
print(f"New participant database created")
else:
self.missing_data.append('participant database')
self.all_data_available = False
else:
self.participants_database = pd.read_csv(participants_csv_path)
print(f"Pseudos database imported from '{participants_csv_path}'")
#add a column "To Process" to the database, with each row filled with True
self.participants_database["To Process"] = self.preselect_all_participants
def import_instructions_languages(self):
self.instructions_languages_csv_path = os.path.join(self.path, f"{self.folder}{self._INSTRUCTIONS_LANGUAGES_SUFFIX}")
if not os.path.exists(self.instructions_languages_csv_path):
self.instructions_languages = None
print(f"No instructions languages database found in {self.path}")
answer = messagebox.askyesno(f"Instructions languages database not found", "Instructions languages database not found, please check the session folder. Do you want to create a new one?")
if answer :
self.instructions_languages = pd.DataFrame(columns=self._INSTRUCTIONS_LANGUAGES_HEADER)
self.instructions_languages.loc[len(self.instructions_languages)] = ['Welcome', "BIENVENUE DANS L'EXPERIENCE I-GRIP", "WELCOME TO THE I-GRIP EXPERIMENT"]
self.save_instructions_languages()
print(f"New instructions languages database created")
else:
self.missing_data.append('instructions languages database')
self.all_data_available = False
else:
self.instructions_languages = pd.read_csv(self.instructions_languages_csv_path)
print(f"Instructions languages database imported from '{self.instructions_languages_csv_path}'")
def scan_participants_basic_data(self):
for index, row in self.participants_database.iterrows():
participant = Participant(row['Pseudo'], self.path, self.experimental_parameters, mode=self.mode)
self.all_participants.append(participant)
# check if the participant is pre-processed
# self.participants_database.loc[index, 'Processed'] = participant.is_processed()
self.participants_database.loc[index, 'All data available'] = participant.is_all_data_available()
# self.participants_database.loc[index, 'Folder available'] = participant.is_folder_available()
# self.participants_database.loc[index, 'Combinations available'] = participant.is_combinations_available()
# self.participants_database.loc[index, 'All trial folders available'] = participant.is_all_trial_folders_available()
self.processing_monitoring_database.loc[index, 'Pseudo'] = row['Pseudo']
self.processing_monitoring_database.loc[index, 'Recording date'] = row['Date']
self.processing_monitoring_database.loc[index, 'Status'] = participant.get_status()
self.processing_monitoring_database.loc[index, 'Number of trials'] = participant.get_number_of_trials()
self.processing_monitoring_database.loc[index, 'Number of trials pre-processed'] = participant.get_number_of_pre_processed_trials()
self.processing_monitoring_database.loc[index, 'Number of trials replayed'] = participant.get_number_of_replayed_trials()
self.processing_monitoring_database.loc[index, 'Number of trials analysed'] = participant.get_number_of_analysed_trials()
self.processing_monitoring_database.loc[index, 'Processable'] = participant.is_folder_available() and participant.is_combinations_available() and participant.get_number_of_trials() > 0
self.processing_monitoring_database.loc[index, 'To Process'] = False
self.save_processing_monitoring()
def import_processing_monitoring(self):
monitoring_csv_path = os.path.join(self.processing_path, f"{self.folder}{self._PROCESSING_MONITORING_SUFFIX}")
if not os.path.exists(monitoring_csv_path):
print(f"No processing monitoring database found in {self.path}")
answer = messagebox.askyesno(f"Processing monitoring database not found", "Processing monitoring database not found, please check the session folder. Do you want to create a new one?")
if answer :
self.processing_monitoring_database = pd.DataFrame(columns=self._PROCESSING_MONITORING_HEADER)
self.processing_monitoring_database.to_csv(monitoring_csv_path, index=False)
print(f"New processing monitoring database created")
else:
self.processing_monitoring_database = pd.read_csv(monitoring_csv_path)
print(f"Processing monitoring database imported from '{monitoring_csv_path}'")
self.processing_monitoring_database[ 'Processable'] = False
self.processing_monitoring_database[ 'To Process'] = False
print('Processing monitoring database: \n', self.processing_monitoring_database)
def extract_devices_data(self):
print("Extracting devices data...")
#TODO : make sure that the devices data are available for all participants
#list files with .npz extension in main path
npz_files = [f for f in os.listdir(self.path) if f.endswith(".npz")]
if len(npz_files) == 0:
self.devices_data = None
print(f"No device data found in {self.path}")
self.missing_data.append("devices data")
else:
self.devices_data = {}
#loop over all files
for npz_file in npz_files:
#get the device id from the file name
device_id = npz_file.split("_")[1].split(".")[0]
# extract the data from the file
data = np.load(os.path.join(self.path, npz_file))
self.devices_data[device_id] = data
print(f"Devices data: {self.devices_data}")
def get_experimental_parameters(self):
return self.experimental_parameters
def get_participants(self):
return self.participants_database
def get_processing_monitoring(self):
return self.processing_monitoring_database
def select_participant(self, pseudo):
# change the value at the line of pseudo and the column "To Process" to true
bool = self.processing_monitoring_database.loc[self.processing_monitoring_database['Pseudo'] == pseudo, 'To Process'].values[0]
self.processing_monitoring_database.loc[self.processing_monitoring_database['Pseudo'] == pseudo, 'To Process'] = not bool
if not bool:
print(f"Pseudo '{pseudo}' selected for pre-processing")
else:
print(f"Pseudo '{pseudo}' deselected for pre-processing")
print(f"Processing database: \n{self.processing_monitoring_database}")
nb_selected_participants = len(self.processing_monitoring_database.loc[self.processing_monitoring_database['To Process']==True])
return nb_selected_participants
def start(self):
self.save_databases()
self.current_participant.initiate_experiment()
def fetch_participants_to_process(self):
self.continue_processing = True
for index, row in self.processing_monitoring_database.iterrows():
if row['To Process']:
self.participants_to_process.append(self.all_participants[index])
def pre_process_selected_participants(self):
self.fetch_participants_to_process()
self.save_processing_monitoring()
self.continue_processing = True
print('Building experiment pre-processor...')
self.experiment_pre_processor = epp.ExperimentPreProcessor()
print('Experiment pre-processor built')
print('Pre-processing selected participants...')
for participant in self.participants_to_process:
self.processing_monitoring_database.loc[self.processing_monitoring_database['Pseudo'] == participant.pseudo, 'Pre-processing date'] = pd.Timestamp.now()
self.save_processing_monitoring()
participant.pre_process(self.experiment_pre_processor)
if self.continue_processing == False:
break
self.save_processing_monitoring()
self.experiment_pre_processor.stop()
def replay_selected_participants(self):
self.fetch_participants_to_process()
self.build_progress_display()
for device_id, device_data in self.devices_data.items():
print(f"Building experiment replayer for device {device_id} with device_data: resolution {device_data['resolution']}, matrix {device_data['matrix']}")
self.current_device_id = device_id
self.experiment_replayer = erp.ExperimentReplayer(device_id, device_data)
self.devices_progress_display.set_current(f"Processing device {device_id}")
self.progress_window.update_idletasks()
print("updating progress window")
self.progress_window.update()
print(f"Experiment replayer for device {device_id} built")
# Loop over selected participants
for participant in self.participants_to_process:
self.processing_monitoring_database.loc[self.processing_monitoring_database['Pseudo'] == participant.pseudo, 'Replay date'] = pd.Timestamp.now()
self.save_processing_monitoring()
self.participants_progress_display.set_current(f"Processing participant {participant.pseudo}")
self.progress_window.update()
participant.set_progress_display( self.progress_window, self.trials_progress_display)
participant.replay(self.experiment_replayer)
self.participants_progress_display.increment()
self.progress_window.update()
if self.continue_processing == False:
break
self.save_processing_monitoring()
self.participants_progress_display.reset()
self.devices_progress_display.increment()
self.progress_window.update()
self.experiment_replayer.stop()
if self.continue_processing == False:
break
print(f"Experiment replayer for device {device_id} stopped")
print("All selected participants replayed")
# self.progress_window.destroy()
def analyse_selected_participants(self):
self.fetch_participants_to_process()
self.build_progress_display()
self.continue_processing = True
for device_id, device_data in self.devices_data.items():
print(f"Building experiment analyser for device {device_id} with device_data: resolution {device_data['resolution']}, matrix {device_data['matrix']}")
self.current_device_id = device_id
self.experiment_analyser = ea.ExperimentAnalyser(device_id, device_data)
self.devices_progress_display.set_current(f"Processing device {device_id}")
self.progress_window.update_idletasks()
print("updating progress window")
self.progress_window.update()
print(f"Experiment analyser for device {device_id} built")
# Loop over selected participants
for participant in self.participants_to_process:
self.processing_monitoring_database.loc[self.processing_monitoring_database['Pseudo'] == participant.pseudo, 'Analysis date'] = pd.Timestamp.now()
self.save_processing_monitoring()
self.participants_progress_display.set_current(f"Analysing participant {participant.pseudo}")
self.progress_window.update()
participant.set_progress_display( self.progress_window, self.trials_progress_display)
participant.analyse(self.experiment_analyser)
self.participants_progress_display.increment()
self.progress_window.update()
if self.continue_processing == False:
break
self.save_processing_monitoring()
self.participants_progress_display.reset()
self.devices_progress_display.increment()
self.progress_window.update()
self.experiment_analyser.stop()
if self.continue_processing == False:
break
print(f"Experiment analyser for device {device_id} stopped")
print("All selected participants analysed")
def interrupt_processing(self):
print("Interrupting pre-processing...")
self.continue_processing = False
def is_data_available(self):
return self.all_data_available
def choose_existing_participant(self, participant_firstname, participant_surname):
#TODO
pass
def get_participant(self, participant_firstname, participant_surname, handedness, location, language = 'English'):
#check if the pseudo already exists
pseudo_in_db = db.check_participant_in_database(participant_firstname, participant_surname, self.participants_pseudos_database)
if not pseudo_in_db:
pseudo = db.generate_new_random_pseudo(self.participants_pseudos_database)
validate_pseudo = messagebox.askquestion("New Participant", f"New participant {participant_firstname} {participant_surname} created with pseudo {pseudo}. Do you want to validate this pseudo?")
if validate_pseudo != 'yes':
return self.get_participant(participant_firstname, participant_surname, handedness, location)
#update the databases
date = pd.Timestamp.now()
print(f'database: {self.participants_database}')
new_data = [pseudo, date, handedness, location, 0, False]
print(f"new_data: {new_data}")
self.participants_database.loc[len(self.participants_database)] = new_data
print(f"self.participants_pseudos_database ici: {self.participants_pseudos_database}")
self.participants_pseudos_database.loc[len(self.participants_pseudos_database)] = [participant_firstname, participant_surname, pseudo]
print(f"self.participants_pseudos_database là: {self.participants_pseudos_database}")
print(f"New participant '{pseudo}' created")
#TODO
else:
print(f"Participant {participant_firstname} {participant_surname} already exists")
load_existing_participant = messagebox.askquestion("Existing Participant", f"Participant {participant_firstname} {participant_surname} already registered in the database, with pseudo {pseudo_in_db}. Do you want to load its data to complete it if needed?")
if load_existing_participant != 'yes':
return None
else:
pseudo = pseudo_in_db
print(f"Participant {participant_firstname} {participant_surname} selected to complete its trials")
print(f'Session database counts now {len(self.participants_database)} participants')
self.current_participant = Participant(pseudo, self.path, self.experimental_parameters, self.recording_parameters, mode=self.mode, language=language)
self.current_participant.set_instructions(self.instructions_languages)
return pseudo
def save_databases(self):
#remove the column "To Process" from the database
to_save = self.participants_database.drop(columns=['To Process'])
to_save.to_csv(os.path.join(self.path, f"{self.folder}{self._PARTICIPANTS_DATABASE_FILE_SUFFIX}"), index=False)
print(f'Participants database saved to {os.path.join(self.path, f"{self.folder}{self._PARTICIPANTS_DATABASE_FILE_SUFFIX}")}')
print(f'Participants database: \n{self.participants_database}')
self.participants_pseudos_database.to_csv(os.path.join(self.path, f"{self.folder}{self._PARTICIPANTS_PSEUDOS_DATABASE_FILE_SUFFIX}"), index=False)
print(f'Participants pseudos database saved to {os.path.join(self.path, f"{self.folder}{self._PARTICIPANTS_PSEUDOS_DATABASE_FILE_SUFFIX}")}')
print(f'Participants pseudos database: \n{self.participants_pseudos_database}')
def save_processing_monitoring(self):
self.processing_monitoring_database.to_csv(os.path.join(self.processing_path, f"{self.folder}{self._PROCESSING_MONITORING_SUFFIX}"), index=False)
print(f'Processing monitoring database saved to {os.path.join(self.processing_path, f"{self.folder}{self._PROCESSING_MONITORING_SUFFIX}")}')
print(f'Processing monitoring database: \n{self.processing_monitoring_database}')
def save_experimental_parameters(self):
csv_path = os.path.join(self.path, f'{self.folder}{self._EXPERIMENTAL_PARAMETERS_SUFFIX}')
#check if the file already exists
if os.path.exists(csv_path):
overwrite = messagebox.askyesno("File already exists", f"File {csv_path} already exists. Do you want to overwrite it?")
if overwrite:
#copy the file to a backup, adding a timestamp
csv_backup_path = os.path.join(self.path, f"bckp_experimental_parameters_{pd.Timestamp.now().strftime('%Y%m%d_%H%M%S')}.csv")
os.rename(csv_path, csv_backup_path)
print('Parameters file backuped to {csv_backup_path}')
else:
return
with open(csv_path, "w", newline="") as csvfile:
writer = csv.writer(csvfile)
params=[]
for param_type, param_list in self.experimental_parameters.items():
params.append([param_type]+param_list)
writer.writerows(params,)
print(f"Parameters written to '{csv_path}'")
def save_recording_parameters(self):
csv_path = os.path.join(self.path, f'{self.folder}{self._RECORDING_PARAMETERS_SUFFIX}')
#check if the file already exists
if os.path.exists(csv_path):
overwrite = messagebox.askyesno("File already exists", f"File {csv_path} already exists. Do you want to overwrite it?")
if overwrite:
#copy the file to a backup, adding a timestamp
csv_backup_path = os.path.join(self.path, f"bckp_recording_parameters_{pd.Timestamp.now().strftime('%Y%m%d_%H%M%S')}.csv")
os.rename(csv_path, csv_backup_path)
print('Parameters file backuped to {csv_backup_path}')
else:
return
with open(csv_path, "w", newline="") as csvfile:
writer = csv.writer(csvfile)
params=[]
for param_type, param_list in self.recording_parameters.items():
params.append([param_type]+param_list)
writer.writerows(params,)
print(f"Parameters written to '{csv_path}'")
def save_instructions_languages(self):
self.instructions_languages.to_csv(os.path.join(self.path, f"{self.folder}{self._INSTRUCTIONS_LANGUAGES_SUFFIX}"), index=False)
def close(self):
if self.experiment_replayer is not None:
self.experiment_replayer.stop()
if self.experiment_pre_processor is not None:
self.experiment_pre_processor.stop()
if self.current_participant is not None:
self.current_participant.close()
class Participant:
def __init__(self, pseudo, session_path, session_experimental_parameters=None, recording_parameters=None, mode = 'Recording', language='English') -> None:
self.pseudo = pseudo
self.experimental_parameters = session_experimental_parameters
self.recording_parameters = recording_parameters
self.combinations_data = []
self.session_path = session_path
self.mode = mode
self.combinations_data = None
self.found_trial_folders = None
self.current_trial_index = 0
self.all_data_available = True
self.processed = False
self.missing_trial_folders = []
self.missing_data = []
self.available_trials = []
self.missing_trials = []
self.replayable_trials = []
self.analyzable_trials = []
self.expe_recorders = []
self.language = language
self.trial_ongoing = False
self.display_thread=None
self.path = os.path.join(self.session_path, self.pseudo)
self.pre_processing_path = os.path.join(f'{self.session_path}_processing/Pre_processing', self.pseudo)
self.replay_path = os.path.join(f'{self.session_path}_processing/Replay', self.pseudo)
self.analyse_path = os.path.join(f'{self.session_path}_processing/Analysis', self.pseudo)
if self.mode == 'Pre-processing':
self.source_path = self.path
self.destination_path = self.pre_processing_path
elif self.mode == 'Replay':
self.source_path = self.pre_processing_path
self.destination_path = self.replay_path
elif self.mode == 'Analysis':
self.source_path = self.replay_path
self.destination_path = self.analyse_path
if self.mode == 'Pre-processing':
if not os.path.exists(self.pre_processing_path):
answer = messagebox.askyesno(f"Participant pre_processing folder not found", f"Participant processing folder not found in {self.pre_processing_path}. Do you want to create a new one?")
if answer:
os.makedirs(self.pre_processing_path)
print(f"New participant pre_processing folder created in {self.pre_processing_path}")
if self.mode == 'Replay':
if not os.path.exists(self.replay_path):
answer = messagebox.askyesno(f"Participant replay folder not found", f"Participant replay folder not found in {self.replay_path}. Do you want to create a new one?")
if answer:
os.makedirs(self.replay_path)
print(f"New participant replay folder created in {self.replay_path}")
if self.mode == 'Analysis':
if not os.path.exists(self.analyse_path):
answer = messagebox.askyesno(f"Participant analysis folder not found", f"Participant analysis folder not found in {self.analyse_path}. Do you want to create a new one?")
if answer:
os.makedirs(self.analyse_path)
print(f"New participant analysis folder created in {self.analyse_path}")
self.combinations_path = os.path.join(self.path, f"{self.pseudo}_combinations.csv")
self.data_csv_path = os.path.join(self.path, f"{self.pseudo}_data.csv")
self.is_new = not os.path.exists(self.path)
self.participant_window = None
self.experimentator_window = None
self.progress_window = None
if self.is_new:
if mode != 'Recording':
print(f"Participant folder not found")
messagebox.showinfo(f"Participant folder not found", f"Participant folder not found in {self.path}")
self.all_data_available = False
self.missing_data.append('participant folder')
else:
os.makedirs(self.path)
self.generate_combinations()
if not self.is_new:
self.get_combinations()
self.fetch_trial_folders()
self.scan_found_trials()
if mode != 'Recording':
self.check_processed()
else:
if self.combinations_data is not None and len(self.available_trials)>0:
answer = messagebox.askyesnocancel(f"Participant folder already exists", f"Participant folder already exists in {self.path}. A combinations file and {len(self.available_trials)} trial folders were found. Please check the participant folder. Press 'yes' to resume the recording and complete missing trials. Press 'no' to delete existing data, generate a new combinations file and start a new recording. Else, press 'cancel' and select another participant.")
if answer == True:
self.all_data_available = True
elif answer == False:
self.back_up_data()
os.makedirs(self.path)
self.generate_combinations()
else:
return
def back_up_data(self):
if os.path.exists(self.path):
#copy the folder to a backup, adding a timestamp
backup_path = os.path.join(self.session_path, f"bckp_{self.pseudo}_{pd.Timestamp.now().strftime('%Y%m%d_%H%M%S')}")
os.rename(self.path, backup_path)
print(f"Participant folder backuped to {backup_path}")
def generate_combinations(self):
# get the parameters from the session and number of repetitions separately
number_of_repetitions = int(self.experimental_parameters['Number of repetitions'][0])
parameters_list = [value for key, value in self.experimental_parameters.items() if key != 'Number of repetitions']
keys_list = [key for key, value in self.experimental_parameters.items() if key != 'Number of repetitions']
# Check if any of the lists is empty or contains only empty strings
if any(not lst or all(val.strip() == "" for val in lst) for lst in parameters_list):
messagebox.showinfo("Empty List", "One or more lists are empty or contain only blank strings. Please provide valid input.")
return
# Generate all combinations of the elements from the lists
combinations_list = []
for i in range(number_of_repetitions):
combinations_list += list(itertools.product(*parameters_list))
# Shuffle the combinations in random order
random.shuffle(combinations_list)
self.combinations_data = pd.DataFrame(combinations_list, columns=keys_list)
self.missing_trials = []
for index, row in self.combinations_data.iterrows():
trial_folder_name = f"trial_{index}_combi"
for key, value in row.items():
trial_folder_name += f"_{value}"
self.combinations_data.loc[index, 'Trial Folder'] = trial_folder_name
self.combinations_data.loc[index, 'Trial Number'] = int(index+1)
self.missing_trials.append(Trial(trial_folder_name, self.path, row, participant_pre_processing_path=self.pre_processing_path, participant_replay_path=self.replay_path, participant_analysis_path=self.analyse_path))
self.save_combinations()
print(f"{len(self.combinations_data)} combinations generated and saved to '{self.combinations_path}'")
def get_combinations(self):
# check if the combinations file exists
if not os.path.exists(self.combinations_path):
print(f"Combinations file not found in {self.combinations_path}")
# messagebox.showinfo(f"Combinations file not found", f"Combinations file not found in {self.combinations_path}")
self.all_data_available = False
self.missing_data.append('combinations')
self.combinations_data = None
else:
#create a pandas dataframe from the csv and read header from file
self.combinations_data = pd.read_csv(self.combinations_path)
self.combinations_data = self.combinations_data.astype({'Trial Number': int})
# for index, row in self.combinations_data.iterrows():
# trial_index = row['Trial Number']
# objects = row['Objects']
# hand = row['Hands']
# grip = row['Grips']
# movement_type = row['Movement Types']
# trial_folder_name = f"trial_{trial_index}_combi_{objects}_{hand}_{grip}_{movement_type}"
# self.combinations_data.loc[index, 'Trial Folder'] = trial_folder_name
# self.combinations_data.loc[index, 'Trial Number'] = int(trial_index+1)
print(f"combinations data: \n{self.combinations_data}")
print(f"Combinations read from '{self.combinations_path}'")
def build_recorders(self, devices_ids, resolution, fps):
print('LESSGOOOOOOO')
for device_id in devices_ids:
expe_recorder = erc.ExperimentRecorder(self.path, device_id = device_id, resolution = resolution, fps = fps)
self.expe_recorders.append(expe_recorder)
def initiate_experiment(self):
devices_ids = self.recording_parameters['devices_ids']
self.resolution = self.recording_parameters['resolution']
fps = self.recording_parameters['fps'][0]
self.build_UIs()
self.build_recorders(devices_ids, self.resolution, fps)
self.save_experimental_parameters()
self.save_recording_parameters()
def start_experiment(self):
self.trial_ongoing = False
self.start_button.state(['disabled'])
self.display_next_trial_button.state(['!disabled'])
self.stop_button.state(['!disabled'])
self.current_trial_index=0
for expe_recorder in self.expe_recorders:
expe_recorder.init()
self.expe_running=True
self.display_thread = threading.Thread(target=self.display_task)
self.display_thread.start()
def stop_experiment(self):
print("Stopping experiment")
if self.trial_ongoing:
self.stop_current_trial()
self.expe_running=False
for rec in self.expe_recorders:
rec.stop()
if self.display_thread is not None:
self.display_thread.join()
print("Experiment stopped")
if self.participant_window is not None:
self.participant_window.destroy()
if self.experimentator_window is not None:
self.experimentator_window.destroy()
def display_next_trial(self):
self.current_trial = self.missing_trials[self.current_trial_index]
self.trials_advancement.set(f"Trial {self.current_trial_index+1}/{self.nb_missing_trials}")
self.current_trial_combination.set(self.current_trial.get_combination())
procede = self.current_trial.check_and_make_dir()
if procede:
# self.instructions_text.set(self.current_trial.get_instructions())
txt = self.current_trial.get_instructions_colored()
self.instructions_text_widget.delete('1.0', tk.END)
for text, tag in txt:
self.instructions_text_widget.insert(tk.END, text, tag)
self.display_next_trial_button.state(['disabled'])
self.start_next_trial_button.state(['!disabled'])
else:
self.current_trial_index += 1
self.display_next_trial()
def start_next_trial(self):
self.trial_ongoing = True
self.start_next_trial_button.state(['disabled'])
self.stop_current_trial_button.state(['!disabled'])
self.instructions_text_widget.insert(tk.END, " \n \n \n \nRecording", "recording")
for rec in self.expe_recorders:
rec.record_trial(self.current_trial)
def stop_current_trial(self):
self.trial_ongoing = False
for rec in self.expe_recorders:
rec.stop_record()
if self.current_trial_index >= len(self.missing_trials)-1:
self.instructions_text_widget.delete('1.0', tk.END)
self.instructions_text_widget.insert(tk.END, "\n \n \n \n \n \n CONGRATULATIONS, YOU HAVE COMPLETED THE EXPERIMENT !", "center")
else:
self.current_trial_index += 1
self.display_next_trial_button.state(['!disabled'])
self.display_next_trial()
self.stop_current_trial_button.state(['disabled'])
print(f"Stopped {self.current_trial.label}")
def display_task(self):
rotate = False
while self.expe_running:
imgs=[]
for rec in self.expe_recorders:
if rec.img is not None:
named_img = rec.img.copy()
if rotate:
named_img = cv2.rotate(named_img, cv2.ROTATE_90_CLOCKWISE)
#TODO : resize the image to fit the screen
named_img = cv2.putText(named_img, f'view {rec.device_id}', (50,50), cv2.FONT_HERSHEY_SIMPLEX, 1, (88, 205, 54), 1, cv2.LINE_AA)
if self.trial_ongoing:
named_img = cv2.putText(named_img, 'Recording', (50,100), cv2.FONT_HERSHEY_SIMPLEX, 1, (10, 10, 255), 1, cv2.LINE_AA)
imgs.append(named_img)
if len(imgs) > 0:
side_by_side_img = cv2.hconcat(imgs)
# cv2.imshow(self.current_trial.label,side_by_side_img)
if not rotate:
side_by_side_img = cv2.resize(side_by_side_img, (self.resolution[0], int(self.resolution[1]/len(imgs))))
cv2.imshow(f'Recording participant {self.pseudo}',side_by_side_img)
k = cv2.waitKey(1)
if k == ord('q'):
break
cv2.destroyAllWindows()
def build_participant_UI(self):
self.participant_window = tk.Toplevel()
size=720
# self.participant_window.attributes('-fullscreen', True)
self.participant_window.title(f'Instructions for participant {self.pseudo}')
frame = ttk.Frame(self.participant_window)
frame.pack(fill=tk.BOTH, expand=True)
# self.instructions_text = tk.StringVar()
# get the instruction corresponding to the label 'Welcome'
# self.instructions_text.set(self.instructions.loc[self.instructions['Label'] == 'Welcome', 'Instructions'].values[0])
#TODO : add language selection
# self.instructions_text.set("Please read the instructions below and click on 'Start' when you are ready to start the experiment.")
# self.instructions_label = ttk.Label(self.participant_window, textvariable=self.instructions_text, font=("Helvetica", 25), wraplength=size-20, justify='center')
# #center the label vertically
# self.instructions_label.pack(fill=tk.BOTH, expand=True)
main_font = ["Helvetica", 30]
self.instructions_text_widget = tk.Text(frame, font=("Helvetica", 25), wrap=tk.WORD)
self.instructions_text_widget.pack(fill=tk.BOTH, expand=True,anchor='center')
self.instructions_text_widget.tag_configure("center", justify='center',font=("Helvetica", 25, "bold"))
self.instructions_text_widget.tag_configure("recording", justify='center',font=("Helvetica", 25, "bold"), foreground="red")
self.instructions_text_widget.tag_configure("left", justify='left')
self.instructions_text_widget.tag_configure("red", foreground="red")
self.instructions_text_widget.tag_configure("green", foreground="green")
self.instructions_text_widget.tag_configure("blue", foreground="blue")
self.instructions_text_widget.tag_configure("purple", foreground="pink")
self.instructions_text_widget.tag_configure("title", font=('Helvetica', 35), justify='center')
self.instructions_text_widget.tag_configure("normal", font=main_font)
self.instructions_text_widget.tag_configure("intro", font=main_font+["bold"], justify='center')
self.instructions_text_widget.tag_configure("hand", font=main_font+["bold"], foreground="#5bc0de")
self.instructions_text_widget.tag_configure("mov_type", font=main_font+["bold"], foreground="#5cb85c")
self.instructions_text_widget.tag_configure("grip", font=main_font+["bold"], foreground="#ffc107")
self.instructions_text_widget.tag_configure("object", font=main_font+["bold"], foreground="#d9534f")
self.instructions_text_widget.tag_configure("bold", font=("Helvetica", 25, "bold"))
self.instructions_text_widget.tag_configure("italic", font=("Helvetica", 25, "italic"))
self.instructions_text_widget.tag_configure("underline", font=("Helvetica", 25, "underline"))
self.instructions_text_widget.insert(tk.END, self.instructions.loc[self.instructions['Label'] == 'Welcome', 'Instructions'].values[0], "center")
def build_experimentator_UI(self):
self.experimentator_window = tk.Toplevel()
self.experimentator_window.geometry("720x720")
self.experimentator_window.title(f'Instructions for experimentator {self.pseudo}')
frame = ttk.Frame(self.experimentator_window)
frame.pack()
# frame.pack(fill=tk.BOTH, expand=True)
self.nb_missing_trials = len(self.missing_trials)
self.trials_advancement = tk.StringVar()
self.trials_advancement.set(f"Trial -/{self.nb_missing_trials}")