Last active
April 24, 2018 01:14
-
-
Save fredcallaway/410aba2642cb037d06f4dbd6f042a8b3 to your computer and use it in GitHub Desktop.
Approves and bonuses all participants in a psiturk experiment.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
""" | |
Approves and bonuses (if applicable) all workers in the database for the | |
current psiturk project. | |
""" | |
from __future__ import print_function | |
from psiturk.amt_services_wrapper import MTurkServicesWrapper, Participant, init_db, db_session | |
wrapper = MTurkServicesWrapper() | |
amt = wrapper.amt_services | |
config = wrapper.config | |
init_db() | |
class ApproveError(Exception): pass | |
class BonusError(Exception): pass | |
def approve(participant): | |
success = amt.approve_worker(participant.assignmentid) | |
if success: | |
participant.status = 5 | |
db_session.add(participant) | |
db_session.commit() | |
else: | |
raise ApproveError() | |
def bonus(participant): | |
if config.has_option('Shell Parameters', 'bonus_message'): | |
reason = config.get('Shell Parameters', 'bonus_message') | |
else: | |
reason = 'Thanks!' | |
success = amt.bonus_worker(participant.assignmentid, participant.bonus, reason) | |
if success: | |
participant.status = 7 | |
db_session.add(participant) | |
db_session.commit() | |
else: | |
raise BonusError() | |
if __name__ == '__main__': | |
for participant in Participant.query.filter(Participant.status == 4).all(): | |
try: | |
approve(participant) | |
print('Approved ' + participant.workerid) | |
except ApproveError: | |
print('ERROR approving ' + participant.workerid) | |
for participant in Participant.query.filter(Participant.status == 5).all(): | |
if participant.bonus > 0: | |
try: | |
bonus(participant) | |
print('Bonused ' + participant.workerid) | |
except BonusError: | |
print('ERROR bonusing ' + participant.workerid) | |
else: | |
print('No bonus for ' + participant.workerid) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment