def grant_bonuses():
    reader = csv.reader(results_file)
    header = reader.next()
    response_col = header.index('Answer.surveycode')
    feedback_col = header.index('Answer.feedback')
    hit_col = header.index('AssignmentId')
    worker_col = header.index('WorkerId')
    total_bonus = 0.

    for row in reader:
        response = row[response_col]
        hit_id = row[hit_col]
        worker_id = row[worker_col]
        feedback = row[feedback_col]
        if response.startswith("I") or response.startswith("C"):
            response = "MTURK_TASK_" + response
        if response == "{}":
            print "Empty response; feedback: {:s}".format(feedback)
            if feedback != "{}" and "MTURK_TASK_" not in feedback:
                total_bonus += 0.25
                print "Based on feedback: Granting bonus 0.25 to worker {:s}".format(
                    worker_id)
                if not debug:
                    mturk_connection.grant_bonus(
                        worker_id,
                        hit_id,
                        Price(amount=0.25),
                        reason=
                        'For the trouble you experienced with our negotiation platform'
                    )
            elif "MTURK_TASK_" in feedback:
                print "Survey code was entered in feedback? {:s} Trying..".format(
                    feedback)
                response = feedback
        if response not in mturk_codes.keys():
            print "No userid associated with code {:s}".format(response)
            continue
        uid = mturk_codes[response]
        if uid not in bonuses.keys():
            print "No chats for user {:s} with code {:s}".format(uid, response)
            continue

        bonus = bonuses[uid]
        if bonus > 0.:
            total_bonus += bonus
            print "Granting bonus {:.2f} to worker {:s}".format(
                bonus, worker_id)
            if not debug:
                mturk_connection.grant_bonus(
                    worker_id,
                    hit_id,
                    Price(amount=bonus),
                    reason=
                    'For having to spend extra time on our negotiation platform'
                )

    print "Total bonus awarded: {:.2f}".format(total_bonus)
Beispiel #2
0
    def create_hit_type(self, owner_id, title, description, price, duration, boomerang_threshold, keywords=None,
                        approval_delay=None, qual_req=None,
                        qualifications_mask=0, boomerang_qual=None):
        hit_type = MTurkHITType.objects.filter(owner_id=owner_id, name=title, description=description,
                                               price=Decimal(str(price)),
                                               duration=duration,
                                               qualifications_mask=qualifications_mask,
                                               boomerang_threshold=boomerang_threshold).first()
        if hit_type is not None:
            return hit_type, True

        reward = Price(price)
        try:
            mturk_ht = self.connection.register_hit_type(title=title, description=description, reward=reward,
                                                         duration=duration, keywords=keywords,
                                                         approval_delay=approval_delay,
                                                         qual_req=qual_req)[0]
            hit_type = MTurkHITType(owner_id=owner_id, name=title, description=description,
                                    price=Decimal(str(price)),
                                    keywords=keywords, duration=duration,
                                    qualifications_mask=qualifications_mask,
                                    boomerang_qualification=boomerang_qual,
                                    boomerang_threshold=boomerang_threshold)
            hit_type.string_id = mturk_ht.HITTypeId
            hit_type.save()
        except MTurkRequestError:
            return None, False
        return hit_type, True
Beispiel #3
0
def main():
    # parse arguments
    parser = argparse.ArgumentParser()
    parser.add_argument('keys_file')
    parser.add_argument('--production', default=False, action='store_true')
    args = parser.parse_args()

    # read keys
    access_key_id, secret_key = None, None

    with open(args.keys_file, 'r') as keys:
        for line in keys.xreadlines():
            items = [xx.strip() for xx in line.split('=')]
            if items[0] == 'AWSAccessKeyId':
                access_key_id = items[1]
            elif items[0] == 'AWSSecretKey':
                secret_key = items[1]

    if not access_key_id or not secret_key:
        raise RuntimeError('Invalid keys file format.')

    # set up URLs
    if args.production:
        mturk_url = 'mechanicalturk.amazonaws.com'
        preview_url = 'https://www.mturk.com/mturk/preview?groupId='
    else:
        print 'SANDBOX'
        mturk_url = 'mechanicalturk.sandbox.amazonaws.com'
        preview_url = 'https://workersandbox.mturk.com/mturk/preview?groupId='

    # connect
    connection = MTurkConnection(aws_access_key_id=access_key_id,
                                 aws_secret_access_key=secret_key,
                                 host=mturk_url)

    # make the HIT
    question = ExternalQuestion(
        external_url=
        'https://kirbpowell.github.io/crowdsourcing-assignment2/',  # URL to serve HIT
        frame_height=600)  # height of frame

    reward = Price(amount=0.25)  # reward for HIT completion

    create_hit_result = connection.create_hit(
        title='Count Recognizable People in Pictures',
        description='Count how many *recognizable* people are in some pictures',
        keywords=[
            'count', 'people', 'pictures', 'simple', 'easy', 'quick', 'label',
            'classification'
        ],
        max_assignments=10,  # number of assignments
        lifetime=datetime.timedelta(days=2),  # time HIT is available
        duration=datetime.timedelta(minutes=5),  # time to complete
        approval_delay=datetime.timedelta(days=7),  # time til HIT approved
        question=question,
        reward=reward,
        response_groups=('Minimal', 'HITDetail'))

    print('Preview: ' + preview_url + create_hit_result[0].HITTypeId)
    print('HIT Id: ' + create_hit_result[0].HITId)
Beispiel #4
0
    def push_tasks_mturk(self):
        frame_height = self.config.get('mturk', 'frameheight')
        amount = 0.01
        tasklets = self.db.get_unassigned_tasklets()
        sdescription = self.config.get('mturk', 'shortdescr')

        for tasklet in tasklets:
            #print 'pushing!'

            url = "https://cgcturk.hacked.jp/tasklet/{}/".format(tasklet['id'])
            keywords = ["easy"]
            questionform = ExternalQuestion(url, frame_height)

            hit_result = self.MTconnection.create_hit(
                title=HaCRSUtil.get_tasklet_name(tasklet),
                description=sdescription,
                keywords=keywords,
                max_assignments=1,
                question=questionform,
                reward=Price(amount=amount),
                response_groups=('Minimal', 'HITDetail'),  # ?
            )
            assert len(hit_result) == 1
            mturkid = self.db.create_mturk_resource(hit_result[0].HITId,
                                                    hit_result[0].HITGroupId)
            self.db.add_mturk_tasklet_association(tasklet['id'], mturkid)
        self.db.commit()
Beispiel #5
0
    def create_hit(self, job_id, bundle_id, hitType="yesno"):
        params_to_encode = {
            "job_id": job_id,
            "bundle_id": bundle_id,
            "host": self.external_submit_endpoint
        }
        encoded_url = encode_get_parameters(
            self.base_url + "/amt_{}".format(hitType), params_to_encode)
        # print(encoded_url)

        if hitType == "yesno":
            props = hit_properties.YesNoHitProperties
        elif hitType == "edit":
            props = hit_properties.EditHitProperties
        else:
            raise Exception("Hit type not implemented")

        create_hit_result = self.connection.create_hit(
            title=props["title"],
            description=props["description"],
            keywords=props["keywords"],
            duration=props["duration"],
            max_assignments=props["max_assignments"],
            question=ExternalQuestion(encoded_url, props["frame_height"]),
            reward=Price(amount=props["reward"]),
            # Determines information returned by certain API methods.
            response_groups=('Minimal', 'HITDetail'),
            qualifications=props["qualifications"])
Beispiel #6
0
def post_HIT(task, trial):
    amount = 0.10
    # Start the verify task
    url = "https://cs279-final-project.herokuapp.com/%s?trial=%s" % (task,
                                                                     trial)
    questionform = ExternalQuestion(url, 1200)
    create_hit_result = connection.create_hit(
        title="Help locate things in Google Street View — one question only!",
        description=
        "Participate in a short study to find things in Google Street View",
        keywords=["find", "locate", "quick"],
        #duration is in seconds
        duration=60 * 5,
        #max_assignments will set the amount of independent copies of the task (turkers can only see one)
        max_assignments=TASK_LIMIT,
        question=questionform,
        reward=Price(amount),
        #Determines information returned by method in API, not super important
        response_groups=('Minimal', 'HITDetail'),
        qualifications=Qualifications(),
    )

    # The response included several fields that will be helpful later
    hit_type_id = create_hit_result[0].HITTypeId
    hit_id = create_hit_result[0].HITId
    print "Your HIT has been created. You can see it at this link:"
    print "https://workersandbox.mturk.com/mturk/preview?groupId={}".format(
        hit_type_id)
    print "Your HIT ID is: {}".format(hit_id)
    return
def make_payments(mturk_conn,
                  results_csv,
                  bonus_amount,
                  rejected,
                  partial,
                  bonuses,
                  debug=False):
    reader = csv.reader(open(results_csv, 'r'))
    header = reader.next()
    assignment_idx = header.index('AssignmentId')
    worker_idx = header.index('WorkerId')
    code_idx = header.index('Answer.surveycode')
    for row in reader:
        assignmentid = row[assignment_idx]
        workerid = row[worker_idx]
        code = row[code_idx]
        try:
            if code in rejected.keys():
                print "Rejecting assignment %s: chat %s, agent %d, worker %s" % (
                    assignmentid, rejected[code][0], rejected[code][1],
                    workerid)
                if not debug:
                    mturk_conn.reject_assignment(
                        assignmentid,
                        feedback=
                        'Not enough of an attempt to complete the negotiation.'
                    )
            elif code in partial.keys():
                print "Partial: approving assignment %s: chat %s, agent %d, worker %s" % (
                    assignmentid, partial[code][0], partial[code][1], workerid)
                if not debug:
                    mturk_conn.approve_assignment(
                        assignmentid,
                        feedback=
                        'Thanks for attempting this negotiation task! :)')
            else:
                # print "Approve assignment %s: " % code
                if not debug:
                    mturk_conn.approve_assignment(
                        assignmentid,
                        feedback=
                        'Thanks for attempting this negotiation task! :)')
        except MTurkRequestError as e:
            print "FAILED: approve/reject:", e.reason

        try:
            if code in bonuses.keys():
                print "Bonus for assignment %s: chat %s, agent %d, worker %s" % (
                    assignmentid, bonuses[code][0], bonuses[code][1], workerid)
                if not debug:
                    mturk_conn.grant_bonus(
                        workerid,
                        assignmentid,
                        Price(amount=bonus_amount),
                        reason='For great negotiation skills!')
            pass
        except MTurkRequestError as e:
            print "FAILED: bonus: ", e.reason
Beispiel #8
0
def create_hit(hit_options):
    """ Create a new HIT on AMT.

        `hit_options` is a dictionary that can contain:

        * `title`: The title that will show up in AMT's HIT listings
        * `description`: The description that will show up in AMT's HIT listings
        * `reward`: A float containing the number of cents to pay for each
          assignment
        * `duration`: The expected amount of time a worker should spend on each
          assignment, in minutes
        * `num_responses`: The number of responses to get for the HIT
        * `frame_height`: The height of the iframe in which workers will see the
          assignment
        * `use_https`: whether or not to load assignment in AMT's iframe using
          HTTPS. Strongly recommended to be True

        By default, options are loaded from `settings.AMT_DEFAULT_HIT_OPTIONS`.
    """
    options = settings.AMT_DEFAULT_HIT_OPTIONS
    options.update(hit_options)

    scheme = 'https' if options['use_https'] else 'http'

    from interface import AMT_INTERFACE
    path = AMT_INTERFACE.get_assignment_url()

    url = (scheme + '://' + settings.PUBLIC_IP + ':8000' +
           path if settings.HAVE_PUBLIC_IP else scheme + '://' +
           settings.AMT_CALLBACK_HOST + path)

    question = ExternalQuestion(external_url=url,
                                frame_height=options['frame_height'])
    qualifications = Qualifications(requirements=[
        PercentAssignmentsApprovedRequirement(
            'GreaterThanOrEqualTo', 85, required_to_preview=True),
    ])
    conn = get_amt_connection(options['sandbox'])

    try:
        create_response = conn.create_hit(
            question=question,
            title=options['title'],
            description=options['description'],
            reward=Price(amount=options['reward']),
            duration=timedelta(minutes=options['duration']),
            max_assignments=options['num_responses'],
            approval_delay=3600,
            qualifications=qualifications)
    except MTurkRequestError:
        logger.debug(traceback.format_exc())
        raise AMTException("""
            Could not reach Amazon Mechanical Turk.
            Check that you are using https mode, and defined a valid assignment.
            Details of the exception have been logged to the ampcrowd server.
            """)

    return create_response[0].HITId
 def get_price_as_price(reward):
     """
     Returns a Price data structure from either a float or a Price
     """
     if isinstance(reward, Price):
         final_price = reward
     else:
         final_price = Price(reward)
     return final_price
