Exemplo n.º 1
0
def extend_hit_assignments(hitid, count):
    m = mturk.MechanicalTurk(get_mturk_conf(False))
    r = m.request("ExtendHIT", {
        'HITId': hitid,
        'MaxAssignmentsIncrement': count
    })
    print r
    return r
Exemplo n.º 2
0
def approve_rejected_assignment(assignmentId):
    m = mturk.MechanicalTurk(get_mturk_conf(False))
    r = m.request(
        "ApproveRejectedAssignment", {
            'AssignmentId':
            assignmentId,
            'RequesterFeedback':
            'Approving some rejected assignments just this time.'
        })
    print r
    return r
Exemplo n.º 3
0
def reject_assignment(assignmentId):
    m = mturk.MechanicalTurk(get_mturk_conf(False))
    r = m.request(
        "RejectAssignment", {
            'AssignmentId':
            assignmentId,
            'RequesterFeedback':
            'Sorry, You failed to rate correctly on our verification message. Please read the instructions carefully next time. More information can be found at https://goo.gl/QAkHaJ. Please contact the requester for more information.'
        })
    print r
    return r
Exemplo n.º 4
0
def gen_operation(op, q):
    # if db.unblocked_workers.find_one({'WorkerId':workerId}):
    # return {'msg':'already blocked', 'workerId':workerId}
    m = mturk.MechanicalTurk(get_mturk_conf(False))
    # q= {
    #         'WorkerId': workerId,
    #         'Reason': 'Task was not completed properly. Rating of messages was found to be inappropriate: you failed to vote correctly on our verification messages.'
    #            }
    # db.insert(q)
    r = m.request(op, q)
    print r
    return r
Exemplo n.º 5
0
def block_worker(workerId):
    if db.blocked_workers.find_one({'WorkerId': workerId}):
        return {'msg': 'already blocked', 'workerId': workerId}
    m = mturk.MechanicalTurk(get_mturk_conf(False))
    q = {
        'WorkerId':
        workerId,
        'Reason':
        'Task was not completed properly. Rating of messages was found to be inappropriate: you failed to vote correctly on our verification messages.'
    }
    db.blocked_workers.insert(q)
    r = m.request("BlockWorker", q)
    print r
    return r
Exemplo n.º 6
0
def grant_bonus(assignmentId, amt, reason):
    worker_id = db.responses.find_one({
        'assignmentId': assignment_id
    }).get('workerId')
    m = mturk.MechanicalTurk(get_mturk_conf(False))
    r = m.request(
        "GrantBonus", {
            'AssignmentId': assignmentId,
            'WorkerId': worker_id,
            'BonusAmount': {
                'Amount': amt,
                'CurrencyCode': 'USD'
            },
            'Reason': reason
        })
    print r
    return r
Exemplo n.º 7
0
conf_turk = {
    "use_sandbox": False,
    "stdout_log": False,
    "verify_mturk_ssl": True,
    "aws_key": "AKIAJLJ5F2MLV36GZKAA",
    "aws_secret_key": "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"
}
conf_sbox = {
    "use_sandbox": True,
    "stdout_log": False,
    "verify_mturk_ssl": True,
    "aws_key": "AKIAJLJ5F2MLV36GZKAA",
    "aws_secret_key": "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"
}

m_Turk = mturk.MechanicalTurk(conf_turk)
m_sandbox = mturk.MechanicalTurk(conf_sbox)

# r = m_Turk.request("GetAccountBalance")
# if r.valid:
#     print r.get_response_element("AvailableBalance")


def doWork(response, timeout=60):
    print 'sleeping for %d seconds' % timeout

    # add timeout
    time.sleep(timeout)
    # logr.plog("Received request: %s"%data)
    data = response['data']
