Exemplo n.º 1
0
def get_hits(status):
    amt_services_wrapper = MTurkServicesWrapper()
    all_studies = False
    if status == 'active':
        hits_data = (amt_services_wrapper.get_active_hits(
            all_studies=all_studies)).data
    elif status == 'reviewable':
        hits_data = (amt_services_wrapper.get_reviewable_hits(
            all_studies=all_studies)).data
    else:
        hits_data = (amt_services_wrapper.get_all_hits(
            all_studies=all_studies)).data
    return hits_data
Exemplo n.º 2
0
def test_task_approve_all(patch_aws_services, stubber, mocker, caplog):

    from psiturk.amt_services_wrapper import MTurkServicesWrapper
    aws_services_wrapper = MTurkServicesWrapper()

    import psiturk.tasks
    mocker.patch.object(psiturk.tasks.TaskUtils, 'aws_services_wrapper',
                        aws_services_wrapper)
    mocked_approve_all = mocker.patch.object(aws_services_wrapper,
                                             'approve_all_assignments')

    from psiturk.tasks import do_approve_all
    do_approve_all('sandbox')

    mocked_approve_all.assert_called_once()
Exemplo n.º 3
0
def test_campaign_round_codeversion_change_cancel(patch_aws_services, campaign,
                                                  mocker, caplog):
    from psiturk.tasks import do_campaign_round

    campaign_args = {'campaign': campaign, 'job_id': campaign.campaign_job_id}

    from psiturk.experiment import app
    mocker.patch.object(app.apscheduler, 'remove_job',
                        lambda *args, **kwargs: True)

    from psiturk.amt_services_wrapper import MTurkServicesWrapper
    aws_services_wrapper = MTurkServicesWrapper()
    aws_services_wrapper.config['Task Parameters'][
        'experiment_code_version'] = '1.1'

    import psiturk.tasks
    mocker.patch.object(psiturk.tasks.TaskUtils, 'aws_services_wrapper',
                        aws_services_wrapper)

    import psiturk.experiment
    remove_job_mock = mocker.patch.object(psiturk.experiment.app.apscheduler,
                                          'remove_job')
    do_campaign_round(**campaign_args)
    remove_job_mock.assert_called()
Exemplo n.º 4
0
    def amt_services_wrapper(self):
        if not self._cached_amt_services_wrapper:
            try:
                _wrapper = MTurkServicesWrapper(config=self.config,
                                                sandbox=self.sandbox)
                self._cached_amt_services_wrapper = _wrapper
            except AmtServicesException as e:
                still_can_do = '\n'.join([
                    '',
                    'You can still use the psiturk server by running non-AWS commands such as:',
                    '- `psiturk server <subcommand>`', '- `psiturk server on`',
                    '- `psiturk server off`', '- `psiturk debug -p`'
                ])
                message = '{}{}'.format(e.message, still_can_do)
                self.pfeedback(message)
            except PsiturkException as e:
                self.poutput(e)

        return self._cached_amt_services_wrapper
Exemplo n.º 5
0
def test_campaign_posts_hits(patch_aws_services, stubber, campaign, mocker,
                             caplog):

    from psiturk.amt_services_wrapper import MTurkServicesWrapper
    aws_services_wrapper = MTurkServicesWrapper()

    import psiturk.tasks
    mocker.patch.object(psiturk.tasks.TaskUtils, 'aws_services_wrapper',
                        aws_services_wrapper)
    mocked_create_hit = mocker.patch.object(aws_services_wrapper, 'create_hit')

    campaign_args = {'campaign': campaign, 'job_id': campaign.campaign_job_id}
    from psiturk.tasks import do_campaign_round
    do_campaign_round(**campaign_args)

    assert mocked_create_hit.call_count == 2
    mocked_create_hit.assert_any_call(num_workers=9,
                                      reward=campaign.hit_reward,
                                      duration=campaign.hit_duration_hours)
    mocked_create_hit.assert_any_call(num_workers=1,
                                      reward=campaign.hit_reward,
                                      duration=campaign.hit_duration_hours)
Exemplo n.º 6
0
 def amt_services_wrapper(self):
     if not self._cached_amt_services_wrapper:
         self._cached_amt_services_wrapper = MTurkServicesWrapper()
     return self._cached_amt_services_wrapper
Exemplo n.º 7
0
#!/usr/bin/env python2
"""
Approves and bonuses (if applicable) all workers in the database for the
current psiturk project.
"""

from __future__ import print_function
from psiturk.amt_services_wrapper import MTurkServicesWrapper, Participant, init_db, db_session

wrapper = MTurkServicesWrapper()
amt = wrapper.amt_services
config = wrapper.config

init_db()

if amt.is_sandbox:
    print('ERROR: Set "launch_in_sandbox_mode = false" in config.txt')
    exit(1)
if not amt.connect_to_turk():
    print('ERROR: Failed to connect to turk for some inexplicable reason.')
    exit(1)


class ApproveError(Exception):
    pass


class BonusError(Exception):
    pass