Beispiel #10
0
 def grant_bonus(self, data):
     '''data = list of (worker_id, assignment_id, bonus_amount, reason)'''
     if raw_input('Granting bonus to %d Turkers. Continue? (y/N) '
                  % len(data)).lower() != 'y':
         return
     for worker_id, assignment_id, bonus_amount, reason in data:
         bonus_amount = Price(float(bonus_amount))
         self.mtc.grant_bonus(worker_id, assignment_id, bonus_amount, reason)
         print 'Granted %s to %s (%s)' % (bonus_amount, worker_id, reason)
Beispiel #11
0
def create_hit(url=None,
               title=None,
               description=None,
               keywords=None,
               reward_amount=None,
               max_assignments=None,
               duration_in_minutes=None,
               lifetime_in_days=None,
               approval_delay_in_days=None,
               qualification_percent_approved=None,
               qualification_hits_approved=None):
    url = url or "https://squadtest.herokuapp.com/"
    title = title or "Compare 100 sets of 2 Instagram posts to guess which performed better (<10 minutes)"
    description = description or "This HIT will take at most 15 minutes (usually much less). If you have a problem with the HIT, message us so we can fix it!"
    keywords = keywords or [
        "easy", "survey", "study", "bonus", "image", "images", "compare",
        "comparisons", "collection", "data", "research", "listings", "simple",
        "photo", "answer", "opinion", "question"
    ]
    frame_height = 800
    reward_amount = reward_amount or 1
    max_assignments = max_assignments or 200

    duration_in_minutes = duration_in_minutes or 20
    duration = datetime.timedelta(minutes=duration_in_minutes)

    lifetime_in_days = lifetime_in_days or 3
    lifetime = datetime.timedelta(days=3)

    approval_delay_in_days = approval_delay_in_days or 5
    approval_delay = datetime.timedelta(days=approval_delay_in_days)

    qualification_percent_approved = qualification_percent_approved or 95
    q1 = PercentAssignmentsApprovedRequirement('GreaterThan',
                                               qualification_percent_approved)

    qualification_hits_approved = qualification_hits_approved or 500
    q2 = NumberHitsApprovedRequirement('GreaterThan',
                                       qualification_hits_approved)
    qualifications = Qualifications([q1, q2])

    questionform = ExternalQuestion(url, frame_height)
    result = connection.create_hit(title=title,
                                   description=description,
                                   keywords=keywords,
                                   max_assignments=max_assignments,
                                   question=questionform,
                                   reward=Price(amount=reward_amount),
                                   response_groups=('Minimal', 'HITDetail',
                                                    'HITQuestion',
                                                    'HITAssignmentSummary'),
                                   lifetime=lifetime,
                                   duration=duration,
                                   approval_delay=approval_delay,
                                   qualifications=qualifications)
    print result
def create_hits(hit_type_id, no_of_hits = NUM_HITS, no_of_assignments = 1, amount = amountToPay, duration = 1200):
    questionform = ExternalQuestion(url, frame_height)
    for _ in xrange(no_of_hits):
        print _
        create_hit_result = mtc.create_hit(
            hit_type = hit_type_id,
            max_assignments = no_of_assignments,
            question = questionform,
            reward = Price(amount=amount),
        )
    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
Beispiel #14
0
 def do_pay_bonus(self, tid, wid, aid, price):
     assert len(tid) > 5, 'tasklet id mismatch'
     reason = "We issued a bonus for reaching a stretch goal of our task - Thanks!"
     assert price < 5
     self.log_bonus(tid, wid, aid, price)
     try:
         self.MTconnection.grant_bonus(wid, aid, Price(price), reason)
         return True
     except Exception as e:
         #print "Not issued for whatever reason: {}".format(e)
         return False
Beispiel #15
0
def grant_bonus(worker, experiment, reward):
  mturk = connect(experiment)

  reason = 'Additional reward for second image labeling task'

  return mturk.grant_bonus(
    worker.id
  , worker.assignment_id
  , Price(cents_to_dollars(reward))
  , reason
  )
