Пример #1
0
def list_all_experiments(exported_archive):

    experiments_module = python.impfromsource(
        conf.repository_experiments_modulename, exported_archive
    )

    experiments_settings\
    = os.path.join(exported_archive, conf.repository_settings_filename)

    config = configobj.ConfigObj(
        experiments_settings,
        configspec = conf.repository_settings_configspec
        )

    validator = validate.Validator()
    assert config.validate(validator, copy=True)

    experiments = []
    for class_name in config['experiments']:

        try:

            getattr(experiments_module, class_name)

        except AttributeError:

            raise AssertionError('No such experiment: %s' % class_name)

        
        experiments.append(class_name)

    return experiments
Пример #2
0
    def make_experiments(self):

        '''
        Create experiment versions (and their experiment parents, if necessary)
        for each experiment listed in this archive. The creation entails the
        creation of playlists for each experiment.
        '''

        exported_archive = git.export(self.repository.path,
                                      self.commit_hash)

        experiments_module = python.impfromsource(
            conf.repository_experiments_modulename, exported_archive
        )

        experiments_settings = os.path.join(exported_archive,
                                            conf.repository_settings_filename)

        config = configobj.ConfigObj(
            experiments_settings,
            configspec = conf.repository_settings_configspec
            )

        validator = validate.Validator()

        assert config.validate(validator, copy=True)

        for class_name, experiment_notes in config['experiments'].items():

            label = utils.make_experiment_release_code(class_name,
                                                       self)

            release_note = experiment_notes['release-note']

            try:

                playlist_factory = getattr(experiments_module, class_name)

            except AttributeError:

                error_msg = strings.msg('''
                No experiment named %s in the repository %s (commit hash: %s).
                ''' % (class_name, self.repository.name, self.commit_hash)
                )

                print(error_msg) # You could log it too.

                raise

            playlist = playlist_factory.new()

            ExperimentVersion.new(
                experiment=Experiment.new(class_name=class_name),
                label=label,
                release_note=release_note,
                playlist=playlist,
                archive=self)
Пример #3
0
def get_experiment_details(exported_archive):
    '''
    Using the settings.cfg file inside the exported wilhelm
    experiments_directory, get the checksum of the source code of the
    Playlist sub class for each experiment listed therein as well as the
    file path names and checksums of the included files.

    This information is useful only to check if the relevant source and stimuli
    files for a given experiment change from one repository version to another.
    If they have changed, we know the experiment has changed.

    Return as dictionary of lists of tuples.
    '''

    experiments_module = python.impfromsource(
        conf.repository_experiments_modulename, exported_archive
    )

    experiments_settings\
    = os.path.join(exported_archive, conf.repository_settings_filename)

    config = configobj.ConfigObj(
        experiments_settings,
        configspec = conf.repository_settings_configspec
        )

    validator = validate.Validator()
    assert config.validate(validator, copy=True)

    experiments_dir = {}
    for class_name, expdict in config['experiments'].items():

        release_note = expdict['release-note']

        experiment_source = inspect.getsource(
            getattr(experiments_module, class_name)
            )

        file_info = dict(
            class_source = sys.checksum(experiment_source)
            )
       
        for filename in expdict['include']:

            file_hash = sys.checksum(
                os.path.join(exported_archive, filename)
            )

            file_info[filename] = file_hash

        experiments_dir[class_name] = dict(
                release_note = release_note, 
                file_info = file_info)

    return experiments_dir
Пример #4
0
    def import_experiments(self):
        '''
        Import the experiments from wilhelm_experiments tarball.
        '''

        self.extract()

        # Import the experiments.
        experiments = python.impfromsource(
            conf.repository_experiments_modulename, self.extraction_dir
        )

        shutil.rmtree(self.extraction_dir)

        return experiments
Пример #5
0
def create_experiment():

    experiment_name = 'brisbane'

    experiment_title = experiment_class_name = 'Brisbane'

    experiment_archive = os.path.join(this_dir, 'experiment_repository')

    experiments_module= python.impfromsource(
        repository_experiments_modulename, experiment_archive
    )

    experiments_settings = os.path.join(experiment_archive,
                                        repository_settings_filename)

    config = configobj.ConfigObj(
        experiments_settings,
        configspec = repository_settings_configspec
        )

    validator = validate.Validator()

    assert config.validate(validator, copy=True)

    for class_name, experiment_notes in config['experiments'].items():

        label = class_name + 'foobaz123456789'

        release_note = experiment_notes['release-note']

        playlist_factory = getattr(experiments_module, class_name)

        playlist = playlist_factory.new()

        fake_repository\
            = ExperimentRepository.objects.create(name = 'fake_repo')
        fake_archive\
            = ExperimentArchive.objects.create(repository=fake_repository,
                                               commit_hash=strings.uid())

        blurb = ' '.join(""" In this experiment, your memory for word lists
                         or short texts will be tested.  For example, you
                         could be shown a list of words and then asked to
                         recall as many as you can. Or you could be asked
                         to read a short text and then asked if certain
                         words occurred or not. There are six parts to this
                         experiment and each part will take around 3-5
                         minutes.  """.split())

        title = 'Memory for texts and word lists'

        experiment\
            = Experiment.objects.create(class_name=class_name,
                                        live=True,
                                        title = title,
                                        blurb=blurb)

        ExperimentVersion.new(
            experiment=experiment,
            label=label,
            release_note=release_note,
            playlist=playlist,
            archive=fake_archive)

    return experiment_name, experiment_class_name, experiment_title