Python boto.mturk.connection.MTurkRequestError() Examples
The following are 13
code examples of boto.mturk.connection.MTurkRequestError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
boto.mturk.connection
, or try the search function
.
Example #1
Source File: utils.py From opensurfaces with MIT License | 5 votes |
def extract_mturk_attr(result_set, attr): """ Extracts an attribute from a boto ResultSet """ if hasattr(result_set, attr): return getattr(result_set, attr) try: for r in result_set: if hasattr(r, attr): return getattr(r, attr) except TypeError: pass raise MTurkRequestError(status=0, reason='Missing %s in response' % attr)
Example #2
Source File: models.py From opensurfaces with MIT License | 5 votes |
def set_value(self, value=1, save=True): dirty = False if not self.granted: dirty = True try: get_mturk_connection().assign_qualification( qualification_type_id=self.qualification.id, worker_id=self.worker.mturk_worker_id, value=value, send_notification=True) self.granted = True self.value = value except MTurkRequestError as e: if 'QualificationAlreadyExists' in e.body: self.granted = True self.value = None else: raise if self.value != value: dirty = True get_mturk_connection().update_qualification_score( qualification_type_id=self.qualification.id, worker_id=self.worker.mturk_worker_id, value=value) self.value = value if dirty and save: self.save()
Example #3
Source File: connection.py From ampcrowd with Apache License 2.0 | 5 votes |
def expire_hit(task): crowd_config = json.loads(task.group.crowd_config) conn = get_amt_connection(crowd_config['sandbox']) try: conn.expire_hit(task.task_id) except MTurkRequestError as e: logger.debug(traceback.format_exc()) raise AMTException( "Couldn't expire HIT " + task.task_id + ": " + str(e) )
Example #4
Source File: connection.py From ampcrowd with Apache License 2.0 | 5 votes |
def disable_hit(task): crowd_config = json.loads(task.group.crowd_config) conn = get_amt_connection(crowd_config['sandbox']) try: conn.disable_hit(task.task_id) except MTurkRequestError as e: logger.debug(traceback.format_exc()) raise AMTException( "Couldn't delete HIT " + task.task_id + ": " + str(e) )
Example #5
Source File: connection.py From ampcrowd with Apache License 2.0 | 5 votes |
def assignment_exists(assignment): crowd_config = json.loads(assignment.task.group.crowd_config) conn = get_amt_connection(crowd_config['sandbox']) try: a = conn.get_assignment(assignment.assignment_id) return True except MTurkRequestError as e: logger.warn("Couldn't fetch assignment--it was probably returned.") logger.warn("Error was %s" % str(e)) logger.debug(traceback.format_exc()) return False
Example #6
Source File: connection.py From ampcrowd with Apache License 2.0 | 5 votes |
def reject_assignment(assignment, 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 rejecting it.") return try: conn.reject_assignment(assignment.assignment_id, reason) except MTurkRequestError as e: logging.debug(traceback.format_exc()) raise AMTException("Couldn't reject assignment %s, worker %s: %s" % ( assignment.assignment_id, assignment.worker.worker_id, str(e)))
Example #7
Source File: clear_hits.py From ampcrowd with Apache License 2.0 | 5 votes |
def purge_all_hits(options): conn = get_amt_connection(options.sandbox) logger.info("Fetching HITs...") hits = list(conn.get_all_hits()) logger.info("%d HITs found." % len(hits)) logger.info("Disabling all HITs...") for hit in hits: try: conn.disable_hit(hit.HITId) logger.debug("Disabled HIT %s." % hit.HITId) except MTurkRequestError as e: logger.exception("Error disabling hit %s." % hit.HITId) logger.info("Done disabling HITs.")
Example #8
Source File: test_disable_hit.py From canvas with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_disable_invalid_hit(self): self.assertRaises(MTurkRequestError, self.conn.disable_hit, 'foo')
Example #9
Source File: turk_admin.py From CAQE with MIT License | 4 votes |
def give_bonus_to_all_first_completed_trials(self, price=app.config['MTURK_FIRST_HIT_BONUS'], calculate_amt_only=False, reason=None, already_bonused_ids=set()): """ Grant bonuses for the first completed trial for each participant. Parameters ---------- price : float, optional The bonus amount to grant in dollars. Default is defined by the CAQE configuration. calculate_amt_only : bool, optional Only calculate the amount of the bonus, do not actual pay out the bonus. reason : str, optional The message to send the workers when they receive the bonus already_bonused_ids : set, optional Set of participant ids that have already been bonused Returns ------- total_bonus: float The total amount paid participants_wo_valid_asgnmts: list of caqe.models.Participant The participants who did not have valid assignments in their trial data (e.g. there must have been an error when submitting the assignment) """ if reason is None: reason = "Thanks for completing our Critical Audio Listening Task HIT. This bonus is to compensate you " \ "for the extra time needed to complete the first assignment of the HIT." total_bonus = 0 participants_wo_valid_asgnmts = [] participants = models.Participant.query.all() for p in participants: if p.id in already_bonused_ids: continue trials = p.trials.all() if len(trials) > 0: bonus_paid = False for t in trials: try: print p.id crowd_data = json.loads(t.crowd_data) assignment_id = crowd_data['assignment_id'] worker_id = p.crowd_worker_id if not calculate_amt_only: self.connection.grant_bonus(worker_id, assignment_id, Price(price), reason) total_bonus += price bonus_paid = True break except MTurkRequestError as e: print e continue if not bonus_paid: participants_wo_valid_asgnmts.append(p) return total_bonus, participants_wo_valid_asgnmts
Example #10
Source File: turk_admin.py From CAQE with MIT License | 4 votes |
def give_consistency_bonus(self, max_price=app.config['MTURK_MAX_CONSISTENCY_BONUS'], threshold=app.config['MTURK_MIN_CONSISTENCY_THRESHOLD_FOR_BONUS'], calculate_amt_only=False, reason=None, already_bonused_ids=set()): """ Grant bonuses based on ratings consistency. Bonus calculated by .. math:: ((consistency - threshold) / (1.0 - threshold)) * max\_price * (consistency > threshold)) Parameters ---------- max_price : float, optional The maximum bonus amount to grant in dollars. Default is defined by the CAQE configuration. threshold : bool Consistency must exceed this value before a bonus is paid out. Default is defined by the CAQE configuration. calculate_amt_only : bool, optional Only calculate the amount of the bonus, do not actual pay out the bonus. reason : str, optional The message to send the workers when they receive the bonus already_bonused_ids : set, optional Set of participant ids that have already been bonused Returns ------- total_bonus : float The total amount paid participants_wo_valid_asgnmts : list of caqe.models.Participant The participants who did not have valid assignments in their trial data (e.g. there must have been an error when submitting the assignment) """ if reason is None: reason = "Thanks for completing our Critical Audio Listening Task HIT. This bonus is to award you for " \ "your consistency in ratings during the task." total_bonus = 0 trials_wo_valid_asgnmts = [] trials = models.Trial.query.all() for t in trials: if t.id in already_bonused_ids: continue try: crowd_data = json.loads(t.crowd_data) data = json.loads(t.data) assignment_id = crowd_data['assignment_id'] worker_id = t.participant.crowd_worker_id consistency = calculate_tsr(data['rating'])[0] price = round( abs(((consistency - threshold) / (1.0 - threshold)) * max_price * (consistency > threshold)), 2) if not calculate_amt_only and price > 0.0: print price self.connection.grant_bonus(worker_id, assignment_id, Price(price), reason) total_bonus += price except MTurkRequestError as e: print e trials_wo_valid_asgnmts.append(t) return total_bonus, trials_wo_valid_asgnmts
Example #11
Source File: mturk_depth_api_lsp.py From rel_3d_pose with MIT License | 4 votes |
def payTurkersAssignments(): _mtc = MTurkConnection( host = _host ) rejected = 0 approved = 0 failed_rejected = 0 failed_approved = 0 failed_approved_list = [] failed_rejected_list = [] return_dict = processAssignments( save=False ) # list with the assignments that are not rejected nor flagged _good_assignments = return_dict['_good_assignments'] for ass in _good_assignments: try: _mtc.approve_assignment( ass['assignment_id'] ) approved += 1 except MTurkRequestError: failed_approved += 1 failed_approved_list.append( ass ) # list containing the assignments that were flagged by the turkers _flagged_assignments = return_dict['_flagged_assignments'] for ass in _flagged_assignments: try: _mtc.approve_assignment( ass['assignment_id'] ) approved += 1 except MTurkRequestError: failed_approved += 1 failed_approved_list.append( ass ) # list with the assignments were something inexpected on my side happened _error_assignments = return_dict['_error_assignments'] for ass in _error_assignments: try: _mtc.approve_assignment( ass['assignment_id'] ) approved += 1 except MTurkRequestError: failed_approved += 1 failed_approved_list.append( ass ) # list with the assignments that were rejected _rejected_assignments = return_dict['_rejected_assignments'] for ass in _rejected_assignments: try: _mtc.reject_assignment( ass['assignment_id'] ) rejected += 1 except MTurkRequestError: failed_rejected += 1 failed_rejected_list.append( ass ) print "Approved: [%d]"%approved print "Rejected: [%d]"%rejected print "Not Approved: [%d]"%failed_approved print "Not Rejected: [%d]"%failed_rejected return (failed_approved_list, failed_rejected_list)
Example #12
Source File: mturk_depth_api_human.py From rel_3d_pose with MIT License | 4 votes |
def payTurkersAssignments(): _mtc = MTurkConnection( host = _host ) rejected = 0 approved = 0 failed_rejected = 0 failed_approved = 0 failed_approved_list = [] failed_rejected_list = [] return_dict = processAssignments( save=False ) # list with the assignments that are not rejected nor flagged _good_assignments = return_dict['_good_assignments'] for ass in _good_assignments: try: _mtc.approve_assignment( ass['assignment_id'] ) approved += 1 except MTurkRequestError: failed_approved += 1 failed_approved_list.append( ass ) # list containing the assignments that were flagged by the turkers _flagged_assignments = return_dict['_flagged_assignments'] for ass in _flagged_assignments: try: _mtc.approve_assignment( ass['assignment_id'] ) approved += 1 except MTurkRequestError: failed_approved += 1 failed_approved_list.append( ass ) # list with the assignments were something inexpected on my side happened _error_assignments = return_dict['_error_assignments'] for ass in _error_assignments: try: _mtc.approve_assignment( ass['assignment_id'] ) approved += 1 except MTurkRequestError: failed_approved += 1 failed_approved_list.append( ass ) # list with the assignments that were rejected _rejected_assignments = return_dict['_rejected_assignments'] for ass in _rejected_assignments: try: _mtc.reject_assignment( ass['assignment_id'] ) rejected += 1 except MTurkRequestError: failed_rejected += 1 failed_rejected_list.append( ass ) print "Approved: [%d]"%approved print "Rejected: [%d]"%rejected print "Not Approved: [%d]"%failed_approved print "Not Rejected: [%d]"%failed_rejected return (failed_approved_list, failed_rejected_list)
Example #13
Source File: connection.py From ampcrowd with Apache License 2.0 | 4 votes |
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