Esempio n. 1
0
import argparse, json

from boto.mturk.price import Price
from boto.mturk.question import HTMLQuestion
from boto.mturk.connection import MTurkRequestError

import os
import simpleamt
import sys

if __name__ == '__main__':
  parser = argparse.ArgumentParser(parents=[simpleamt.get_parent_parser()])
  parser.add_argument('--hit_properties_file', type=argparse.FileType('r'))
  parser.add_argument('--html_template')
  parser.add_argument('--input_json_file', type=argparse.FileType('r'))
  args = parser.parse_args()

  mtc = simpleamt.get_mturk_connection_from_args(args)

  hit_properties = json.load(args.hit_properties_file)
  hit_properties['reward'] = Price(hit_properties['reward'])
  simpleamt.setup_qualifications(hit_properties, mtc)

  frame_height = hit_properties.pop('frame_height')
  env = simpleamt.get_jinja_env(args.config)
  template = env.get_template(args.html_template)

  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):
Esempio n. 2
0
import argparse

import simpleamt

if __name__ == '__main__':
    parser = argparse.ArgumentParser(parents=[simpleamt.get_parent_parser()],
                                     description="Delete HITs")
    parser.add_argument('--hit_id')
    args = parser.parse_args()
    mtc = simpleamt.get_mturk_connection_from_args(args)
    hit_id = args.hit_id

    print('This will delete HIT with ID: %s with sandbox=%s' %
          (hit_id, str(args.sandbox)))
    print 'Continue?'
    s = raw_input('(Y/N): ')
    if s == 'Y' or s == 'y':
        try:
            mtc.disable_hit(hit_id)
        except:
            print 'Failed to disable: %s' % (hit_id)
    else:
        print 'Aborting'
Esempio n. 3
0
import argparse, json, sys
import simpleamt
def process_assignments(mtc, hit_id):  results = []  assignments = mtc.get_assignments(hit_id) for a in assignments: if a.AssignmentStatus in ['Approved', 'Submitted']: try:        output = json.loads(a.answers[0][0].fields[0]) except ValueError as e: print >> sys.stderr, ('Bad data from assignment %s (worker %s)' % (a.AssignmentId, a.WorkerId)) continue      results.append({ 'assignment_id': a.AssignmentId, 'hit_id': hit_id, 'worker_id': a.WorkerId, 'output': json.loads(a.answers[0][0].fields[0]),      }) return results
if __name__ == '__main__':  parser = argparse.ArgumentParser(parents=[simpleamt.get_parent_parser()])  args = parser.parse_args()  mtc = simpleamt.get_mturk_connection_from_args(args)   results = []
 if args.hit_ids_file is None: for hit in mtc.get_all_hits():      results += process_assignments(mtc, hit.HITId) else: with open(args.hit_ids_file, 'r') as f: for line in f:        hit_id = line.strip()        results += process_assignments(mtc, hit_id)
 for assignment_result in results: print json.dumps(assignment_result)
Esempio n. 4
0
import argparse, json
from boto.mturk.price import Pricefrom boto.mturk.question import HTMLQuestionfrom boto.mturk.connection import MTurkRequestError
import simpleamt
if __name__ == '__main__':  parser = argparse.ArgumentParser(parents=[simpleamt.get_parent_parser()])  parser.add_argument('--hit_properties_file', type=argparse.FileType('r'))  parser.add_argument('--html_template')  parser.add_argument('--input_json_file', type=argparse.FileType('r'))  args = parser.parse_args()
  mtc = simpleamt.get_mturk_connection_from_args(args)
  hit_properties = json.load(args.hit_properties_file)  hit_properties['reward'] = Price(hit_properties['reward'])  simpleamt.setup_qualifications(hit_properties)
  frame_height = hit_properties.pop('frame_height')  env = simpleamt.get_jinja_env(args.config)  template = env.get_template(args.html_template)
  hit_ids = [] 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: print 'Trying to launch HIT %d' % (i + 1)        boto_hit = mtc.create_hit(**hit_properties)        launched = True except MTurkRequestError as e: print e    hit_id = boto_hit[0].HITId    hit_ids.append(hit_id)
 # TODO: Should the hit ids file be mandatory? if args.hit_ids_file is not None: with open(args.hit_ids_file, 'w') as f: for hit_id in hit_ids:        f.write('%s\n' % hit_id)
Esempio n. 5
0
import argparse
import simpleamt

if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        parents=[simpleamt.get_parent_parser()],
        description="Show your AMT account balance.")
    args = parser.parse_args()
    mtc = simpleamt.get_mturk_connection_from_args(args)
    print(mtc.get_account_balance()['AvailableBalance'])
Esempio n. 6
0
import argparse
import simpleamt
if __name__ == '__main__':  parser = argparse.ArgumentParser(parents=[simpleamt.get_parent_parser()], description="Delete HITs")  parser.add_argument('--all', action='store_true', default=False)  args = parser.parse_args()
 if (args.hit_ids_file is not None) == args.all: print 'Must specify exactly one of --hit_ids_file or --all' import sys; sys.exit(1)
  mtc = simpleamt.get_mturk_connection_from_args(args)
 if args.all:    hit_ids = [] for hit in mtc.get_all_hits():      hit_ids.append(hit.HITId) else: with open(args.hit_ids_file, 'r') as f:      hit_ids = [line.strip() for line in f]
 print ('This will delete %d HITs with sandbox=%s' % (len(hit_ids), str(args.sandbox))) print 'Continue?'  s = raw_input('(Y/N): ') if s == 'Y' or s == 'y': for hit_id in hit_ids:      mtc.disable_hit(hit_id) else: print 'Aborting'
import argparsefrom collections import Counter
import simpleamt

if __name__ == '__main__':  parser = argparse.ArgumentParser(parents=[simpleamt.get_parent_parser()])  args = parser.parse_args()
  mtc = simpleamt.get_mturk_connection_from_args(args)
 if args.hit_ids_file is None:    parser.error('Must specify hit_ids_file')
 with open(args.hit_ids_file, 'r') as f:    hit_ids = [line.strip() for line in f]   counter = Counter() for idx, hit_id in enumerate(hit_ids):    hit = mtc.get_hit(hit_id)[0]    total = int(hit.MaxAssignments)    completed = 0 for a in mtc.get_assignments(hit_id):      s = a.AssignmentStatus if s == 'Submitted' or s == 'Approved':        completed += 1 print 'HIT %d/%d: %d/%d assignments completed.' % (idx+1, len(hit_ids), completed, total)    counter.update([(completed, total)])
 for (completed, total), count in counter.most_common(): print ' completed %d / %d, count: %d' % (completed, total, count)