示例#1
0
 def create_html_hit(self, params):
     """
     creates a HIT for a question with the specified HTML
     :param params a dict of the HIT parameters, must contain a "html" parameter
     :return the created HIT object
     """
     question = HTMLQuestion(params["html"], params["frame_height"])
     return self._create_hit(params, question=question)
    def create_hits(self, category_id, task_id, num_hits):

        print "Connecting to Turk host at"
        print app.config['MTURK_HOST']
        sys.stdout.flush()

        mturk = MTurkConnection(app.config['AWS_ACCESS_KEY_ID'],
                                app.config['AWS_SECRET_ACCESS_KEY'],
                                host=app.config['MTURK_HOST'])

        print "Uploading %d hits to turk" % num_hits
        hits = []
        qualifications = app.config['QUALIFICATIONS']

        for hit_num in range(num_hits):

            category = app.config['EXAMPLE_CATEGORIES'][category_id]
            hit_html = category['hit_html']
            hit_html = hit_html.replace('${task_id}', task_id)
            hit_html = hit_html.replace('${requester_id}',
                                        app.config['CROWDJS_REQUESTER_ID'])
            hit_html = hit_html.replace(
                '${task_data_url}', app.config['CROWDJS_GET_TASK_DATA_URL'])
            hit_html = hit_html.replace(
                '${submit_answer_url}',
                app.config['CROWDJS_SUBMIT_ANSWER_URL'])
            hit_html = hit_html.replace('${compute_taboo_url}',
                                        app.config['SUBMIT_TABOO_URL'])
            hit_html = hit_html.replace('${return_hit_url}',
                                        app.config['CROWDJS_RETURN_HIT_URL'])
            hit_html = hit_html.replace('${assign_url}',
                                        app.config['CROWDJS_ASSIGN_URL'])
            hit_html = hit_html.replace('${taboo_threshold}',
                                        str(app.config['TABOO_THRESHOLD']))
            hit_html = hit_html.replace(
                '${mturk_external_submit}',
                str(app.config['MTURK_EXTERNAL_SUBMIT']))

            question = HTMLQuestion(hit_html, 800)
            hit = mturk.create_hit(
                title=category['task_name'],
                description=category['task_description'],
                question=question,
                reward=Price(category['price']),
                duration=datetime.timedelta(minutes=10),
                lifetime=datetime.timedelta(days=7),
                keywords=
                'information extraction, events, natural language processing',
                max_assignments=1,
                approval_delay=3600,
                qualifications=qualifications)[0]

            hits.append(hit.HITId)

        return hits
示例#3
0
def launch_hit(conn, hit_type_id: str, config: dict, html: str) -> dict:
    """
    Launch a HIT using the configuration in `config` with contents `html`.

    Args:
        conn: A MTurk client connection
        hit_type_id: The HITTypeId returned by `setup_hit_type`. This ID
                     defines all the shared properties of tasks in this
                     HIT like their reward, and approval policy.
        config: The task configuration from ``task.yaml``.
        html: The HTML that will be rendered as part of this task.

    Returns:
        A dictionary describing the HIT.
    """
    response = conn.create_hit_with_hit_type(
        HITTypeId=hit_type_id,
        MaxAssignments=config['MaxAssignments'],
        LifetimeInSeconds=config.get("LifetimeInSeconds",
                                     60 * 60 * 24 * 10),  # 10 days is default.
        Question=HTMLQuestion(html, config.get("FrameHeight",
                                               1000)).get_as_xml(),
    )

    return {
        "HITId":
        response["HIT"]["HITId"],
        "HITTypeId":
        response["HIT"]["HITTypeId"],
        "CreationTime":
        "{:%Y%m%d %H:%M}".format(response["HIT"]["CreationTime"]),
        "HITStatus":
        response["HIT"]["HITStatus"],
        "MaxAssignments":
        response["HIT"]["MaxAssignments"],
        "NumberOfAssignmentsPending":
        response["HIT"]["NumberOfAssignmentsPending"],
        "NumberOfAssignmentsAvailable":
        response["HIT"]["NumberOfAssignmentsAvailable"],
        "NumberOfAssignmentsCompleted":
        response["HIT"]["NumberOfAssignmentsCompleted"],
        "NumberOfAssignmentsApproved":
        0,
        "NumberOfAssignmentsRejected":
        0,
    }
示例#4
0
    def html_question(self, data):
        receivers = []
        for r in ['To', 'Cc', 'Bcc']:
            try:
                res = data[r]
                receivers.extend(res)
            except KeyError:
                continue
        if len(receivers) > 15:
            raise ReceiversTooMuch
        data['receivers'] = receivers
        question_html_value = self.render('question_tpl.html', data)

        # The first parameter is the HTML content
        # The second is the height of the frame it will be shown in
        # Check out the documentation on HTMLQuestion for more details
        return HTMLQuestion(question_html_value, 500)
