コード例 #1
0
ファイル: test_mturk.py プロジェクト: mt-digital/Dallinger
 def test_create_compensation_hit(self, with_cleanup):
     # In practice, this would include a qualification assigned to a
     # single worker.
     hit = with_cleanup.create_hit(
         **standard_hit_config(
             title="Compensation Immediate",
             question=MTurkQuestions.compensation(sandbox=True),
         )
     )
     assert hit["status"] == "Assignable"
     assert hit["max_assignments"] == 1
コード例 #2
0
ファイル: recruiters.py プロジェクト: willschulz/Dallinger
    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
        }