def handle(self, *args, **options):
        conn = connection.MTurkConnection(
            aws_access_key_id = settings.AWS_ACCESS_KEY,
            aws_secret_access_key = settings.AWS_SECRET_KEY,
            host = settings.MTURK_HOST
        )

        location = Location.objects.create(
            name = "Liberty Lounge TEST",
            website = "http://www.justinhinh.com",
            formattedPhoneNumber = "(202)790-4414",
            dateLastUpdated = timezone.now()
        )

        mturk_location_info = MTurkLocationInfo.objects.create(
            location = location,
            name = location.name,
            phone_number = location.formattedPhoneNumber,
            website = location.website
        )

        mturk_location_info.save()

        mturk_utilities.register_hit_types(conn)
        mturk_utilities.create_hit(conn, mturk_location_info, settings.MTURK_HIT_TYPES[FIND_HAPPY_HOUR])

        print("HIT " + mturk_location_info.hit_id + " created.")
        raw_input("Respond at workersandbox.mturk.com...")

        update_mturk_tasks.update()
        print("Updated")

        mturk_location_info.delete()
        location.delete()
def main():

    # Connect to MTurk
    connection = mt.MTurkConnection(aws_access_key_id=ACCESS_ID,
                                    aws_secret_access_key=SECRET_KEY,
                                    host=HOST)

    # Overview
    overview = mt_q.Overview()

    with open('instructions.txt') as f_in:
        instructions = f_in.read()

    overview.append_field('FormattedContent', '<![CDATA[%s]]>' % instructions)
    overview.append_field('Title', 'Answer the following questions:')

    # Question form
    question_form = mt_q.QuestionForm()
    question_form.append(overview)

    with open('questions.txt') as f_in:
        questions = [line.strip() for line in f_in]

    answers = [('Reference', 'reference'), ('Year', 'year'), ('Age', 'age'),
               ('People', 'people'), ('None', 'none')]

    for i, question in enumerate(questions):

        qc = mt_q.QuestionContent()
        qc.append_field('FormattedContent', '<![CDATA[%s]]>' % question)
        fta = mt_q.SelectionAnswer(min=1,
                                   max=1,
                                   style='radiobutton',
                                   selections=answers,
                                   type='text',
                                   other=False)
        q = mt_q.Question(identifier='q%d' % (i + 1),
                          content=qc,
                          answer_spec=mt_q.AnswerSpecification(fta),
                          is_required=True)
        question_form.append(q)

    # Build the answer key
    with open('answer_key.xml') as f_in:
        answer_key = f_in.read()

    # Create the qualification type
    connection.create_qualification_type(
        name='What\'s Missing',
        description='Choose the best description of numbers inside texts',
        status='Active',
        test=question_form,
        answer_key=answer_key,
        test_duration=3600,
        retry_delay=600)
Exemplo n.º 3
0
def new_mturk_connection():
    return conn.MTurkConnection(aws_access_key_id=lines[0],
                                aws_secret_access_key=lines[1],
                                is_secure=True,
                                port=None,
                                proxy=None,
                                proxy_port=None,
                                proxy_user=None,
                                proxy_pass=None,
                                host=None,
                                debug=0,
                                https_connection_factory=None,
                                security_token=None,
                                profile_name=None)
Exemplo n.º 4
0
    def handle(self, *args, **options):
        conn = connection.MTurkConnection(
            aws_access_key_id=settings.AWS_ACCESS_KEY,
            aws_secret_access_key=settings.AWS_SECRET_KEY,
            host=settings.MTURK_HOST)

        hits = list(conn.get_all_hits())

        for hit in hits:
            conn.disable_hit(hit.HITId)

        # Remove all MTurkLocationInfo and Stats
        for mturk_location_info in list(MTurkLocationInfo.objects.all()):
            if mturk_location_info.stat != None:
                mturk_location_info.stat.delete()
            mturk_location_info.delete()
Exemplo n.º 5
0
def get_mt_conn(sandbox=settings.SANDBOX):
    """
    returns a connection to mechanical turk.
    requires that settings defines the following variables:
    
    settings.SANDBOX:    True|False
    settings.aws_id:     your aws id
    settings.aws_secret: your aws secret key
    """
    if sandbox:
        host="mechanicalturk.sandbox.amazonaws.com"
    else:
        host="mechanicalturk.amazonaws.com"

    return connection.MTurkConnection(
        aws_access_key_id=settings.aws_id,
        aws_secret_access_key=settings.aws_secret,
        host=host)
Exemplo n.º 6
0
import sys
import os
import boto.mturk.connection as mtc
import mechturk.utils.environment as env

mt = mtc.MTurkConnection(env.amt_access_key, env.amt_secret_key)
hits_dir = sys.argv[1]
while hits_dir[-1] == '/':
    hits_dir = hits_dir[:-1]
with open(hits_dir + '/' + os.path.basename(hits_dir) + '.success') as fh:
    hits = [line.split()[0] for line in fh.readlines()[1:]]

for hit in hits:
    mt.expire_hit(hit)
Exemplo n.º 7
0
settings_in_file = settings.parse(settings_raw)
# settings_modified = (action is not "show status" and settings_in_log is not settings_in_file)
# TODO: bail if settings modified
settings = settings_in_file

## load hit metadata if it exists
hit_modes = dict()
hit = None
if os.path.isfile("hit_modes.json"):
  hit_modes = json.load(open("hit_modes.json", "r"))
  if mode in hit_modes:
    hit = hit_modes[mode]

## connect to amazon
mtc = connection.MTurkConnection(aws_access_key_id=ACCESS_ID,
                                 aws_secret_access_key=SECRET_KEY,
                                 host=HOST)

def create_hit(settings):
  global hit
  ## make sure there isn't already a hit
  if (hit is not None):
    sys.exit("Error: it looks like you already created the hit in %s mode (HIT ID stored in hit_modes.json)" % mode)

  hit_quals = Qualifications()
  settings_quals = settings["qualifications"]
  ## TODO: master worker, custom quals, utility for creating qualifications?
  if (settings_quals):
    if settings_quals["location"]:
      hit_quals.add(LocaleRequirement("EqualTo", settings_quals["location"]))
Exemplo n.º 8
0
from numpy import array
import numpy as np
import os
import shutil
from matplotlib import pyplot as plt
import itertools
import boto.mturk.connection as conn
import boto.mturk.qualification as qual

mturk = conn.MTurkConnection(
    aws_access_key_id='AKIAJUL53VTH3ENYMNIQ',
    aws_secret_access_key='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',
    is_secure=True,
    port=None,
    proxy=None,
    proxy_port=None,
    proxy_user=None,
    proxy_pass=None,
    host=None,
    debug=0,
    https_connection_factory=None,
    security_token=None,
    profile_name=None)