示例#5
0
def create_mtc_question(mtc,
                        exampleset,
                        duration=datetime.timedelta(0, 1500),
                        reward=0.5,
                        max_assignments=3,
                        title='Help recommend a restaurant to a friend.',
                        redo=False):

    if not redo and hasattr(exampleset, "HITId"):
        warn("ExampleSet was already submitted")
        return None
    else:
        description = (
            'Read short snippets about places someone liked'
            '  or disliked, and choose among a list which corresponds best')
        keywords = 'rating, opinions, recommendation'
        url = "https://workersandbox.mturk.com/mturk/externalSubmit" if (
            "sandbox"
            in mtc.host) else "https://www.mturk.com/mturk/externalSubmit"
        form = open("mturk/form.html").read().format(
            style_code=open("mturk/form.css").read(),
            javascript=open("mturk/form.js").read(),
            difficulty=exampleset.difficulty,
            url=url,
            input_restaurants=convert_to_input_list(
                exampleset.example_names()),
            restaurant_options=convert_to_select_options(
                exampleset.option_names()),
            personality_type=exampleset.personality_type,
            examples="".join(exampleset.get_examples_html()),
            options="".join(exampleset.get_options_html()))
        qc1 = HTMLQuestion(html_form=form, frame_height=4500)

        hit = mtc.create_hit(question=qc1,
                             max_assignments=max_assignments,
                             title=title,
                             description=description,
                             keywords=keywords,
                             duration=duration,
                             reward=reward)
        if not hasattr(exampleset, "HITId"):
            exampleset.HITId = []
        else:
            exampleset.HITId.append(hit[0].HITId)
        return hit
示例#6
0
 def create_questions(self, questions):
     hit_questions = []
     question_data = []
     for question_group in questions:
         html_questions = self.create_question_group(question_group)
         html_hit = self.overall_template.format(
             title=self.title,
             instructions=self.create_instructions(len(question_group)),
             script=self.script,
             questions=html_questions,
         )
         #with open('/afs/cs.stanford.edu/u/hehe/www/question.html', 'w') as fout:
         #    fout.write(html_hit)
         #    import sys; sys.exit()
         html_hit = HTMLQuestion(html_hit, 600)
         hit_questions.append(html_hit)
         question_data.append(self.json_question_data(question_group))
     return hit_questions, question_data
示例#7
0
    if args.hit_ids_file is None:
        print 'Need to input a hit_ids_file'
        sys.exit()
    if os.path.isfile(args.hit_ids_file):
        print 'hit_ids_file already exists'
        sys.exit()

    with open(args.hit_ids_file, 'w') as hit_ids_file:
        for i, line in enumerate(args.input_json_file):
            hit_input = json.loads(line.strip())

            # In a previous version I removed all single quotes from the json dump.
            # TODO: double check to see if this is still necessary.
            template_params = {'input': json.dumps(hit_input)}
            html = template.render(template_params)
            html_question = HTMLQuestion(html, frame_height)
            hit_properties['question'] = html_question

            # This error handling is kinda hacky.
            # TODO: Do something better here.
            launched = False
            while not launched:
                try:
                    boto_hit = mtc.create_hit(**hit_properties)
                    launched = True
                except MTurkRequestError as e:
                    print e
            hit_id = boto_hit[0].HITId
            hit_ids_file.write('%s\n' % hit_id)
            print 'Launched HIT ID: %s, %d' % (hit_id, i + 1)
示例#8
0
<!-- This is where you define your question(s) --> 
<h1>Please name the company that created the iPhone</h1>
<p><textarea name='answer' rows=3 cols=80></textarea></p>

