예제 #1
0
    def recruit(self, n=1):
        """Recruit n new participant bots to the queue"""
        logger.info("Recruiting {} Bot participants".format(n))
        factory = self._get_bot_factory()
        urls = []
        q = _get_queue(name="low")
        for _ in range(n):
            base_url = get_base_url()
            worker = generate_random_id()
            hit = generate_random_id()
            assignment = generate_random_id()
            ad_parameters = (
                "recruiter={}&assignmentId={}&hitId={}&workerId={}&mode=sandbox"
            )
            ad_parameters = ad_parameters.format(self.nickname, assignment,
                                                 hit, worker)
            url = "{}/ad?{}".format(base_url, ad_parameters)
            urls.append(url)
            bot = factory(url,
                          assignment_id=assignment,
                          worker_id=worker,
                          hit_id=hit)
            job = q.enqueue(bot.run_experiment, job_timeout=self._timeout)
            logger.warning("Created job {} for url {}.".format(job.id, url))

        return urls
예제 #2
0
파일: recruiters.py 프로젝트: fhk/Dallinger
 def recruit_participants(self, n=1):
     """Talk about recruiting participants."""
     for i in range(n):
         ad_url = "{}/ad?assignmentId=debug{}&hitId={}&workerId={}&mode=debug".format(
             get_base_url(),
             generate_random_id(),
             generate_random_id(),
             generate_random_id(),
         )
         logger.info('New participant requested: {}'.format(ad_url))
예제 #3
0
    def recruit(self, n=1):
        """Generate experiemnt URLs and print them to the console."""
        urls = []
        template = "{}/ad?recruiter={}&assignmentId={}&hitId={}&workerId={}&mode={}"
        for i in range(n):
            ad_url = template.format(get_base_url(), self.nickname,
                                     generate_random_id(),
                                     generate_random_id(),
                                     generate_random_id(), self._get_mode())
            logger.info('{} {}'.format(NEW_RECRUIT_LOG_PREFIX, ad_url))
            urls.append(ad_url)

        return urls
예제 #4
0
 def test_user_s3_bucket_thrice(self):
     conn = dallinger.data._s3_connection()
     id = generate_random_id()
     for i in range(3):
         bucket = dallinger.data.user_s3_bucket(canonical_user_id=id, )
         assert bucket
     conn.delete_bucket(bucket)
예제 #5
0
 def test_user_s3_bucket_thrice(self):
     id = generate_random_id()
     for i in range(3):
         bucket = dallinger.data.user_s3_bucket(
             canonical_user_id=id,
         )
         assert bucket
     bucket.delete()
예제 #6
0
 def _make_qtype(self, mturk):
     qtype = mturk.create_qualification_type(
         name=generate_random_id(size=32),
         description=TEST_QUALIFICATION_DESCRIPTION,
         status='Active',
     )
     self._qtypes_to_purge.append(qtype['id'])
     return qtype
예제 #7
0
    def test_create_and_dispose_qualification_type(self, with_cleanup):
        result = with_cleanup.create_qualification_type(
            name=generate_random_id(size=32),
            description=TEST_QUALIFICATION_DESCRIPTION,
            status='Active',
        )

        assert isinstance(result['id'], unicode)
        assert result['status'] == u'Active'
        assert with_cleanup.dispose_qualification_type(result['id'])
예제 #8
0
    def recruit(self, n=1):
        """Recruit n new participant bots to the queue"""
        factory = self._get_bot_factory()
        urls = []
        q = _get_queue()
        for _ in range(n):
            base_url = get_base_url()
            worker = generate_random_id()
            hit = generate_random_id()
            assignment = generate_random_id()
            ad_parameters = 'assignmentId={}&hitId={}&workerId={}&mode=sandbox'
            ad_parameters = ad_parameters.format(assignment, hit, worker)
            url = '{}/ad?{}'.format(base_url, ad_parameters)
            urls.append(url)
            bot = factory(url, assignment_id=assignment, worker_id=worker)
            job = q.enqueue(bot.run_experiment, timeout=60 * 20)
            logger.info("Created job {} for url {}.".format(job.id, url))

        return urls
예제 #9
0
    def test_create_and_dispose_qualification_type(self, with_cleanup):
        result = with_cleanup.create_qualification_type(
            name=generate_random_id(size=32),
            description=TEST_QUALIFICATION_DESCRIPTION,
            status="Active",
        )

        assert isinstance(result["id"], six.text_type)
        assert result["status"] == u"Active"
        assert with_cleanup.dispose_qualification_type(result["id"])
예제 #10
0
def bot(app, debug):
    """Run the experiment bot."""
    if debug is None:
        verify_id(None, None, app)

    (id, tmp) = setup_experiment()

    if debug:
        url = debug
    else:
        heroku_app = HerokuApp(dallinger_uid=app)
        worker = generate_random_id()
        hit = generate_random_id()
        assignment = generate_random_id()
        ad_url = '{}/ad'.format(heroku_app.url)
        ad_parameters = 'assignmentId={}&hitId={}&workerId={}&mode=sandbox'
        ad_parameters = ad_parameters.format(assignment, hit, worker)
        url = '{}?{}'.format(ad_url, ad_parameters)
    bot = bot_factory(url)
    bot.run_experiment()
