Пример #1
0
 def from_db(cls, eartag, experiment_name, testing=False, postgresql=None):
     if testing:
         with TestingCursor(postgresql) as cursor:
             mouse = Mouse.from_db(eartag,
                                   testing=testing,
                                   postgresql=postgresql)
             experiment = Experiment.from_db(experiment_name,
                                             testing=testing,
                                             postgresql=postgresql)
             return cls.__from_db(cursor, mouse, experiment)
     else:
         with Cursor() as cursor:
             mouse = Mouse.from_db(eartag)
             experiment = Experiment.from_db(experiment_name)
             return cls.__from_db(cursor, mouse, experiment)
Пример #2
0
 def test_from_db(self):
     self.load_mouse = Mouse.from_db(self.seed_tup[0], testing=True, postgresql=self.postgresql)
     self.assertEqual(self.seed_tup[0], self.load_mouse.eartag)
     self.assertEqual(self.seed_tup[1], self.load_mouse.birthdate)
     self.assertEqual(self.seed_tup[2], self.load_mouse.genotype)
     self.assertEqual(self.seed_tup[3], self.load_mouse.sex)
     self.assertFalse(self.load_mouse.mouse_id is None)
Пример #3
0
 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 setUp(self):
     self.postgresql = Postgresql()
     database.handlers.handlers.handler_seed_sessions_table(self.postgresql)
     [eartag, _, _, _, _, experiment_name, _, _] = test_mouse_table_seed.pop()
     self.mouse = Mouse.from_db(eartag, testing=True, postgresql=self.postgresql)
     self.experiment = Experiment.from_db(experiment_name, testing=True, postgresql=self.postgresql)
     possible_sessions = test_session_table_seed[eartag, utils.prep_string_for_db(experiment_name)]
     self.session_date, self.session_dir = possible_sessions.pop()
 def setUp(self):
     self.postgresql = Postgresql()
     database.handlers.handlers.handler_seed_mouse(self.postgresql)
     database.handlers.handlers.handler_seed_experiments(self.postgresql)
     self.mouse = Mouse.from_db(9990, testing=True, postgresql=self.postgresql)
     self.experiment = Experiment.from_db('test-experiment-one', testing=True, postgresql=self.postgresql)
     self.session_date = 20200503
     self.session_dir = '/exp/one/dir/9990/20200503_S2'
def main():
    pc = Pc()

    pc.add_element(Motherboard())
    pc.add_element(GraphicCard())
    pc.add_element(Keyboard())
    pc.add_element(Monitor())
    pc.add_element(Mouse())

    print(pc)
Пример #7
0
 def test_list_participants(self):
     all_participants = ParticipantDetails.list_participants(
         self.exp_seed[0], testing=True, postgresql=self.postgresql)
     self.assertTrue(len(all_participants) == 5)
     for mouse_id in all_participants:
         eartag = Mouse.from_db_by_id(mouse_id,
                                      testing=True,
                                      postgresql=self.postgresql).eartag
         if 'one' in self.exp_seed[0]:
             self.assertTrue((eartag % 2) == 0)
         else:
             self.assertTrue((eartag % 2) != 0)
Пример #8
0
 def test_from_db(self):
     test_details = ParticipantDetails.from_db(self.mouse_seed[0],
                                               self.mouse_seed[5],
                                               testing=True,
                                               postgresql=self.postgresql)
     self.assertTrue(
         Mouse.from_db(self.mouse_seed[0],
                       testing=True,
                       postgresql=self.postgresql) == test_details.mouse)
     self.assertTrue(
         Experiment.from_db(
             self.mouse_seed[5], testing=True, postgresql=self.postgresql)
         == test_details.experiment)
     self.assertFalse(test_details.detail_id is None)
Пример #9
0
 def test_add_new_participant_details(self):
     test_mouse = Mouse.from_db(self.mouse_seed[0],
                                testing=True,
                                postgresql=self.postgresql)
     test_exp = Experiment.from_db(self.mouse_seed[5],
                                   testing=True,
                                   postgresql=self.postgresql)
     test_details = ParticipantDetails(
         test_mouse, test_exp, self.mouse_seed[6],
         self.mouse_seed[7]).save_to_db(testing=True,
                                        postgresql=self.postgresql)
     self.assertTrue(test_mouse == test_details.mouse)
     self.assertTrue(test_exp == test_details.experiment)
     self.assertFalse(test_details.detail_id is None)
Пример #10
0
def list_participants(experiment_name='all'):
    if experiment_name == 'all':
        all_participants = dict()
        with Cursor() as cursor:
            all_experiments = list_all_experiments(cursor)
        for experiment_name in all_experiments:
            all_participants[experiment_name] = sorted(set(
                (Mouse.from_db_by_id(mouse_id).eartag
                 for mouse_id in list_participants(experiment_name))),
                                                       key=int)
        return all_participants
    experiment_participant_details = ParticipantDetails.list_participants(
        experiment_name)
    return sorted(set(experiment_participant_details), key=int)
Пример #11
0
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_participant_details(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_pd.seed_participant_details(cursor,
                                                     mouse.mouse_id,
                                                     experiment.experiment_id,
                                                     start_date=m[6],
                                                     end_date=m[7])
Пример #13
0
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)
Пример #14
0
 def test_delete_mouse(self):
     mouse_to_delete = Mouse.from_db(self.seed_tup[0], testing=True, postgresql=self.postgresql)
     mouse_to_delete.delete_from_db(testing=True, postgresql=self.postgresql)
     test_reload_mouse = Mouse.from_db(self.seed_tup[0], testing=True, postgresql=self.postgresql)
     self.assertIsNone(test_reload_mouse)
Пример #15
0
 def test_duplicate_mouse(self):
     test_mouse = Mouse(1111, self.birthdate, 'wild type', 'female').save_to_db(testing=True,
                                                                                postgresql=self.postgresql)
     dup_mouse = test_mouse.save_to_db(testing=True, postgresql=self.postgresql)
     self.assertFalse(dup_mouse.mouse_id is None)
Пример #16
0
from templates.experiment_specific_details import skilled_reaching
from utilities import read_table_csv_to_list

Database.initialize(**dbDetails, **dbUser_Krista)

project_base_dir = Path(__file__).parent.parent.parent
backup_csv_path = os.path.join(project_base_dir, 'data', 'database_backup_csv')

tables_to_populate = ['mouse', 'experiments', 'participant_details']

# MOUSE TABLE
all_mouses = read_table_csv_to_list(backup_csv_path, 'mouse')
for [mouse_id, eartag, birthdate, genotype, sex] in all_mouses:
    eartag = int(eartag)
    birthdate = ''.join(birthdate.split('-'))
    Mouse(eartag, int(birthdate), genotype, sex).save_to_db()

# EXPERIMENTS TABLE
all_experiments = read_table_csv_to_list(backup_csv_path, 'experiments')
for [experiment_id, experiment_dir, experiment_name] in all_experiments:
    Experiment(experiment_name, experiment_dir).save_to_db()

# PARTICIPANT DETAILS TABLE
all_participant_details = read_table_csv_to_list(backup_csv_path,
                                                 'participant_details')
for participant_detail in all_participant_details:
    detail_id = participant_detail[0]
    mouse_id = participant_detail[1]
    experiment_id = participant_detail[2]
    start_date = participant_detail[3]
    start_date = int(''.join(start_date.split('-')))