<!-- HTML to handle submitting the HIT -->
<p><input type='submit' id='submitButton' value='Submit' /></p></form>
<script language='Javascript'>turkSetAssignmentID();</script>
</body>
</html>
"""

# The first parameter is the HTML content
# The second is the height of the frame it will be shown in
# Check out the documentation on HTMLQuestion for more details
html_question = HTMLQuestion(question_html_value, 500)

# These parameters define the HIT that will be created
# question is what we defined above
# max_assignments is the # of unique Workers you're requesting
# title, description, and keywords help Workers find your HIT
# duration is the # of seconds Workers have to complete your HIT
# reward is what Workers will be paid when you approve their work
# Check out the documentation on CreateHIT for more details
response = mtc.create_hit(question=html_question,
                          max_assignments=1,
                          title="Answer a simple question",
                          description="Help research a topic",
                          keywords="question, answer, research",
                          duration=120,
                          reward=0.50)
示例#9
0
    def make_html_transcription_HIT(self,
                                    audio_clip_urls,
                                    hit_title,
                                    question_title,
                                    description,
                                    keywords,
                                    duration=DEFAULT_DURATION,
                                    reward_per_clip=DEFAULT_REWARD,
                                    max_assignments=DEFAULT_MAX_ASSIGNMENTS):
        overview = Overview()
        overview.append_field(
            "Title", "Type the words in the following audio clip in order.")

        descriptions = [
            "The following audio clips are in English.",
            "Transcribe the audio clip by typing the words that the person \
                        says in order.",
            "Do not use abbreviations: 'street' and NOT 'st.'",
            "Write numbers long-form, as in: 'twenty fifth' NOT '25th'.",
            "Write letters (see example).", "Punctuation does not matter.",
            "Hotkeys: press Tab to play the next clip."
        ]

        keywords = "audio, transcription, English"
        html_head = self.transcription_head.replace(self.html_tags["title"],
                                                    hit_title)
        for description in descriptions:
            html_head = html_head.replace(
                self.html_tags["description"], "<li>" + description +
                "</li>\n" + self.html_tags["description"])
        count = 0
        questions = []
        inputs = []
        for acurl, acid in audio_clip_urls:
            input_id = str(acid)
            question = self.transcription_question.replace(
                self.html_tags["audio_url"], acurl)
            question = question.replace(self.html_tags["audioclip_id"],
                                        str(acid))
            question = question.replace("${count}", input_id)
            count += 1
            questions.append(question)
            inputs.append(input_id)

        for input_id in inputs:
            script = self.disable_input_script.replace("${input_id}", input_id)
            html_head = html_head.replace(self.html_tags["disable_script"],script+\
                                          "\n"+self.html_tags["disable_script"])
            if (self.html_tags["audio_id"]) in html_head:
                html_head = html_head.replace(self.html_tags["audio_id"],"'"+\
                                              input_id+"'"+","+self.html_tags["audio_id"])

        html_head = html_head.replace(self.html_tags["disable_script"], "")
        html_head = html_head.replace("," + self.html_tags["audio_id"], "")
        html_head = html_head.replace(self.html_tags["description"], "")
        html = html_head

        for question in questions:
            html += question
            count += 1

        html += self.transcription_tail
        html_question = HTMLQuestion(html, 800)

        #reward calculation
        reward = reward_per_clip * len(audio_clip_urls)
        try:
            return self.conn.create_hit(title=hit_title,
                                        question=html_question,
                                        max_assignments=max_assignments,
                                        description=description,
                                        keywords=keywords,
                                        duration=duration,
                                        reward=reward)
        except MTurkRequestError as e:
            if e.reason != "OK":
                raise
            else:
                print(e)
                return False
        return False
示例#10
0
    def make_html_elicitation_HIT(self,
                                  prompt_list,
                                  hit_title,
                                  prompt_title,
                                  keywords,
                                  hit_description,
                                  duration=DEFAULT_DURATION,
                                  reward_per_clip=DEFAULT_REWARD,
                                  max_assignments=DEFAULT_MAX_ASSIGNMENTS):
        overview = Overview()
        overview.append_field(
            "Title", "Record yourself speaking the words in the prompt.")
        descriptions = [
            "The following prompts are in English.",
            "Click the prompt to record your voice (Redirects to recording Page).",
            "Follow the directions on that page.",
            "Copy and paste the URL in box below the prompt on this page."
        ]
        keywords = "audio, recording, elicitation, English"

        html_head = self.elicitation_head.replace(self.html_tags["title"],
                                                  hit_title)
        for description in descriptions:
            html_head = html_head.replace(
                self.html_tags["description"], "<li>" + description +
                "</li>\n" + self.html_tags["description"])
        questions_html = []
        prompt_ids = []

        for prompt_words, prompt_id in prompt_list:
            #For each prompt, generate the question html given the template
            prompt_id = str(prompt_id)
            prompt = " ".join(prompt_words)
            underscored_prompt = "_".join(prompt_words)
            question = self.elicitation_question.replace(
                self.html_tags["prompt"], prompt)
            question = question.replace(self.html_tags["underscored_prompt"],
                                        underscored_prompt)
            question = question.replace(self.html_tags["prompt_id"],
                                        str(prompt_id))
            questions_html.append(question)
            prompt_ids.append(prompt_id)

        for prompt_id in prompt_ids:
            #Disable the inputs for the prompts, which are just text fields for the
            #audio recording URLs
            script = self.disable_input_script.replace("${input_id}",
                                                       prompt_id)
            html_head = html_head.replace(self.html_tags["disable_script"],script+\
                                          "\n"+self.html_tags["disable_script"])
            if (self.html_tags["prompt_id"]) in html_head:
                html_head = html_head.replace(self.html_tags["prompt_id"],"'"+prompt_id+"'"+\
                                              ","+self.html_tags["prompt_id"])
        #Get rid of html tags
        html_head = html_head.replace(self.html_tags["disable_script"], "")
        html_head = html_head.replace("," + self.html_tags["prompt_id"], "")
        html_head = html_head.replace(self.html_tags["description"], "")
        html = html_head

        for question in questions_html:
            html += question

        html += self.transcription_tail
        html_question = HTMLQuestion(html, 800)
        open("/home/taylor/csaesr/tmp/hithtml.html", "w").write(html)

        #reward calculation

        quals = qualification.Qualifications()
        quals.add(qualification.LocaleRequirement("EqualTo", "US"))
        reward = reward_per_clip * len(prompt_list)
        try:
            return self.conn.create_hit(title=hit_title,
                                        question=html_question,
                                        max_assignments=max_assignments,
                                        description=hit_description,
                                        qualifications=quals,
                                        keywords=keywords,
                                        duration=duration,
                                        reward=reward)
        except MTurkRequestError as e:
            if e.reason != "OK":
                raise
            else:
                print(e)
                return False
        return False