Skip to content

Commit

Permalink
Merge branch 'allow-repeats-to-adserver'
Browse files Browse the repository at this point in the history
  • Loading branch information
deargle committed Feb 15, 2017
2 parents 55206bf + 9ae3b32 commit 0d61195
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
4 changes: 0 additions & 4 deletions doc/config/hit_configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,6 @@ the Unix curl command.

`allow_repeats` [boolean]
-------------------------
.. warning::
This feature is not yet implemented on the **psiTurk** ad server. If you want to allow repeats, you will need to host your own ad. See
`use_psiturk_ad_server <shell_parameters.html#use-psiturk-ad-server-true-false>`__

`allow_repeats` specifies whether participants may complete the experiment more
than once. If it is set to `false` (the default), then participants will be
blocked from completing the experiment more than once. If it is set to `true`,
Expand Down
27 changes: 21 additions & 6 deletions psiturk/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,27 @@ def check_worker_status():
return jsonify(**resp)
else:
worker_id = request.args['workerId']
try:
part = Participant.query.\
filter(Participant.workerid == worker_id).one()
status = part.status
except exc.SQLAlchemyError:
status = NOT_ACCEPTED
assignment_id = request.args['assignmentId']
allow_repeats = CONFIG.getboolean('HIT Configuration', 'allow_repeats')
if allow_repeats: # if you allow repeats focus on current worker/assignment combo
try:
part = Participant.query.\
filter(Participant.workerid == worker_id).\
filter(Participant.assignmentid == assignment_id).one()
status = part.status
except exc.SQLAlchemyError:
status = NOT_ACCEPTED
else: # if you disallow repeats search for highest status of anything by this worker
try:
matches = Participant.query.\
filter(Participant.workerid == worker_id).all()
numrecs = len(matches)
if numrecs==0: # this should be caught by exception, but just to be safe
status = NOT_ACCEPTED
else:
status = max([record.status for record in matches])
except exc.SQLAlchemyError:
status = NOT_ACCEPTED
resp = {"status" : status}
return jsonify(**resp)

Expand Down
9 changes: 8 additions & 1 deletion psiturk/psiturk_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,12 @@ def create_psiturk_ad(self):
else:
ip_address = str(self.web_services.get_my_ip())
port = str(self.config.get('Server Parameters', 'port'))

if self.config.has_option('HIT Configuration', 'allow_repeats'):
allow_repeats = self.config.getboolean('HIT Configuration', 'allow_repeats')
else:
allow_repeats = False

ad_content = {
'psiturk_external': True,
'server': ip_address,
Expand All @@ -1144,7 +1150,8 @@ def create_psiturk_ad(self):
'experiment_name': str(self.config.get('HIT Configuration', 'title')),
'contact_email_on_error': str(self.config.get('HIT Configuration', 'contact_email_on_error')),
'ad_group': str(self.config.get('HIT Configuration', 'ad_group')),
'keywords': str(self.config.get('HIT Configuration', 'psiturk_keywords'))
'keywords': str(self.config.get('HIT Configuration', 'psiturk_keywords')),
'allow_repeats': int(allow_repeats)
}
ad_id = self.web_services.create_ad(ad_content)
return ad_id
Expand Down

0 comments on commit 0d61195

Please sign in to comment.