Exemplo n.º 1
0
    def do_it():
        from psiturk.psiturk_shell import PsiturkNetworkShell
        import psiturk.experiment_server_controller as control
        from psiturk.psiturk_config import PsiturkConfig

        import psiturk.experiment_server_controller
        mocker.patch.object(psiturk.experiment_server_controller.ExperimentServerController, 'is_port_available', lambda *args, **kwargs: True)

        mocker.patch.object(PsiturkNetworkShell,'get_intro_prompt', lambda *args, **kwargs: '')
        mocker.patch.object(PsiturkNetworkShell,'update_hit_tally', lambda *args, **kwargs: None)
        mocker.patch.object(PsiturkNetworkShell,'_confirm_dialog', lambda *args, **kwargs: True)

        config = PsiturkConfig()
        config.load_config()
        server = control.ExperimentServerController(config)

        launch_in_sandbox_mode = True
        quiet = False
        shell = PsiturkNetworkShell(
            config, server,
            launch_in_sandbox_mode,
            quiet=quiet)
        shell.persistent_history_file = None
        shell.echo = True
        stubber.assert_no_pending_responses()
        return shell
Exemplo n.º 2
0
def test_awscreds_notset_shell(capfd, experiment_server_controller,
                               psiturk_shell):
    from psiturk.psiturk_config import PsiturkConfig
    from psiturk.psiturk_shell import PsiturkNetworkShell
    import psiturk.psiturk_shell as ps
    import psiturk.experiment_server_controller

    config = PsiturkConfig()
    config.load_config()
    config.set('Shell Parameters', 'persistent_history_file', '')
    config.set('AWS Access', 'aws_access_key_id', 'YourAccessKeyId')
    config.set('AWS Access', 'aws_secret_access_key', 'YourSecretAccessKey')

    server = psiturk.experiment_server_controller.ExperimentServerController(
        config)

    launch_in_sandbox_mode = True
    quiet = False
    try:
        shell = PsiturkNetworkShell(config,
                                    server,
                                    launch_in_sandbox_mode,
                                    quiet=quiet)
    except SystemExit:
        pass

    out, err = capfd.readouterr()
    assert AWSAccessKeysNotSetError().message in err
Exemplo n.º 3
0
def test_awskeys_invalid(capfd):
    import psiturk.experiment_server_controller as control
    from psiturk.psiturk_config import PsiturkConfig
    from psiturk.psiturk_shell import PsiturkNetworkShell
    import psiturk.psiturk_shell as ps

    config = PsiturkConfig()
    config.load_config()
    config.set('Shell Parameters', 'persistent_history_file', '')
    config.set('AWS Access', 'aws_access_key_id', '')
    config.set('AWS Access', 'aws_secret_access_key', '')
    server = control.ExperimentServerController(config)

    launch_in_sandbox_mode = True
    quiet = False
    try:
        shell = PsiturkNetworkShell(config,
                                    server,
                                    launch_in_sandbox_mode,
                                    quiet=quiet)
    except SystemExit:
        pass

    out, err = capfd.readouterr()
    assert NoMturkConnectionError().message in out
Exemplo n.º 4
0
    def open_recruitment(self, n=1):
        """Open recruitment for the first HIT, unless it's already open."""
        from psiturk.amt_services import MTurkServices, RDSServices
        from psiturk.psiturk_shell import PsiturkNetworkShell
        from psiturk.psiturk_org_services import PsiturkOrgServices

        psiturk_access_key_id = os.getenv(
            "psiturk_access_key_id",
            self.config.get("psiTurk Access", "psiturk_access_key_id"))

        psiturk_secret_access_id = os.getenv(
            "psiturk_secret_access_id",
            self.config.get("psiTurk Access", "psiturk_secret_access_id"))

        web_services = PsiturkOrgServices(psiturk_access_key_id,
                                          psiturk_secret_access_id)

        aws_rds_services = RDSServices(self.aws_access_key_id,
                                       self.aws_secret_access_key,
                                       self.aws_region)

        self.amt_services = MTurkServices(
            self.aws_access_key_id, self.aws_secret_access_key,
            self.config.getboolean('Shell Parameters',
                                   'launch_in_sandbox_mode'))

        self.shell = PsiturkNetworkShell(
            self.config, self.amt_services, aws_rds_services, web_services,
            self.server,
            self.config.getboolean('Shell Parameters',
                                   'launch_in_sandbox_mode'))

        try:
            participants = Participant.query.all()
            assert (participants)

        except Exception:
            # Create the first HIT.
            self.shell.hit_create(
                n, self.config.get('HIT Configuration', 'base_payment'),
                self.config.get('HIT Configuration', 'duration'))

        else:
            # HIT was already created, no need to recreate it.
            print "Reject recruitment reopening: experiment has started."
