本文整理匯總了Python中boto.mturk.connection.MTurkRequestError方法的典型用法代碼示例。如果您正苦於以下問題:Python connection.MTurkRequestError方法的具體用法?Python connection.MTurkRequestError怎麽用?Python connection.MTurkRequestError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類boto.mturk.connection
的用法示例。
在下文中一共展示了connection.MTurkRequestError方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: extract_mturk_attr
# 需要導入模塊: from boto.mturk import connection [as 別名]
# 或者: from boto.mturk.connection import MTurkRequestError [as 別名]
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)
示例2: set_value
# 需要導入模塊: from boto.mturk import connection [as 別名]
# 或者: from boto.mturk.connection import MTurkRequestError [as 別名]
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()
示例3: expire_hit
# 需要導入模塊: from boto.mturk import connection [as 別名]
# 或者: from boto.mturk.connection import MTurkRequestError [as 別名]
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)
)
示例4: disable_hit
# 需要導入模塊: from boto.mturk import connection [as 別名]
# 或者: from boto.mturk.connection import MTurkRequestError [as 別名]
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)
)
示例5: assignment_exists
# 需要導入模塊: from boto.mturk import connection [as 別名]
# 或者: from boto.mturk.connection import MTurkRequestError [as 別名]
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
示例6: reject_assignment
# 需要導入模塊: from boto.mturk import connection [as 別名]
# 或者: from boto.mturk.connection import MTurkRequestError [as 別名]
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)))
示例7: purge_all_hits
# 需要導入模塊: from boto.mturk import connection [as 別名]
# 或者: from boto.mturk.connection import MTurkRequestError [as 別名]
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.")
示例8: test_disable_invalid_hit
# 需要導入模塊: from boto.mturk import connection [as 別名]
# 或者: from boto.mturk.connection import MTurkRequestError [as 別名]
def test_disable_invalid_hit(self):
self.assertRaises(MTurkRequestError, self.conn.disable_hit, 'foo')
示例9: give_bonus_to_all_first_completed_trials
# 需要導入模塊: from boto.mturk import connection [as 別名]
# 或者: from boto.mturk.connection import MTurkRequestError [as 別名]
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
示例10: give_consistency_bonus
# 需要導入模塊: from boto.mturk import connection [as 別名]
# 或者: from boto.mturk.connection import MTurkRequestError [as 別名]
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
示例11: payTurkersAssignments
# 需要導入模塊: from boto.mturk import connection [as 別名]
# 或者: from boto.mturk.connection import MTurkRequestError [as 別名]
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)
示例12: create_hit
# 需要導入模塊: from boto.mturk import connection [as 別名]
# 或者: from boto.mturk.connection import MTurkRequestError [as 別名]
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