def test_duplicate_session(self): test_folder = Folder(self.session.session_id, self.folder_dir).save_to_db( testing=True, postgresql=self.postgresql) dup_folder = test_folder.save_to_db(testing=True, postgresql=self.postgresql) self.assertFalse(dup_folder.folder_id is None)
def test_from_db(self): load_folder = Folder.from_db(folder_dir=self.folder_dir, testing=True, postgresql=self.postgresql) self.assertEqual(self.session.session_id, load_folder.session_id) self.assertEqual(self.folder_dir, load_folder.folder_dir) self.assertFalse(load_folder.folder_id is None)
def handler_seed_blind_trials(postgresql): all_trials = [ 'trial_1.txt', 'trial_2.txt', 'trial_3.txt', 'trial_4.txt', 'trial_5.txt' ] with TestingCursor(postgresql) as cursor: handler_seed_blind_folders_table_only(cursor) all_blind_names = models.blind_folders.list_all_blind_names(cursor) for blind_name in all_blind_names: blind_folder = BlindFolder.from_db(blind_name=blind_name, testing=True, postgresql=postgresql) reviewer = Reviewer.from_db(reviewer_id=blind_folder.reviewer_id, testing=True, postgresql=postgresql) folder = Folder.from_db(folder_id=blind_folder.folder_id, testing=True, postgresql=postgresql) for trial_file in all_trials: trial = Trial.from_db(trial_dir='/'.join( [folder.folder_dir, trial_file]), testing=True, postgresql=postgresql) full_path = '/'.join( [reviewer.toScore_dir, blind_name, blind_name + trial_file]) with TestingCursor(postgresql) as cursor: database.seed_tables.seed_tables.seed_blind_trials_table( cursor, trial.trial_id, trial.folder_id, full_path)
def setUp(self): self.postgresql = Postgresql() database.handlers.handlers.handler_seed_trials_table(self.postgresql) with TestingCursor(self.postgresql) as cursor: cursor.execute("SELECT session_dir from sessions;") all_session_dir = cursor.fetchall() session_dir = all_session_dir.pop() self.session = Session.from_db(session_dir=session_dir, testing=True, postgresql=self.postgresql) folder_dir = '/'.join([self.session.session_dir, 'Reaches02']) self.folder = Folder.from_db(folder_dir, testing=True, postgresql=self.postgresql) self.trial_dir = '/'.join([self.folder.folder_dir, 'trial_1.txt'])
def setUp(self): self.postgresql = Postgresql() database.handlers.handlers.handler_seed_trials_table(self.postgresql) database.handlers.handlers.handler_seed_reviewers_table(self.postgresql) with TestingCursor(self.postgresql) as cursor: database.handlers.handlers.handler_seed_blind_folders_table_only(cursor) blind_name = models.blind_folders.list_all_blind_names(cursor).pop() trial = 'trial_1.txt' self.blind_folder = BlindFolder.from_db(blind_name=blind_name, testing=True, postgresql=self.postgresql) self.folder = Folder.from_db(folder_id=self.blind_folder.folder_id, testing=True, postgresql=self.postgresql) self.reviewer = Reviewer.from_db(reviewer_id=self.blind_folder.reviewer_id, testing=True, postgresql=self.postgresql) self.trial = Trial.from_db(trial_dir='/'.join([self.folder.folder_dir, trial]), testing=True, postgresql=self.postgresql) self.full_path = '/'.join([self.reviewer.toScore_dir, self.blind_folder.blind_name, self.blind_folder.blind_name + '_1.txt'])
def test_add_new_trial(self): test_folder_dir = '/exp/two/dir/9993/20200516_S1/Reaches01' test_trial = 'trial_2.txt' trial_dir = '/'.join([test_folder_dir, test_trial]) test_folder = Folder.from_db(folder_dir=test_folder_dir, testing=True, postgresql=self.postgresql) test_session = Session.from_db(test_folder.session_id, testing=True, postgresql=self.postgresql) test_trial = Trial(test_session.experiment_id, test_folder.folder_id, trial_dir, test_session.session_date).save_to_db( testing=True, postgresql=self.postgresql) self.assertEqual(test_session.experiment_id, test_trial.experiment_id) self.assertEqual(test_folder.folder_id, test_trial.folder_id) self.assertEqual(trial_dir, test_trial.trial_dir) self.assertEqual(test_session.session_date, test_trial.trial_date) self.assertFalse(test_trial.trial_id is None)
def handler_seed_trials_table(postgresql): handler_seed_folders_table(postgresql) all_trials = [ 'trial_1.txt', 'trial_2.txt', 'trial_3.txt', 'trial_4.txt', 'trial_5.txt' ] with TestingCursor(postgresql) as cursor: cursor.execute("SELECT * from folders_all_upstream_ids;") all_ids = cursor.fetchall() for [_, experiment_id, session_id, folder_id] in all_ids: folder = Folder.from_db(folder_id=folder_id, testing=True, postgresql=postgresql) session = Session.from_db(session_id, testing=True, postgresql=postgresql) for trial in all_trials: trial_dir = '/'.join([folder.folder_dir, trial]) database.seed_tables.seed_tables.seed_trials_table( cursor, experiment_id, folder_id, trial_dir, session.session_date)
from models.folders import Folder from models.blind_folders import BlindFolder from models.reviewers import Reviewer from models.trials import Trial from models.blind_trials import BlindTrial import shutil import os Database.initialize(**dbDetails, **dbUser_Krista) experiment_name = 'skilled-reaching' reviewer_name = 'Krista K' num_folders_to_mask = 25 sr_exp = Experiment.from_db(experiment_name) all_folders = Folder.list_all_folders(sr_exp.experiment_id) all_blind_folders = BlindFolder.list_all_blind_folders(sr_exp.experiment_id) all_not_blind_folders = list() for folder in all_folders: for blind_folder in all_blind_folders: if folder.folder_id == blind_folder.folder_id: break if folder.folder_id == blind_folder.folder_id: continue all_not_blind_folders.append(folder) folders_to_mask = list() for ii in range(num_folders_to_mask): folders_to_mask.append(all_not_blind_folders.pop())
from models.trials import Trial from models.blind_trials import BlindTrial import models.trials from database.database import Database from data.constants import dbDetails, dbUser_Krista Database.initialize(**dbDetails, **dbUser_Krista) scrambled_mask_keys_file = Path('/Users/Krista/Desktop/master_file_keys_scrambled.csv') with open(scrambled_mask_keys_file) as f: scrambled_mask_keys = list(csv.reader(f)) for (LED_detection_output_csv, reviewer_fullname, blind_name) in scrambled_mask_keys: csv_num = LED_detection_output_csv.split('_')[-1] csv_num = csv_num.strip('.csv') folder_dir = Path(LED_detection_output_csv).parent.joinpath(f'Reaches{csv_num}') folder = Folder.from_db(str(folder_dir)) reviewer = Reviewer.from_db(reviewer_fullname) blind_folder = BlindFolder(folder.folder_id, reviewer.reviewer_id, blind_name).save_to_db() all_trial_dirs_for_folder = Trial.list_trial_dir_for_folder(folder.folder_id) count = 0 for trial_dir in all_trial_dirs_for_folder: count += 1 if len(str(count)) < 2: blind_trial_num = f'0{count}' else: blind_trial_num = str(count) blind_trial_full_path = Path(reviewer.toScore_dir).joinpath( f'{blind_folder.blind_name}/{blind_folder.blind_name}_R{blind_trial_num}.mp4') trial = Trial.from_db(trial_dir) blind_trial = BlindTrial(trial.trial_id, folder.folder_id, str(blind_trial_full_path)).save_to_db()
def test_add_new_session(self): test_folder = Folder(self.session.session_id, self.folder_dir).save_to_db( testing=True, postgresql=self.postgresql) self.assertFalse(test_folder.folder_id is None)