def __init__(self, mouse, experiment, participant_dir=None, start_date=None, end_date=None, exp_spec_details=None, detail_id=None): self.mouse = mouse self.experiment = experiment self.participant_dir = participant_dir self.start_date = utils.convert_date_int_yyyymmdd(start_date) self.end_date = utils.convert_date_int_yyyymmdd(end_date) self.exp_spec_details = exp_spec_details self.detail_id = detail_id
def test_from_db(self): load_session = Session.from_db(session_dir=self.session_dir, testing=True, postgresql=self.postgresql) self.assertEqual(self.mouse.mouse_id, load_session.mouse_id) self.assertEqual(self.experiment.experiment_id, load_session.experiment_id) self.assertEqual(utils.convert_date_int_yyyymmdd(self.session_date), load_session.session_date) self.assertEqual(self.session_dir, load_session.session_dir) self.assertFalse(load_session.session_id is None)
def test_add_new_mouse(self): test_mouse = Mouse(1111, self.birthdate, 'wild type', 'female').save_to_db(testing=True, postgresql=self.postgresql) self.assertEqual(1111, test_mouse.eartag) self.assertEqual(util.convert_date_int_yyyymmdd(self.birthdate), test_mouse.birthdate) self.assertEqual('wild type', test_mouse.genotype) self.assertEqual('female', test_mouse.sex) self.assertFalse(test_mouse.mouse_id is None)
def __init__(self, mouse_id, experiment_id, session_dir, session_date=None, session_id=None): self.mouse_id = mouse_id self.experiment_id = experiment_id self.session_dir = session_dir self.session_date = utils.convert_date_int_yyyymmdd(session_date) self.session_id = session_id
def __init__(self, experiment_id, folder_id, trial_dir, trial_date, trial_id=None): self.experiment_id = experiment_id self.folder_id = folder_id self.trial_dir = trial_dir self.trial_date = utils.convert_date_int_yyyymmdd(trial_date) self.trial_id = trial_id
def handler_seed_sessions_table(postgresql): handler_seed_mouse(postgresql) handler_seed_experiments(postgresql) with TestingCursor(postgresql) as cursor: for [mouse_eartag, experiment_name] in session_seed.keys(): all_sessions = session_seed[mouse_eartag, experiment_name] mouse = Mouse.from_db(mouse_eartag, testing=True, postgresql=postgresql) experiment = Experiment.from_db(experiment_name, testing=True, postgresql=postgresql) for [session_date, session_dir] in all_sessions: database.seed_tables.seed_tables.seed_sessions_table( cursor, mouse.mouse_id, experiment.experiment_id, utils.convert_date_int_yyyymmdd(session_date), session_dir)
def handler_seed_trials(postgresql): with TestingCursor(postgresql) as cursor: seed_id.seed_mouse_table(cursor) seed_id.seed_experiments_table(cursor) with TestingCursor(postgresql) as cursor: all_mice = list_all_mice(cursor) for eartag in all_mice: mouse = Mouse.from_db(eartag, testing=True, postgresql=postgresql) for m in mouse_seed: if m[0] == mouse.eartag: experiment = Experiments.from_db(m[5], testing=True, postgresql=postgresql) seed_mouse_all_trials = trial_seed[( mouse.eartag, experiment.experiment_name)] for trial in seed_mouse_all_trials: trial_date, trial_dir = trial seed_tr.seed_trials( cursor, mouse.mouse_id, experiment.experiment_id, utils.convert_date_int_yyyymmdd(trial_date), trial_dir)
def main(a_cursor, trial_dir): cursor.execute( "INSERT INTO trials (experiment_id, folder_id, trial_dir, trial_date) VALUES (%s, %s, %s, %s);", (self.experiment_id, self.folder_id, self.trial_dir, utils.convert_date_int_yyyymmdd(self.trial_date))) return self.__from_db_by_dir(a_cursor, trial_dir)
import utilities as util birthdate1 = util.convert_date_int_yyyymmdd(20200101) birthdate2 = util.convert_date_int_yyyymmdd(20200102) start1 = util.convert_date_int_yyyymmdd(20200501) end1 = util.convert_date_int_yyyymmdd(20200601) start2 = util.convert_date_int_yyyymmdd(20200515) end2 = util.convert_date_int_yyyymmdd(20200615) test_mouse_table_seed = [(9990, birthdate2, 'wild type', 'male', True, 'test experiment one', start1, end1), (9991, birthdate1, 'wild type', 'male', False, 'test experiment two', start2, end2), (9992, birthdate1, 'wild type', 'male', True, 'test experiment one', start1, end1), (9993, birthdate1, 'wild type', 'male', False, 'test experiment two', start2, end2), (9994, birthdate1, 'wild type', 'female', True, 'test experiment one', start1, end1), (9995, birthdate1, 'wild type', 'female', False, 'test experiment two', start2, end2), (9996, birthdate1, 'knock out', 'female', True, 'test experiment one', start1, end1), (9997, birthdate1, 'knock out', 'female', False, 'test experiment two', start2, end2), (9998, birthdate1, 'knock out', 'female', True, 'test experiment one', start1, end1), (9999, birthdate2, 'knock out', 'female', False, 'test experiment two', start2, end2)] exp_one = ('test experiment one', '/test/directory/experiment/one') exp_two = ('test experiment two', '/test/directory/experiment/two')
def test_isdate(self): may182020 = datetime.date(2020, 5, 18) out_date = utilities.convert_date_int_yyyymmdd(may182020) self.assertEqual(may182020, out_date)
def test_isint(self): may192020 = 20200519 out_date = utilities.convert_date_int_yyyymmdd(may192020) self.assertIsInstance(out_date, datetime.date) self.assertEqual(datetime.date(2020, 5, 19), out_date)