headers = [
    'video_url_mp4', 'video_url_webm', 'title', 'start_time', 'end_time'
]
url = 'http://cs.ubc.ca/~troniak/'
template_name = 'template.html'
qualified_workers = [
    'A248D5XVN1YGCZ', 'A2QAJ8BJ5QBB9A', 'A2WRSEO8HQRG5K', 'A37P0EXFVTAP0D',
    'A38KIO2400LOTJ', 'A3DY78Q4FCWTXX', 'A3N87BX6PS0SIB', 'A9XWAWNLJN8DA'
Exemplo n.º 9
0
        print "batch."
        exit(1)

    batch_id = int(sys.argv[1])

    transcribed_rate_gateway = models.TranscribedRateDataGateway('results.db')
    transcribed_rate_gateway.create_table()
    manual_review_gateway = models.ManualReviewDataGateway('results.db')
    manual_review_gateway.create_table()

    rejected_hits = collections.defaultdict(list)
    accepted_hits = collections.defaultdict(list)
    assignment_to_results = {}

    mturk_connection = connection.MTurkConnection(
        aws_access_key_id=AWS_ACCESS_KEY_ID,
        aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
    assignment_gateway = assignments.AssignmentGateway.get(mturk_connection)

    for each in assignment_gateway.get_by_batch_id(batch_id):
        if not each.rates:
            continue

        try:
            parse_result = ratecard_models.ParseResult.get_for_assignment(each)
        except ratecard_models.ParseFailedException as pfe:
            rejected_hits[each.hit_id].append(each.assignment_id)
            parse_turk_results.print_rate_results(each.hit_id, each.worker_id,
                                                  each.rates)
            continue
Exemplo n.º 10
0
        outfile = os.path.join(opts.outdir, 'batch_' + timestamp + '.csv')
        print 'Manually writing batch to csv file', outfile + '...',
        with open(outfile, 'w') as fout:
            headers = [
                'tgt', 'pos', 'bogus', 'unsorted', 'sorted', 'seeded',
                'num_classes', 'num_anno', 'latest_timestamp', 'crowdstarter'
            ]
            writer = csv.DictWriter(fout, fieldnames=headers)
            writer.writeheader()
            writer.writerows(hits)
            print 'Done'
        ## optionally auto-upload to AMT
        if opts.mode == 'auto':
            print 'Auto-uploading HITs to', settings['HOST']
            conn = connection.MTurkConnection(
                aws_access_key_id=settings['ACCESS_ID'],
                aws_secret_access_key=settings['SECRET_KEY'],
                host=settings['HOST'])
            qualifications = Qualifications()
            for q in settings['QUALIFICATIONS']:
                qualifications.add(q)

            for i, h in enumerate(hits):
                print 'posting HIT %d of %d' % (i, len(hits))
                params = [
                    layoutparam.LayoutParameter(k, v)
                    for k, v in h.iteritems()
                ]
                result = conn.create_hit(
                    hit_layout=settings['HIT_LAYOUT_ID'],
                    qualifications=qualifications,
                    max_assignments=settings['REDUNDANCY'],
Exemplo n.º 11
0
def update():

    django.setup()

    conn = connection.MTurkConnection(
        aws_access_key_id=settings.AWS_ACCESS_KEY,
        aws_secret_access_key=settings.AWS_SECRET_KEY,
        host=settings.MTURK_HOST)

    register_hit_types(conn)

    # Get the website updates in progress
    locations_to_update = MTurkLocationInfo.objects.all()

    # Add new locations that can be updated
    add_mturk_locations_to_update(conn)

    for mturk_location in locations_to_update:

        # If there is no HIT for the location, create one
        if (mturk_location.hit_id == None):
            create_hit(conn, mturk_location,
                       settings.MTURK_HIT_TYPES[FIND_HAPPY_HOUR])
            mturk_location.save()

        else:
            # Evaluate the corresponding HIT assignments for this location if all assignments are complete
            hit = conn.get_hit(mturk_location.hit_id)[0]

            if (hit.HITStatus == REVIEWABLE):
                assignments = conn.get_assignments(hit.HITId)
                deal_jsons = []
                comments = []

                for assignment in assignments:
                    if assignment.AssignmentStatus != REJECTED:
                        answers = assignment.answers[0]
                        deals_result = json.loads(
                            get_answer(answers, DEALS_RESULT))

                        if deals_result["dealsFound"]:
                            deal_jsons.append(deals_result)

                            if get_answer(answers, COMMENTS) != None:
                                comments.append(get_answer(answers, COMMENTS))

                # Require that at least half of responses to contain data
                if len(deal_jsons) > (len(assignments) / 2):
                    confirmed_deals = get_confirmed_deals(deal_jsons)

                    # If able to match any deal details, save the HIT results
                    if len(deal_jsons) >= settings.MIN_RESPONSES and len(
                            confirmed_deals) > 0:
                        comment_string = ("\n".join(comments))[:1000]
                        save_results(mturk_location.location, confirmed_deals,
                                     comment_string)

                        if mturk_location.stat != None:
                            complete_mturk_stat(mturk_location, True)

                        approve_and_dispose(conn, hit)
                        mturk_location.location.dateLastUpdated = timezone.now(
                        )
                        mturk_location.location.save()
                        mturk_location.delete()

                    # Otherwise, if max number of assignments has not been reached, extend the HIT
                    elif len(
                            assignments) < settings.MAX_ASSIGNMENTS_TO_PUBLISH:
                        extend(conn, hit, mturk_location)

                    else:
                        # Fail the HIT since we cannot exceed max number of assignments on Amazon
                        if mturk_location.stat != None:
                            complete_mturk_stat(mturk_location, False)

                        approve_and_dispose(conn, hit)
                        mturk_location.location.mturkDataCollectionFailed = True
                        mturk_location.location.dateLastUpdated = timezone.now(
                        )
                        mturk_location.location.save()
                        mturk_location.delete()

                else:
                    # Not enough people found data. Mark the HIT as no data
                    if mturk_location.stat != None:
                        complete_mturk_stat(mturk_location, False)

                    approve_and_dispose(conn, hit)
                    mturk_location.location.mturkNoDealData = True
                    mturk_location.location.dateLastUpdated = timezone.now()
                    mturk_location.location.save()
                    mturk_location.delete()
Exemplo n.º 12
0
    from django.conf import settings

import sys
from boto.mturk import connection, price
from comparisons import models
import datetime
from django.utils import timezone

from credentials.reitter import *
#from credentials.cole import *

host = "mechanicalturk.sandbox.amazonaws.com"
host = "mechanicalturk.amazonaws.com"

conn = connection.MTurkConnection(aws_access_key_id=access,
                                  aws_secret_access_key=secret,
                                  host=host)

dry_run = True
if "-r" in sys.argv:
    dry_run = False
total_bonus = 0.0
total_appr = 0


def print_totals():
    print(str(total_appr) + " workers approved.")
    print("Total bonus: $" + str(total_bonus))


def approve_by_worker(worker):
Exemplo n.º 13
0
def make_con():
    return connection.MTurkConnection(aws_access_key_id=access,
                                      aws_secret_access_key=secret,
                                      host=host)