Exemplo n.º 5
0
    def open_recruitment(self, n=1):
        """Open recruitment for the first HIT, unless it's already open."""
        from psiturk.amt_services import MTurkServices, RDSServices
        from psiturk.psiturk_shell import PsiturkNetworkShell
        from psiturk.psiturk_org_services import PsiturkOrgServices

        psiturk_access_key_id = os.getenv(
            "psiturk_access_key_id",
            self.config.get("psiTurk Access", "psiturk_access_key_id"))

        psiturk_secret_access_id = os.getenv(
            "psiturk_secret_access_id",
            self.config.get("psiTurk Access", "psiturk_secret_access_id"))

        web_services = PsiturkOrgServices(
            psiturk_access_key_id,
            psiturk_secret_access_id)

        aws_rds_services = RDSServices(
            self.aws_access_key_id,
            self.aws_secret_access_key,
            self.aws_region)

        self.amt_services = MTurkServices(
            self.aws_access_key_id,
            self.aws_secret_access_key,
            self.config.getboolean(
                'Shell Parameters', 'launch_in_sandbox_mode'))

        self.shell = PsiturkNetworkShell(
            self.config, self.amt_services, aws_rds_services, web_services,
            self.server,
            self.config.getboolean(
                'Shell Parameters', 'launch_in_sandbox_mode'))

        try:
            participants = Participant.query.all()
            assert(participants)

        except Exception:
            # Create the first HIT.
            self.shell.hit_create(
                n,
                self.config.get('HIT Configuration', 'base_payment'),
                self.config.get('HIT Configuration', 'duration'))

        else:
            # HIT was already created, no need to recreate it.
            print "Reject recruitment reopening: experiment has started."
Exemplo n.º 6
0
def test_awskeys_invalid_shell(capfd, experiment_server_controller,
                               psiturk_shell):
    """test_awskeys_invalid_shell."""
    import psiturk.experiment_server_controller
    from psiturk.psiturk_config import PsiturkConfig
    from psiturk.psiturk_shell import PsiturkNetworkShell
    config = PsiturkConfig()
    config.load_config()
    config.set('Shell Parameters', 'persistent_history_file', '')

    server = psiturk.experiment_server_controller.ExperimentServerController(
        config)

    quiet = False
    try:
        shell = PsiturkNetworkShell(config,
                                    server,
                                    mode='sandbox',
                                    quiet=quiet)
    except SystemExit:
        pass

    out, err = capfd.readouterr()
    assert NoMturkConnectionError().message in err