Beispiel #16
0
 def __init__(self, title, description, keywords, url, frame_height,
              reward_as_usd_float, assignment_duration, lifetime,
              max_assignments, auto_approval_delay):
     self.title = title
     self.description = description
     self.keywords = keywords
     self.url = url
     self.frame_height = frame_height
     self.reward_as_usd_float = reward_as_usd_float
     self.assignment_duration = assignment_duration
     self.lifetime = lifetime
     self.max_assignments = max_assignments
     self.auto_approval_delay = auto_approval_delay
     self._question = ExternalQuestion(escape(self.url), self.frame_height)
     self._price = Price(self.reward_as_usd_float)
Beispiel #17
0
def bonus_worker(worker, assignment, amount, reason):
    crowd_config = json.loads(assignment.task.group.crowd_config)
    conn = get_amt_connection(crowd_config['sandbox'])
    if not assignment_exists(assignment):
        logger.warn("No assignment--not granting it a bonus.")
        return

    try:
        conn.grant_bonus(worker.worker_id, assignment.assignment_id,
                         Price(amount=amount), reason)
    except MTurkRequestError as e:
        logging.debug(traceback.format_exc())
        raise AMTException(
            "Couldn't grant bonus to worker %s for assignment %s: %s" %
            (worker.worker_id, assignment.assignment_id, str(e)))
Beispiel #18
0
 def register(self):
     mtc = self.account.connection(self.sandbox)
     rs = mtc.register_hit_type(title=self.title,
                                description=self.description,
                                reward=Price(self.reward),
                                duration=self.duration,
                                keywords=self.keywords,
                                approval_delay=self.approval_delay,
                                qual_req=build_qualifications(
                                    self.qualifications))
     if rs.status:
         self.status = 'Registered'
         self.mturk_id = rs[0].HITTypeId
         return True
     return False
    def create_hit(self, task, *rows, reward=None, max_assignments=None):
        logger.info("creating hit for task %s", task.id)
        reward = reward or DEFAULT_REWORD
        logger.info(".. reward: %s", reward)
        max_assignments = max_assignments or DEFAULT_MAX_ASSIGNMENTS
        logger.info(".. max_assignments: %s", max_assignments)

        upper_task = task.wrong_rows_definition
        logger.info(".. upper_task: %s", upper_task)
        lower_task = task.task_definition
        logger.info(".. lower_task: %s", lower_task)
        functions = json.dumps(task.get_functions())
        logger.info(".. functions: %s", functions)
        values = []
        for row in rows:
            values.append([row.number, row.get_values()])
        values = json.dumps(values)

        connection = self.get_connection()
        question = ExternalQuestion(QUESTION_URL, QUESTION_HEIGHT)
        result = connection.create_hit(question=question,
                                       title=QUESTION_TITLE,
                                       description=QUESTION_DESC,
                                       reward=Price(reward),
                                       keywords=QUESTION_KEYWORDS,
                                       max_assignments=max_assignments,
                                       lifetime=QUESTION_LIFETIME,
                                       annotation=QUESTION_ANNOTATION)
        hit = result[0]

        url = "https://{}/mturk/preview?groupId={}".format(
            URLHOST, hit.HITTypeId)
        logger.info(".. url: %s", url)

        logger.info(".. done: %s - %s", hit.HITId, hit.HITTypeId)

        return self.model(ident=hit.HITId,
                          task=task,
                          group=hit.HITTypeId,
                          reward=reward,
                          max_assignments=max_assignments,
                          upper_task=upper_task,
                          lower_task=lower_task,
                          functions=functions,
                          url=url,
                          values=values)
def bonus_for_hits(request, hit):
    passed_num = 0
    assignments = mtc.get_assignments(hit)
    for a in assignments:
        label_count = Emotion_Label_Component_Process_Likert.objects.filter(
            wid=a.WorkerId, aid=a.AssignmentId).count()
        bonus = Bonus_Paid.objects.filter(wid=a.WorkerId,
                                          aid=a.AssignmentId,
                                          hid=hit).count()
        if label_count > 0 and bonus == 0:
            mtc.grant_bonus(a.WorkerId, a.AssignmentId, Price(4.00),
                            "You passed prescreen, so you get this bonus!")
            nb = Bonus_Paid(wid=a.WorkerId, aid=AssignmentId, hid=hit)
            nb.save()
            # do accept also here?
            passed_num = passed_num + 1
    return HttpResponse("Paid bonus to " + str(passed_num) + " workers")