예제 #11
0
    def compensate_worker(self, worker_id, email, dollars, notify=True):
        """Pay a worker by means of a special HIT that only they can see.
        """
        qualification = self.mturkservice.create_qualification_type(
            name="Dallinger Compensation Qualification - {}".format(
                generate_random_id()),
            description=(
                "You have received a qualification to allow you to complete a "
                "compensation HIT from Dallinger for ${}.".format(dollars)),
        )
        qid = qualification["id"]
        self.mturkservice.assign_qualification(qid,
                                               worker_id,
                                               1,
                                               notify=notify)
        hit_request = {
            "experiment_id": "(compensation only)",
            "max_assignments": 1,
            "title": "Dallinger Compensation HIT",
            "description": "For compenation only; no task required.",
            "keywords": [],
            "reward": float(dollars),
            "duration_hours": 1,
            "lifetime_days": 3,
            "question": MTurkQuestions.compensation(sandbox=self.is_sandbox),
            "qualifications": [MTurkQualificationRequirements.must_have(qid)],
            "do_subscribe": False,
        }
        hit_info = self.mturkservice.create_hit(**hit_request)
        if email is not None:
            message = {
                "subject":
                "Dallinger Compensation HIT",
                "sender":
                self.config.get("dallinger_email_address"),
                "recipients": [email],
                "body":
                ("A special compenstation HIT is available for you to complete on MTurk.\n\n"
                 "Title: {title}\n"
                 "Reward: ${reward:.2f}\n"
                 "URL: {worker_url}").format(**hit_info),
            }

            self.mailer.send(**message)
        else:
            message = {}

        return {
            "hit": hit_info,
            "qualification": qualification,
            "email": message
        }
예제 #12
0
def fake_worker_qualification_response():
    canned_response = {
        u'Qualification': {
            u'GrantTime': datetime.datetime(2018, 1, 1),
            u'IntegerValue': 2,
            u'QualificationTypeId': six.text_type(generate_random_id(size=32)),
            u'Status': u'Granted',
            u'WorkerId': u'FAKE_WORKER_ID'
        },
        'ResponseMetadata': response_metadata()['ResponseMetadata']
    }

    return canned_response
예제 #13
0
def fake_qualification_type_response():
    canned_response = {
        u"QualificationType": {
            u"AutoGranted": False,
            u"CreationTime": datetime.datetime(2018, 1, 1),
            u"Description": u"***TEST SUITE QUALIFICATION***",
            u"IsRequestable": True,
            u"Name": u"Test Qualification",
            u"QualificationTypeId": generate_random_id(size=32),
            u"QualificationTypeStatus": u"Active",
        }
    }
    return canned_response
예제 #14
0
def fake_worker_qualification_response():
    canned_response = {
        u"Qualification": {
            u"GrantTime": datetime.datetime(2018, 1, 1),
            u"IntegerValue": 2,
            u"QualificationTypeId": six.text_type(generate_random_id(size=32)),
            u"Status": u"Granted",
            u"WorkerId": u"FAKE_WORKER_ID",
        },
        "ResponseMetadata": response_metadata()["ResponseMetadata"],
    }

    return canned_response
예제 #15
0
def fake_qualification_type_response():
    canned_response = {
        u'QualificationType': {
            u'AutoGranted': False,
            u'CreationTime': datetime.datetime(2018, 1, 1),
            u'Description': u'***TEST SUITE QUALIFICATION***',
            u'IsRequestable': True,
            u'Name': u'Test Qualification',
            u'QualificationTypeId': generate_random_id(size=32),
            u'QualificationTypeStatus': u'Active',
        }
    }
    return canned_response
예제 #16
0
def fake_qualification_response():
    canned_response = {
        'Status': u'Granted',
        'QualificationTypeId': generate_random_id(size=32),
        'SubjectId': u'A2ZTO3X61UKR1G',
        'Qualification': '',
        'GrantTime': u'2017-02-02T13:06:13.000-08:00',
        'IntegerValue': u'2'
    }
    qtype = Qualification(None)
    for k, v in canned_response.items():
        qtype.endElement(k, v, None)

    return as_resultset(qtype)
예제 #17
0
def fake_qualification_type_response():
    canned_response = {
        'AutoGranted': u'0',
        'QualificationType': '',
        'Description': u'***TEST SUITE QUALIFICATION***',
        'QualificationTypeId': generate_random_id(size=32),
        'IsValid': u'True',
        'Request': '',
        'QualificationTypeStatus': u'Active',
        'CreationTime': u'2017-02-02T17:36:03Z',
        'Name': u'Test Qualifiction'
    }

    qtype = QualificationType(None)
    for k, v in canned_response.items():
        qtype.endElement(k, v, None)

    return as_resultset(qtype)
예제 #18
0
 def test_user_s3_bucket_first_time(self):
     bucket = dallinger.data.user_s3_bucket(
         canonical_user_id=generate_random_id())
     assert bucket
     bucket.delete()
예제 #19
0
def fake_hit_type_response():
    return {
        u"HITTypeId": six.text_type(generate_random_id(size=32)),
        "ResponseMetadata": response_metadata()["ResponseMetadata"],
    }
예제 #20
0
def name_with_hostname_prefix():
    # Including the hostname in content created in the MTurk sandbox helps
    # identify its source when reviewing records there.
    hostname = socket.gethostname()
    name = "{}:{}".format(hostname, generate_random_id(size=32))
    return name
예제 #21
0
def fake_hit_type_response():
    return {
        u'HITTypeId': six.text_type(generate_random_id(size=32)),
        'ResponseMetadata': response_metadata()['ResponseMetadata']
    }
예제 #22
0
def name_with_hostname_prefix():
    hostname = socket.gethostname()
    name = "{}:{}".format(hostname, generate_random_id(size=32))
    return name
예제 #23
0
 def test_user_s3_bucket_first_time(self):
     conn = dallinger.data._s3_connection()
     bucket = dallinger.data.user_s3_bucket(
         canonical_user_id=generate_random_id(), )
     assert bucket
     conn.delete_bucket(bucket)