Exemplo n.º 7
0
class PsiTurkRecruiter(Recruiter):

    """Recruit participants from Amazon Mechanical Turk."""

    def __init__(self):

        """Set up the connection to MTurk and psiTurk web services."""

        # load the configuration options
        self.config = PsiturkConfig()
        self.config.load_config()

        class FakeExperimentServerController(object):
            def is_server_running(self):
                return "yes"

        self.server = FakeExperimentServerController()

        # Get keys from environment variables or config file.
        self.aws_access_key_id = os.getenv("aws_access_key_id", self.config.get("AWS Access", "aws_access_key_id"))

        self.aws_secret_access_key = os.getenv(
            "aws_secret_access_key", self.config.get("AWS Access", "aws_secret_access_key")
        )

        self.aws_region = os.getenv("aws_region", self.config.get("AWS Access", "aws_region"))

    def open_recruitment(self, n=1):
        """Open recruitment for the first HIT, unless it's already open."""
        from psiturk.amt_services import MTurkServices, RDSServices
        from psiturk.psiturk_shell import PsiturkNetworkShell
        from psiturk.psiturk_org_services import PsiturkOrgServices

        psiturk_access_key_id = os.getenv(
            "psiturk_access_key_id", self.config.get("psiTurk Access", "psiturk_access_key_id")
        )

        psiturk_secret_access_id = os.getenv(
            "psiturk_secret_access_id", self.config.get("psiTurk Access", "psiturk_secret_access_id")
        )

        web_services = PsiturkOrgServices(psiturk_access_key_id, psiturk_secret_access_id)

        aws_rds_services = RDSServices(self.aws_access_key_id, self.aws_secret_access_key, self.aws_region)

        self.amt_services = MTurkServices(
            self.aws_access_key_id,
            self.aws_secret_access_key,
            self.config.getboolean("Shell Parameters", "launch_in_sandbox_mode"),
        )

        self.shell = PsiturkNetworkShell(
            self.config,
            self.amt_services,
            aws_rds_services,
            web_services,
            self.server,
            self.config.getboolean("Shell Parameters", "launch_in_sandbox_mode"),
        )

        try:
            participants = Participant.query.all()
            assert participants

        except Exception:
            # Create the first HIT.
            self.shell.hit_create(
                n,
                self.config.get("HIT Configuration", "base_payment"),
                self.config.get("HIT Configuration", "duration"),
            )

        else:
            # HIT was already created, no need to recreate it.
            print "Reject recruitment reopening: experiment has started."

    def recruit_participants(self, n=1):
        """Extend the HIT to recruit more people."""
        auto_recruit = os.environ["auto_recruit"] == "true"

        if auto_recruit:

            print "Starting Wallace's recruit_participants."

            hit_id = str(Participant.query.with_entities(Participant.hitid).first().hitid)

            print "hit_id is {}.".format(hit_id)

            is_sandbox = self.config.getboolean("Shell Parameters", "launch_in_sandbox_mode")

            if is_sandbox:
                host = "mechanicalturk.sandbox.amazonaws.com"
            else:
                host = "mechanicalturk.amazonaws.com"

            mturkparams = dict(
                aws_access_key_id=self.aws_access_key_id, aws_secret_access_key=self.aws_secret_access_key, host=host
            )

            self.mtc = MTurkConnection(**mturkparams)

            self.mtc.extend_hit(hit_id, assignments_increment=int(n or 0))

            expiration_increment = self.config.get("HIT Configuration", "duration")

            self.mtc.extend_hit(hit_id, expiration_increment=int(float(expiration_increment or 0) * 3600))
        else:
            print (">>>> auto_recruit set to {}: recruitment suppressed".format(auto_recruit))

    def approve_hit(self, assignment_id):
        """Approve the HIT."""
        from psiturk.amt_services import MTurkServices

        self.amt_services = MTurkServices(
            self.aws_access_key_id,
            self.aws_secret_access_key,
            self.config.getboolean("Shell Parameters", "launch_in_sandbox_mode"),
        )
        return self.amt_services.approve_worker(assignment_id)

    def reward_bonus(self, assignment_id, amount, reason):
        """Reward the Turker with a bonus."""
        from psiturk.amt_services import MTurkServices

        self.amt_services = MTurkServices(
            self.aws_access_key_id,
            self.aws_secret_access_key,
            self.config.getboolean("Shell Parameters", "launch_in_sandbox_mode"),
        )
        return self.amt_services.bonus_worker(assignment_id, amount, reason)

    def close_recruitment(self):
        """Close recruitment."""
        pass