def get_hits():
    sandbox_flag = request.args.get('sandbox_flag', 'False')
    conf = {
        "use_sandbox": eval(sandbox_flag),
        "stdout_log": False,
        "verify_mturk_ssl": True,
        "aws_key": "AKIAJLJ5F2MLV36GZKAA",
        "aws_secret_key": "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"
    }

    m = mturk.MechanicalTurk(conf)
    # get all hits
    hits = []
    r = m.request("SearchHITs", {
        'SortDirection': 'Descending',
        'PageSize': 100
    })
    total_hits = int(
        r[u'SearchHITsResponse'][u'SearchHITsResult'][u'TotalNumResults'])
    # hits = [(x['CreationTime'],x['HITId'],x['NumberOfAssignmentsCompleted'])
    # for x in r['SearchHITsResponse']['SearchHITsResult']['HIT']]#[:20]
    pgno = 0

    while len(hits) < 20:
        pgno += 1
        r = m.request("SearchHITs", {
            'SortDirection': 'Descending',
            'PageSize': 100,
            'PageNumber': pgno
        })
        try:
            hits.extend([
                (x['CreationTime'], x['HITId'],
                 x['NumberOfAssignmentsCompleted']
                 )  # , x['RequesterAnnotation'])
                for x in r['SearchHITsResponse']['SearchHITsResult']['HIT']
            ])
        except Exception as e:
            print 'some error on page %s: %s' % (pgno, e)
            break
        break
        # time.sleep(1)
    print 'Total HITs', len(hits)
    alldata = []
    for hit in hits[:20]:
        try:
            hitd = db.hits.find_one({'hitId': hit[1]}, {'_id': False})
            output = '<div style="overflow:auto; height:40px; width:300px;"><pre><code class="prettyprint">{hitr}</pre></code></div>'.format(
                hitr=json_util.dumps(hitd, indent=4))
            alldata.append({
                'task_type':
                hitd.get('taskType', 'NA'),
                'shortname':
                '%s | %s' % (hitd['requirements'].get('persona', 'NA'),
                             hitd['requirements'].get('shortname', 'NA')),
                'task_title':
                hitd['requirements'].get('task_title', 'NA'),
                'hitId':
                hit[1],
                'CreationTime':
                hit[0],
                'Assignments':
                hit[2],
                'hitURL':
                '<a href="%s">Link</a>' % hitd.get('url', 'NA'),
                'hit_json':
                output,
            })
        except:
            alldata.append({
                'task_type': 'Not Found',
                'hitId': hit[1],
                'CreationTime': hit[0],
                'Assignments': hit[2],
                'hitURL': 'Not Found',
                'hit_json': 'Not Found'
            })

    return render_template('hits.html', data=alldata)
Exemplo n.º 9
0
def create_hit(hit_config, task_config):
    m = mturk.MechanicalTurk(get_mturk_conf(task_config['use_sandbox']))
    description = task_config['title']
    keywords = 'idea, message, text, walking, support, help, physical, activity'
    # v = task_config['incentive']
    v = get_hit_incentive(task_config)
    amt = math.ceil(v * 100) / 100
    reward = {'Amount': amt, 'CurrencyCode': 'USD'}
    duration = 60 * 20
    autoapp = 60 * 60 * 48

    question = get_question(task_config)
    lifetime = 60 * 60 * 24
    max_assignments = task_config['max_assignments']
    qualification_req = [
        {
            "QualificationTypeId": "000000000000000000L0",
            "IntegerValue": 98,
            'Comparator': 'GreaterThan'
        },
        {
            "QualificationTypeId": "00000000000000000040",
            "IntegerValue": 1000 if task_config['use_sandbox'] == False else 1,
            'Comparator': 'GreaterThan'
        },
        {
            "QualificationTypeId": "00000000000000000071",
            'Comparator': 'EqualTo',
            'LocaleValue': {
                'Country': 'US'
            }
        },
    ]

    task_type_conf = {
        'Title': task_config['title'],
        'Description': description,
        'MaxAssignments': max_assignments,
        'Keywords': keywords,
        'Reward': reward,
        'RequesterAnnotation': task_config.get('taskid'),
        'AssignmentDurationInSeconds': duration,
        'AutoApprovalDelayInSeconds': autoapp,
        'Question': question,
        'LifetimeInSeconds': lifetime,
        'QualificationRequirement': qualification_req
    }

    r = m.request("CreateHIT", task_type_conf)
    try:
        print 'HITId: %s' % r['CreateHITResponse']['HIT']['HITId']
    except:
        print 'Some problem. AWS Response: %s' % r

    hitid = r[u'CreateHITResponse'][u'HIT'][u'HITId']
    hit_typeid = r[u'CreateHITResponse'][u'HIT'][u'HITTypeId']
    create_time = datetime.now(pytz.utc)
    requirements = {
        'task_id': task_config.get('task_id', 'task_id'),
        'experiment_id': task_config.get('experiment_id', 'experiment_id'),
        'task_type': task_config['task_type'],
        'use_sandbox': task_config['use_sandbox'],
        'max_assignments': task_config['max_assignments']
    }

    requirements.update(hit_config)
    d = {
        'hitId': hitid,
        'createTime': create_time,
        'hitTypeId': hit_typeid,
        'task_type': task_config['task_type'],
        'experiment_id': task_config.get('experiment_id', 'experiment_id'),
        'task_id': task_config.get('task_id', ''),
        'url':
        '%s/get_hit?hitId=%s' % (get_hostname(task_config['port']), hitid),
        'requirements': requirements,
        'task_type_conf': task_type_conf,
        'task_config': task_config,
        'additional_assignments': 0,
        'shortname': task_config.get('shortname', 'NA')
    }

    return d
Exemplo n.º 10
0
def get_balance(use_sandbox=False):
    requester_conf = get_mturk_conf(use_sandbox)
    r = mturk.MechanicalTurk(requester_conf).request("GetAccountBalance")
    if r.valid:
        return r.get_response_element("AvailableBalance")