Beispiel #21
0
    def create_hit_type(self, *args):
        print "Creating HIT Type..."

        #Set up qualifications
        my_qual_req = Qualifications()
        #my_qual_req.add(PercentAssignmentsApprovedRequirement("GreaterThan", 85))
        #my_qual_req.add(NumberHitsApprovedRequirement("GreaterThan", 100))
        #my_qual_req.add(LocaleRequirement("EqualTo", "US"))

        #Create json object for storage to mongo
        J = {
            'title':
            "Read a blog post or news article and answer questions about it",
            'description':
            "Read a short blog post or news article and answer questions about it. These are quick HITs, and there are going to be a lot of them.  Bonuses for accurate answers!",
            'reward': 0.06,
            'duration': 3600,
            'keywords': "blog, news, article, quick, easy, bonus, civility",
            'approval_delay': 2592000,
            'qual_req': [req.__dict__ for req in my_qual_req.requirements],
        }

        #Register HIT type on mongo
        HT_id = self.mt_conn.register_hit_type(
            title=J["title"],
            description=J["description"],
            reward=Price(J["reward"]),
            duration=J["duration"],
            keywords=J["keywords"],
            approval_delay=J["approval_delay"],
            qual_req=my_qual_req,
        )

        #Retrieve the HITTypeId
        J["hittypeid"] = HT_id[0].HITTypeId
        J["created_at"] = datetime.datetime.now()

        #        print json.dumps(J, cls=helpers.MongoEncoder, indent=2)
        print "\tHIT Type created with ID", J["hittypeid"]

        #Save the object to mongo
        db_id = self.db_conn['cvm_mturk_hittypeid'].insert(J)
        print "\tHIT Type stored to database with ID ", db_id

        return 1
Beispiel #22
0
def create_hit(hit_options):
    ''' Create a new HIT on AMT.

        `hit_options` is a dictionary that can contain:

        * `title`: The title that will show up in AMT's HIT listings
        * `description`: The description that will show up in AMT's HIT listings
        * `reward`: A float containing the number of cents to pay for each
          assignment
        * `duration`: The expected amount of time a worker should spend on each
          assignment, in minutes
        * `num_responses`: The number of responses to get for the HIT
        * `frame_height`: The height of the iframe in which workers will see the 
          assignment
        * `use_https`: whether or not to load assignment in AMT's iframe using
          HTTPS. Strongly recommended to be True

        By default, options are loaded from `settings.AMT_DEFAULT_HIT_OPTIONS`.
    '''
    options = settings.AMT_DEFAULT_HIT_OPTIONS
    options.update(hit_options)

    scheme = 'https' if options['use_https'] else 'http'

    from interface import AMT_INTERFACE
    path = AMT_INTERFACE.get_assignment_url()

    url = (scheme + '://' + json.loads(urlopen('http://jsonip.com').read())['ip'] + ':8000' +  path
           if settings.HAVE_PUBLIC_IP else scheme + '://' + Site.objects.get_current().domain + path)

    question = ExternalQuestion(
        external_url=url,
        frame_height=options['frame_height'])
    conn = get_amt_connection(options['sandbox'])

    create_response = conn.create_hit(
        question=question,
        title=options['title'],
        description=options['description'],
        reward=Price(amount=options['reward']),
        duration=timedelta(minutes=options['duration']),
        max_assignments=options['num_responses'],
        approval_delay=0)

    return create_response[0].HITId
Beispiel #23
0
def createSeveralHits(numberOfSubjects):
    
    #    HOST = 'mechanicalturk.sandbox.amazonaws.com'
    #    HOST = 'mechanicalturk.amazonaws.com'

    global connection
    global layoutID
    url = 'THE LINK TO THE STUDY'
    title = "TITLE OF THE STUDY"
    description = "DESCRIPTION OF THE STUDY"
    keywords = ["KEYWORDS"]
    amount = 0.4
# game = ExternalQuestion(url, frame_height)
    remaining = numberOfSubjects
    create_hit_result = None
    timestr = time.strftime("%Y%m%d-%H%M%S")
    myfile=open("./HITIDs/"+timestr + '.txt', 'w')      # Saves all the created hits under HITIDS. The name of the file is based on the date and time of creation.
    ####Setting Worker Requirements:
    workerRequirements=Qualifications()
    req1= PercentAssignmentsApprovedRequirement(comparator = "GreaterThan", integer_value = "96",required_to_preview=True)
    workerRequirements.add(req1)
    req2= LocaleRequirement(comparator = "EqualTo",locale ="US",required_to_preview=True)
    workerRequirements.add(req2)
    req3=NumberHitsApprovedRequirement(comparator = "GreaterThan", integer_value = "50",required_to_preview=True)
    workerRequirements.add(req3)
    
   
    while remaining>0:
        no_assignments = min(9, remaining)
        create_hit_result = connection.create_hit(
            title=title,
            description=description,
            keywords=keywords,
            max_assignments=no_assignments,
            hit_layout=layoutID,
            lifetime=6*60*60,
            duration=3*60*60,
            approval_delay=3*60*60*24,
            reward=Price(amount=amount),
            qualifications=workerRequirements)
        remaining -= no_assignments
        myfile.write(create_hit_result[0].HITId+"\n")
        print "No. Assignments: ", no_assignments
        print "Results:", create_hit_result
        print "hit ID:", create_hit_result[0].HITId
Beispiel #24
0
 def _create_hit(self, params, **kwargs):
     """
     internal helper function for creating a HIT
     :param params the parameters (required and optional) common to all HITs
     :param **kwargs any other parameters needed for a specific HIT type
     :return the created HIT object
     """
     return self.connection.create_hit(
         title=params["title"],
         description=params["description"],
         keywords=params["keywords"],
         max_assignments=params["max_assignments"],
         reward=Price(amount=params["amount"]),
         qualifications=params["qualifications"],
         lifetime=params["lifetime"],
         # optional params below
         annotation=params.get("annotation"),
         **kwargs)
 def create_hits(self, project, tasks=None, repetition=None):
     if project.min_rating > 0:
         return 'NOOP'
     title = project.name
     reward = Price(project.price)
     if not tasks:
         query = '''
             select t.id, count(tw.id) worker_count from
             crowdsourcing_task t
             LEFT OUTER JOIN crowdsourcing_taskworker tw on t.id = tw.task_id and tw.task_status
             not in (%(skipped)s, %(rejected)s)
             where project_id = %(project_id)s
             GROUP BY t.id
         '''
         tasks = Task.objects.raw(query,
                                  params={
                                      'skipped': TaskWorker.STATUS_SKIPPED,
                                      'rejected':
                                      TaskWorker.STATUS_REJECTED,
                                      'project_id': project.id
                                  })
     for task in tasks:
         question = self.create_external_question(task)
         max_assignments = 1
         qualifications = None
         if str(settings.MTURK_QUALIFICATIONS) == 'True':
             qualifications = self.get_qualifications()
         if not MTurkHIT.objects.filter(task=task):
             hit = self.connection.create_hit(
                 hit_type=None,
                 max_assignments=max_assignments,
                 title=title,
                 reward=reward,
                 duration=datetime.timedelta(hours=72),
                 description=self.description,
                 keywords=self.keywords,
                 qualifications=qualifications,
                 question=question)[0]
             self.set_notification(hit_type_id=hit.HITTypeId)
             mturk_hit = MTurkHIT(hit_id=hit.HITId,
                                  hit_type_id=hit.HITTypeId,
                                  task=task)
             mturk_hit.save()
     return 'SUCCESS'
Beispiel #26
0
    def create_hit(self, title, description, keywords, reward, duration_hours,
                   lifetime_days, ad_url, notification_url,
                   approve_requirement, max_assignments, us_only):
        """Create the actual HIT and return a dict with its useful properties."""
        frame_height = 600
        mturk_question = ExternalQuestion(ad_url, frame_height)
        qualifications = self.build_hit_qualifications(approve_requirement,
                                                       us_only)
        hit_type_id = self.register_hit_type(title, description, reward,
                                             duration_hours, keywords)
        self.set_rest_notification(notification_url, hit_type_id)

        params = {
            'hit_type':
            hit_type_id,
            'question':
            mturk_question,
            'lifetime':
            datetime.timedelta(days=lifetime_days),
            'max_assignments':
            max_assignments,
            'title':
            title,
            'description':
            description,
            'keywords':
            keywords,
            'reward':
            Price(reward),
            'duration':
            datetime.timedelta(hours=duration_hours),
            'approval_delay':
            None,
            'qualifications':
            qualifications,
            'response_groups':
            ['Minimal', 'HITDetail', 'HITQuestion', 'HITAssignmentSummary']
        }
        hit = self.mturk.create_hit(**params)[0]
        if hit.IsValid != 'True':
            raise MTurkServiceException(
                "HIT request was invalid for unknown reason.")

        return self._translate_hit(hit)
Beispiel #27
0
def grant_bonus(result_id):
    '''grant_bonus will calculate and grant a total bonus for a worker
    :param result_id: the id the result to grant the bonus for
    '''
    result = Result.objects.get(id=result_id)
    worker = result.worker
    battery = result.battery
    result.assignment.hit.generate_connection()
    try:
        bonus = Bonus.objects.get(worker=worker, battery=battery)
        amount = bonus.calculate_bonus()
        price = Price(amount)
        reason = get_bonus_reason(bonus)
        result.assignment.hit.connection.grant_bonus(
            worker.id, result.assignment.mturk_id, price, reason)
        bonus.granted = True
        bonus.save()
    except Bonus.DoesNotExist:
        pass
Beispiel #28
0
 def grant_bonus(self, assignment_id, amount, reason):
     """Grant a bonus to the MTurk Worker.
     Issues a payment of money from your account to a Worker.  To
     be eligible for a bonus, the Worker must have submitted
     results for one of your HITs, and have had those results
     approved or rejected. This payment happens separately from the
     reward you pay to the Worker when you approve the Worker's
     assignment.
     """
     amount = Price(amount)
     assignment = self.mturk.get_assignment(assignment_id)[0]
     worker_id = assignment.WorkerId
     try:
         return self._is_ok(
             self.mturk.grant_bonus(worker_id, assignment_id, amount,
                                    reason))
     except MTurkRequestError:
         logger.exception("Failed to pay assignment {} bonus of {}".format(
             assignment_id, amount))
Beispiel #29
0
def give_bonus(worker_ids, hit_id, bonus, reason):
    payment = Price(bonus)
    assignments = []
    page = 1
    while (1):
        res = connection.get_assignments(hit_id,
                                         page_size=100,
                                         page_number=str(page))
        if len(res) > 0:
            assignments.extend(res)
            page += 1
        else:
            break
    for assignment in assignments:
        if assignment.WorkerId in worker_ids:
            result = connection.grant_bonus(assignment.WorkerId,
                                            assignment.AssignmentId, payment,
                                            reason)
            if result != []:
                print result
Beispiel #30
0
    def register_hit(self, configuration=None):
        """
        Register a hit on Mechanical Turk according to `hit_params`. This will provide you with a HITTypeId.

        Parameters
        ----------
        configuration : dict

        Returns
        -------
        str
            The HITTypeId which is how you refer to your newly registered hit with Amazon
        """
        if configuration is None:
            configuration = app.config

        qualifications = Qualifications()
        if self.debug:
            qualifications.add(
                NumberHitsApprovedRequirement('GreaterThanOrEqualTo', 0))
            qualifications.add(
                PercentAssignmentsApprovedRequirement('GreaterThanOrEqualTo',
                                                      0))
        else:
            qualifications.add(
                NumberHitsApprovedRequirement(
                    'GreaterThanOrEqualTo',
                    configuration['MTURK_NUMBER_HITS_APPROVED_REQUIREMENT']))
            qualifications.add(
                PercentAssignmentsApprovedRequirement(
                    'GreaterThanOrEqualTo', configuration[
                        'MTURK_PERCENT_ASSIGNMENTS_APPROVED_REQUIREMENT']))

        hit_type = self.connection.register_hit_type(
            configuration['MTURK_TITLE'], configuration['MTURK_DESCRIPTION'],
            Price(configuration['MTURK_REWARD']),
            configuration['MTURK_ASSIGNMENT_DURATION_IN_SECONDS'],
            configuration['MTURK_KEYWORDS'],
            configuration['MTURK_AUTO_APPROVAL_DELAY_IN_SECONDS'],
            qualifications)
        return hit_type[0].HITTypeId