Exemplo n.º 8
0
class PsiTurkRecruiter(Recruiter):
    """Recruit participants from Amazon Mechanical Turk via PsiTurk."""
    def __init__(self):
        """Set up the connection to MTurk and psiTurk web services."""
        # load the configuration options
        self.config = PsiturkConfig()
        self.config.load_config()

        class FakeExperimentServerController(object):
            def is_server_running(self):
                return 'yes'

        self.server = FakeExperimentServerController()

        # Get keys from environment variables or config file.
        self.aws_access_key_id = os.getenv(
            "aws_access_key_id",
            self.config.get("AWS Access", "aws_access_key_id"))

        self.aws_secret_access_key = os.getenv(
            "aws_secret_access_key",
            self.config.get("AWS Access", "aws_secret_access_key"))

        self.aws_region = os.getenv(
            "aws_region", self.config.get("AWS Access", "aws_region"))

    def open_recruitment(self, n=1):
        """Open recruitment for the first HIT, unless it's already open."""
        from psiturk.amt_services import MTurkServices, RDSServices
        from psiturk.psiturk_shell import PsiturkNetworkShell
        from psiturk.psiturk_org_services import PsiturkOrgServices

        psiturk_access_key_id = os.getenv(
            "psiturk_access_key_id",
            self.config.get("psiTurk Access", "psiturk_access_key_id"))

        psiturk_secret_access_id = os.getenv(
            "psiturk_secret_access_id",
            self.config.get("psiTurk Access", "psiturk_secret_access_id"))

        web_services = PsiturkOrgServices(psiturk_access_key_id,
                                          psiturk_secret_access_id)

        aws_rds_services = RDSServices(self.aws_access_key_id,
                                       self.aws_secret_access_key,
                                       self.aws_region)

        self.amt_services = MTurkServices(
            self.aws_access_key_id, self.aws_secret_access_key,
            self.config.getboolean('Shell Parameters',
                                   'launch_in_sandbox_mode'))

        self.shell = PsiturkNetworkShell(
            self.config, self.amt_services, aws_rds_services, web_services,
            self.server,
            self.config.getboolean('Shell Parameters',
                                   'launch_in_sandbox_mode'))

        try:
            participants = Participant.query.all()
            assert (participants)

        except Exception:
            # Create the first HIT.
            self.shell.hit_create(
                n, self.config.get('HIT Configuration', 'base_payment'),
                self.config.get('HIT Configuration', 'duration'))

        else:
            # HIT was already created, no need to recreate it.
            print "Reject recruitment reopening: experiment has started."

    def recruit_participants(self, n=1):
        """Recruit n participants."""
        auto_recruit = os.environ['auto_recruit'] == 'true'

        if auto_recruit:

            print "Starting Dallinger's recruit_participants."

            hit_id = str(
                Participant.query.with_entities(
                    Participant.hitid).first().hitid)

            print "hit_id is {}.".format(hit_id)

            is_sandbox = self.config.getboolean('Shell Parameters',
                                                'launch_in_sandbox_mode')

            if is_sandbox:
                host = 'mechanicalturk.sandbox.amazonaws.com'
            else:
                host = 'mechanicalturk.amazonaws.com'

            mturkparams = dict(
                aws_access_key_id=self.aws_access_key_id,
                aws_secret_access_key=self.aws_secret_access_key,
                host=host)

            self.mtc = MTurkConnection(**mturkparams)

            self.mtc.extend_hit(hit_id, assignments_increment=int(n or 0))

            expiration_increment = self.config.get('HIT Configuration',
                                                   'duration')

            self.mtc.extend_hit(hit_id,
                                expiration_increment=int(
                                    float(expiration_increment or 0) * 3600))
        else:
            print(">>>> auto_recruit set to {}: recruitment suppressed".format(
                auto_recruit))

    def approve_hit(self, assignment_id):
        """Approve the HIT."""
        from psiturk.amt_services import MTurkServices

        self.amt_services = MTurkServices(
            self.aws_access_key_id, self.aws_secret_access_key,
            self.config.getboolean('Shell Parameters',
                                   'launch_in_sandbox_mode'))
        return self.amt_services.approve_worker(assignment_id)

    def reward_bonus(self, assignment_id, amount, reason):
        """Reward the Turker with a bonus."""
        from psiturk.amt_services import MTurkServices

        self.amt_services = MTurkServices(
            self.aws_access_key_id, self.aws_secret_access_key,
            self.config.getboolean('Shell Parameters',
                                   'launch_in_sandbox_mode'))
        return self.amt_services.bonus_worker(assignment_id, amount, reason)

    def close_recruitment(self):
        """Close recruitment."""
        pass
Exemplo n.º 9
0
import psiturk.experiment_server_controller as control
from psiturk.psiturk_config import PsiturkConfig
from psiturk.psiturk_shell import PsiturkNetworkShell


try:

    config = PsiturkConfig()
    config.load_config()
    server = control.ExperimentServerController(config)

    launch_in_sandbox_mode = True
    quiet = False

    shell = PsiturkNetworkShell(
        config, server,
        launch_in_sandbox_mode,
        quiet=quiet)
        
    shell.persistent_history_file = None

    # #########################
    # all `do_` commands:
    # #################
    # [] def do_psiturk_status
    # [] def do_debug
    # [] def do_version
    # [] def do_dev

    # def do_config(self, arg):
    #    """
    #    Usage: