def create_hit(conn, frame_height=None, title=None, description=None, max_assignments=None, duration=None, lifetime=None, reward=None, **kwargs): """ Create a hit on mturk with @question in a @batch using @mturk_connection """ logger.debug("Creating HIT(%s)", title) question = ExternalQuestion(MTURK_URL, frame_height) response = conn.create_hit(Question=question.get_as_xml(), Title=title, Description=description, MaxAssignments=int(max_assignments), AssignmentDurationInSeconds=int(duration), LifetimeInSeconds=int(lifetime), Reward=reward) logger.debug([ "HIT created: ", response['HIT']['HITTypeId'], response['HIT']['HITId'] ]) return response['HIT']['HITTypeId'], response['HIT']['HITId']
def create_hits(self, num_hits, configuration=None, hit_type_id=None): """ Create `num_audio_hits` according to the parameters specified in `hit_params` Parameters ---------- num_hits: int configuration: dict hit_type_id: int, optional Returns ------- None """ if configuration is None: configuration = app.config if hit_type_id is None: hit_type_id = self.hit_type_id question = ExternalQuestion( configuration['MTURK_QUESTION_URL'], frame_height=configuration['MTURK_FRAME_HEIGHT']) for _i in range(num_hits): self.connection.create_hit_with_hit_type( HITTypeId=hit_type_id, MaxAssignments=configuration['MTURK_MAX_ASSIGNMENTS'], LifetimeInSeconds=configuration['MTURK_LIFETIME_IN_SECONDS'], Question=question.get_as_xml())
def create_hit(task_settings, conn=None, url=settings.URL): """ Create a hit on mturk with @question in a @batch using @mturk_connection """ assert "Title" in task_settings assert "Description" in task_settings assert "MaxAssignments" in task_settings assert "Reward" in task_settings assert "AssignmentDurationInSeconds" in task_settings assert "LifetimeInSeconds" in task_settings if conn is None: conn = _CONN logger.debug("Creating HIT") question = ExternalQuestion(url, task_settings.get("FrameHeight", 800)) response = conn.create_hit(Question=question.get_as_xml(), Title=task_settings["Title"], Description=task_settings["Description"], MaxAssignments=task_settings["MaxAssignments"], AssignmentDurationInSeconds=task_settings["AssignmentDurationInSeconds"], LifetimeInSeconds=task_settings["LifetimeInSeconds"], Reward=task_settings["Reward"], QualificationRequirements=task_settings.get("QualificationRequirements"), ) logger.debug("HIT created (%s, %s).", response['HIT']['HITTypeId'], response['HIT']['HITId']) return response['HIT']
def create_task(client): question = ExternalQuestion(os.environ['HEROKU_URL'], frame_height=540) new_hit = client.create_hit( Title='Finish the game (Move with WASD or arrow keys).', Description='It might take approximately 30 secs to load the page.', Keywords='question, answer, research, game, grid', Reward='0.15', MaxAssignments=100, LifetimeInSeconds=172800, AssignmentDurationInSeconds=1200, AutoApprovalDelayInSeconds=14400, Question=question.get_as_xml(), # <--- this does the trick ) print("HITID = " + new_hit['HIT']['HITId'])
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)
def external_question(self): q = ExternalQuestion( external_url= "http://www.kernel.org/pub/software/scm/git/docs/everyday.html", frame_height=200) # keywords = ['image', 'filter', 'google'] # #create hit without id # create_hit_rs = self.connect.create_hit( question=q, lifetime=60 * 65, max_assignments=2, title="Google Image Filter", keywords=keywords, reward=0.05, duration=60 * 6, approval_delay=60 * 60, annotation='An annotation from boto external question test', response_groups=['Minimal', 'HITDetail', 'HITQuestion', 'HITAssignmentSummary', ], qualifications=self.qualifications ) #create hit with id if self.hit_type_id: try: hit = self.connect.create_hit( hit_type=self.hit_type_id, question=q, lifetime=datetime.timedelta(days=14), max_assignments=1, annotation="This is a annotation") except MTurkRequestError as e: print "register hit type error:\n status: %s reason: %s\n body: %s" % ( e.status, e.reason, e.body) else: print "hit id: %s " % hit[0].HITId print "hit type id: %s " % hit[0].HITTypeId
def get_form(app_name, example_id, **options): url = "https://{}.herokuapp.com/example/{}".format(app_name, example_id) if options: url = url + '?' + '&'.join( ['{}={}'.format(k, v) for k, v in options.items()]) question_form = ExternalQuestion(url, 800) return question_form
def create_hit(self, url, extra_settings): """Eventually, this should take a TEMPLATE and a dictionary of INPUT data that's put into that template. This function would then create an HTML file locally (assuming we're running on a web server) by replacing template {tags} with input values, and then send the URL to the newly created page to MTurk.""" settings = self.default_settings.copy() settings['LifetimeInSeconds'] = extra_settings.get('lifetime', DAY) settings['AssignmentDurationInSeconds'] = extra_settings.get( 'duration', 10 * MINUTE) settings['AutoApprovalDelayInSeconds'] = extra_settings.get( 'approval_delay', DAY) settings['Title'] = extra_settings.get('title', 'Unknown') settings['Description'] = extra_settings.get('description', 'Unknown') settings['Keywords'] = ','.join(extra_settings.get('keywords', [])) settings['Reward'] = str(extra_settings.get('reward', '0.01')) settings['QualificationRequirements'] = extra_settings.get( 'qualifications', []) settings['MaxAssignments'] = extra_settings.get('max_assignments', 1) settings["Question"] = ExternalQuestion( url, extra_settings.get('height', 700)).get_as_xml() hit = self.c.create_hit(**settings)["HIT"] return hit["HITId"], hit["HITGroupId"]
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"])
def configure_hit(self): # Configure portal experimentPortalURL = self.config.get('HIT Configuration', 'question_url') frameheight = 600 mturkQuestion = ExternalQuestion(experimentPortalURL, frameheight) # Qualification: quals = Qualifications() approve_requirement = self.config.get('HIT Configuration', 'Approve_Requirement') quals.add( PercentAssignmentsApprovedRequirement("GreaterThanOrEqualTo", approve_requirement)) if self.config.getboolean('HIT Configuration', 'US_only'): quals.add(LocaleRequirement("EqualTo", "US")) # Specify all the HIT parameters self.paramdict = dict( hit_type = None, question = mturkQuestion, lifetime = datetime.timedelta(hours=self.config.getfloat('HIT Configuration', 'HIT_lifetime')), max_assignments = self.config.getint('HIT Configuration', 'max_assignments'), title = self.config.get('HIT Configuration', 'title'), description = self.config.get('HIT Configuration', 'description'), keywords = self.config.get('HIT Configuration', 'keywords'), reward = self.config.getfloat('HIT Configuration', 'reward'), duration = datetime.timedelta(hours=self.config.getfloat('HIT Configuration', 'duration')), approval_delay = None, questions = None, qualifications = quals )
def post(self): experiment = Experiment() experiment.owner = users.get_current_user() experiment.params = self.reader.blob_info.key() experiment.url = self.data['external_hit_url'] key = experiment.put() url = '%s/task?%s' % (self.request.host_url, urllib.urlencode({'key': key})) question = ExternalQuestion(external_url=url, frame_height=800) response = mturk.create_hit(self.connection, question, self.data) assert (response.status == True) if response[0].IsValid == 'True': experiment.task_id = response[0].HITId experiment.put() link = Struct(href='/', text='Create another experiment') self.render('templates/info.htm', { 'message': 'Created HIT: ' + response[0].HITId, 'link': link }) else: self._render_error('Error: could not create HIT')
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 configure_hit(self, hit_config): # configure question_url based on the id experimentPortalURL = hit_config['ad_location'] frameheight = 600 mturkQuestion = ExternalQuestion(experimentPortalURL, frameheight) # Qualification: quals = Qualifications() approve_requirement = hit_config['approve_requirement'] quals.add( PercentAssignmentsApprovedRequirement("GreaterThanOrEqualTo", approve_requirement)) if hit_config['us_only']: quals.add(LocaleRequirement("EqualTo", "US")) # Specify all the HIT parameters self.paramdict = dict(hit_type=None, question=mturkQuestion, lifetime=hit_config['lifetime'], max_assignments=hit_config['max_assignments'], title=hit_config['title'], description=hit_config['description'], keywords=hit_config['keywords'], reward=hit_config['reward'], duration=hit_config['duration'], approval_delay=None, questions=None, qualifications=quals)
def send_task(self): if self.osm_from is not None and self.osm_to is not None and self.reference is not None: title = 'Find the corresponding product' description = ('Select the most appropriate answer') keywords = 'images, selecting, products, matching, match, selection' self.save_task() question = ExternalQuestion( 'http://www.dalliz.com/mturk/key/%s' % (self.key), 1106) qualifications = Qualifications() qualifications.add( PercentAssignmentsApprovedRequirement('GreaterThanOrEqualTo', 95)) #--------------- CREATE THE HIT ------------------- a = self.mtc.create_hit( question=question, title=title, description=description, keywords=keywords, reward=0.01, max_assignments=10, approval_delay=datetime.timedelta(seconds=3600 * 24 * 30), # auto-approve timeout duration=datetime.timedelta(seconds=3600 * 24 * 30))
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()
def create_hit(cfg): mtc = connect_mtc(cfg) tc = cfg['turkConfig'] quals = boto.mturk.qualification.Qualifications() if tc['live']: for qual in tc['quals']: quals.add(getattr(boto.mturk.qualification, qual[0])(*qual[1:])) # create question question = ExternalQuestion(tc['questionUrl'], tc['questionFrameHeight']) r = mtc.create_hit(question=question, max_assignments=tc['maxAssignments'], title=tc['hitTitle'], description=tc['hitDescription'], keywords=tc['hitKeywords'], duration=tc['hitDurationSec'], reward=tc['hitRewardDollar'], qualifications=quals) mtc.close() hitId = r[0].HITId return hitId
def configure_hit(self, hit_config): ''' Configure HIT ''' # configure question_url based on the id experiment_portal_url = hit_config['ad_location'] frame_height = 600 mturk_question = ExternalQuestion(experiment_portal_url, frame_height) # Qualification: quals = Qualifications() approve_requirement = hit_config['approve_requirement'] quals.add( PercentAssignmentsApprovedRequirement("GreaterThanOrEqualTo", approve_requirement)) if hit_config['us_only']: quals.add(LocaleRequirement("EqualTo", "US")) # Create a HIT type for this HIT. hit_type = self.mtc.register_hit_type(hit_config['title'], hit_config['description'], hit_config['reward'], hit_config['duration'], keywords=hit_config['keywords'], approval_delay=None, qual_req=quals)[0] # Check the config file to see if notifications are wanted. config = PsiturkConfig() config.load_config() try: url = config.get('Server Parameters', 'notification_url') all_event_types = [ "AssignmentAccepted", "AssignmentAbandoned", "AssignmentReturned", "AssignmentSubmitted", "HITReviewable", "HITExpired", ] self.mtc.set_rest_notification(hit_type.HITTypeId, url, event_types=all_event_types) except: pass # Specify all the HIT parameters self.param_dict = dict(hit_type=hit_type.HITTypeId, question=mturk_question, lifetime=hit_config['lifetime'], max_assignments=hit_config['max_assignments'], questions=None, response_groups=[ 'Minimal', 'HITDetail', 'HITQuestion', 'HITAssignmentSummary' ])
def create_external_question(self, task, frame_height=800): task_hash = Hashids(salt=settings.SECRET_KEY, min_length=settings.ID_HASH_MIN_LENGTH) task_id = task_hash.encode(task) url = self.host + '/mturk/task/?taskId=' + task_id question = ExternalQuestion(external_url=url, frame_height=frame_height) return question
def create_url_hit(self, params): """ creates a HIT for an external question with a specified URL :param params a dict of the HIT parameters. must contain a "url" parameter :return the created HIT object """ question = ExternalQuestion(params["url"], params["frame_height"]) return self._create_hit(params, question=question)
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 publish_hit(credentials, isSandbox, ename, num_hits, lvlset, adminToken, db, mode, no_ifs, individual, with_new_var_powerup, mc=None, email=None, maxlvls=None, colSwap=False, replay=False): title = "Play a Math Puzzle Game For Science!" max_assignments = 1 keywords = "game, math, programming" description = \ """ NOTE: PLEASE DON'T ACCEPT MORE THAN ONE HIT AT A TIME! First finish your current HIT before looking for others!\n """ + \ """Help us evaluate our verification game InvGen! Each level is structured as a math puzzle, where you try to come up with correct expressions. Your work directly helps with the verification of programs! This HIT involves playing at least two non-tutorial levels of our game. Played it before? Come play again! You will bypass the tutorial and get new levels! New player? Come try it out! We aim to pay about $10/hr. More specifically: (a) $1.50 for the HIT, which involves playing the game for at least 2 non-tutorial levels (b) $1.50 bonus for doing the tutorial, which you only do the first time (c) $0.75 bonus for each non-tutorial level you pass beyond two.""" mastersQualType = "2ARFPLSP75KLA8M8DH1HTEQVJT3SY6" if isSandbox else \ "2F1QJWKUDD8XADTFD2Q0G6UTO95ALH" quals = [] if isSandbox else\ [ NumberHitsApprovedRequirement("GreaterThanOrEqualTo", 1000), PercentAssignmentsApprovedRequirement("GreaterThanOrEqualTo", 97), Requirement(mastersQualType, "Exists") ] if mc is None: mc = connect(credentials, isSandbox) balance = mc.get_account_balance() print("Balance:", balance[0]) exp = Experiment(ename, True) print("Running under experiment", ename) for i in range(num_hits): port = get_unused_port() srid = exp.create_unique_server_run_id() p = start_server(port, ename, srid, lvlset, adminToken, db, email, maxlvls, colSwap, replay) print("Started server run", srid, "on port", port, "with pid", p.pid) start_url =\ "https://zoidberg.ucsd.edu:{0}/mturk_landing.html?mode=" + mode if (no_ifs): start_url += "&noifs" if individual: start_url += "&individual=1" if with_new_var_powerup: start_url += "&nvpower=1" q = ExternalQuestion(start_url.format(port), 1024) kind = "ExternalQuestion" r = mc.create_hit(question=q, lifetime=timedelta(7), max_assignments=max_assignments, title=title, description=description, keywords=keywords, reward=HIT_REWARD, duration=timedelta(0, 45*60), qualifications=Qualifications(quals)) assert len(r) == 1 print("Created", kind, "HIT", r[0].HITId) exp.add_session(ServerRun(srid, r[0].HITId, p.pid, port)) return exp
def create_hit(treatment, max_assignment=12, frame_height=800, reward=0.5, sandbox=True): url = f"https://tube.ddns.net/start/{treatment}/?adapter=mturk" # <-- this is my website mturk = get_mturk_client(sandbox) qualificationRequirements = [ { "QualificationTypeId": "000000000000000000L0", "Comparator": "GreaterThanOrEqualTo", "IntegerValues": [80], "RequiredToPreview": False, "ActionsGuarded": "Accept" }, { "QualificationTypeId": "00000000000000000071", "Comparator": "EqualTo", "LocaleValues": [{ "Country": "US" }], "RequiredToPreview": False, "ActionsGuarded": "Accept" }, ] if sandbox: qualificationRequirements = [] question = ExternalQuestion(url, frame_height=frame_height) new_hit = mturk.create_hit( Title='The Ultimatum Bargaining Experiment', Description= 'Take part on an intresting experiment about human behaviour', Keywords='survey, bargaining, experiment', Reward='0.5', MaxAssignments=max_assignment, LifetimeInSeconds=7 * 24 * 3600, AssignmentDurationInSeconds=60 * 30, AutoApprovalDelayInSeconds=6 * 24 * 3600, Question=question.get_as_xml(), # <--- this does the trick QualificationRequirements=qualificationRequirements, ) click.echo(f"New hit created: {new_hit}") return new_hit
def test(): q = ExternalQuestion(external_url="http://websort.net/s/F3481C", frame_height=800) conn = MTurkConnection(host='mechanicalturk.sandbox.amazonaws.com') keywords=['boto', 'test', 'doctest'] qualifications = Qualifications() qualifications.add(PercentAssignmentsApprovedRequirement(comparator="GreaterThan", integer_value="95")) create_hit_rs = conn.create_hit(question=q, lifetime=60*65, max_assignments=2, title="Boto External Question Test", keywords=keywords, reward = 0.05, duration=60*6, approval_delay=60*60, annotation='An annotation from boto external question test', qualifications=qualifications) assert(create_hit_rs.status == True) print create_hit_rs.HITTypeId
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 test_locale_qualification_in_notin(self): self.set_http_response(status_code=200, body=MOCK_SERVER_RESPONSE) q = ExternalQuestion(external_url="http://samplesite", frame_height=800) keywords = ['boto', 'test', 'doctest'] title = "Boto External Question Test" annotation = 'An annotation from boto external question test' qualifications = Qualifications() test_requirement1 = LocaleRequirement(comparator='In', locale=[('US', 'CA')]) test_requirement2 = LocaleRequirement(comparator='NotIn', locale=[('US', 'WA'), 'CA']) qualifications.add(test_requirement1) qualifications.add(test_requirement2) create_hit_rs = self.service_connection.create_hit( question=q, lifetime=60 * 65, max_assignments=2, title=title, keywords=keywords, reward=0.05, duration=60 * 6, approval_delay=60 * 60, annotation=annotation, qualifications=qualifications) self.assert_request_parameters( { 'QualificationRequirement.1.Comparator': 'In', 'QualificationRequirement.1.LocaleValue.1.Country': 'US', 'QualificationRequirement.1.LocaleValue.1.Subdivision': 'CA', 'QualificationRequirement.1.QualificationTypeId': '00000000000000000071', 'QualificationRequirement.2.Comparator': 'NotIn', 'QualificationRequirement.2.LocaleValue.1.Country': 'US', 'QualificationRequirement.2.LocaleValue.1.Subdivision': 'WA', 'QualificationRequirement.2.LocaleValue.2.Country': 'CA', 'QualificationRequirement.2.QualificationTypeId': '00000000000000000071' }, ignore_params_values=[ 'AWSAccessKeyId', 'SignatureVersion', 'Timestamp', 'Title', 'Question', 'AssignmentDurationInSeconds', 'RequesterAnnotation', 'Version', 'LifetimeInSeconds', 'AutoApprovalDelayInSeconds', 'Reward.1.Amount', 'Description', 'MaxAssignments', 'Reward.1.CurrencyCode', 'Keywords', 'Operation' ]) self.assertEquals(create_hit_rs.status, True)
def PostHits_loop(): # To post a HIT, first connect to Turk using our access codes: # The ACCESS_ID and SECRET_KEY are loaded before this function is called # (e.g., from alvarezlab import * ); mtc = MTurkConnection(aws_access_key_id=ACCESS_ID, aws_secret_access_key=SECRET_KEY, host=HOST) for x in range(startHSet, endHSet + 1): HSet = x urlForHIT = "https://scorsese.wjh.harvard.edu/turk/experiments/cfm/Search10/index_cmtrial_Search10.html?HSetNum=%d" % HSet # Now lets setup a structure for our external HIT. We need the URL we want to be # shown within the Turk window and also how tall we want the Turk iframe to be: q = ExternalQuestion(external_url=urlForHIT, frame_height=frameHeight) # And any qualifications we want people to have: qualifications = mtqu.Qualifications() qualifications.add( mtqu.PercentAssignmentsApprovedRequirement( 'GreaterThanOrEqualTo', percentAssignmentsApprovedRequirement)) qualifications.add(mtqu.LocaleRequirement("EqualTo", localeRequirement)) if (qualificationID != "NONE"): qualifications.add( mtqu.Requirement(qualificationID, "EqualTo", 1, notifyWorkerOfQualification)) # Post: theHIT = mtc.create_hit( question=q, lifetime=minToSec(minutesBeforeHitExpires), max_assignments=numAssignmentsToPost, title=titleForWorkers, description=descriptionForWorkers, keywords=keywordsForWorkers, qualifications=qualifications, reward=pay, duration=minToSec(minutesForUsersToFinish), approval_delay=minToSec(minutesBeforeAutoApproved), annotation=projectNameForRequesters) # get more info about the hit hit = mtc.get_hit(theHIT[0].HITId) # Print out the HIT's ID if all went well: # pprint(vars(hit[0])) # print "Experiment info:" # print HOST print "preview hit in HSet ", HSet, ": " # print urlForHIT, "\n" # print "HITId" # print theHIT[0].HITId, "\n" print PREVIEW + "?groupId=" + hit[0].HITGroupId, "\n"
def create_batch(self, properties, variables_list, maxhits=None): '''Create a new batch of HITs. Return (list of hit_ids, hit_type_id). 'variables_list' is a list of dicts {key1: value1, key2: value2, ...} Strings of the form '${key1}' in question and annotation will be replaced with value1 and so on. ''' if maxhits: variables_list = variables_list[:maxhits] if raw_input('Creating %d HITs. Continue? (y/N) ' % len(variables_list)).lower() != 'y': return # Register the HIT type if 'hittypeid' in properties: hit_type_id = properties['hittypeid'] else: result = self.mtc.register_hit_type( properties['title'], properties['description'], properties['reward'], properties['assignmentduration'], properties['keywords'], properties['autoapprovaldelay'], properties['qualifications']) hit_type_id = result[0].HITTypeId # Reading parameters for individual HITs hit_ids = [] for i, variables in enumerate(variables_list): question = ExternalQuestion( self._replace_variables(properties['url'], variables), properties['frameheight']) annotation = self._replace_variables( properties['annotation'], variables) if isinstance(properties['assignments'], int): max_assignments = properties['assignments'] else: max_assignments = properties['assignments'][i] if max_assignments <= 0: print '(%5d/%5d)' % (i + 1, len(variables_list)), print 'Skipped because assignments <= 0' continue result = self.mtc.create_hit( hit_type=hit_type_id, question=question, annotation=annotation, lifetime=properties['hitlifetime'], max_assignments=max_assignments) hit_id = result[0].HITId hit_ids.append(hit_id) assert hit_type_id == result[0].HITTypeId print '(%5d/%5d)' % (i + 1, len(variables_list)), print 'Created HIT', hit_id print ('DONE! %d HITs created. Preview the HITs here:' % len(variables_list)) if self.sandbox: print MTurkWrapper.PREVIEW_SANDBOX + hit_type_id else: print MTurkWrapper.PREVIEW_REAL + hit_type_id return hit_ids, hit_type_id
def postJob(task_id): hit = db.session.query(Task).filter(Task.id == task_id).first() ############################################################## #source: https://github.com/numaer/psyturk/blob/master/hits.py ############################################################# connection.create_hit_with_hit_type(HITTypeId=hit.HIT_Type_id, MaxAssignments=1, LifetimeInSeconds=hit.hit_expiry, Question=ExternalQuestion( hit.task_url, 800).get_as_xml())
def create_hit(self, ex_uids): """Create a HIT involving the specified Examples. Args: ex_uids (list[str]): a list of Example UIDs Returns: str: HITId """ param_str = urllib.parse.urlencode({'exampleUIDs': ','.join(ex_uids)}) custom_url = '?'.join([self._url, param_str]) external_question = ExternalQuestion(custom_url, frame_height=500) return super(self, ExternalQuestionTask).create_hit(external_question)