Skip to content

Commit 0135ada

Browse files
committed
Implemented Special Conditions
1 parent 66652bf commit 0135ada

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

web2py/applications/utility/models/__init__.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -653,11 +653,17 @@ def choose_condition():
653653

654654
# Else, let's make a new one.
655655

656-
# Choose a condition. We'll grab the next one in round-robin fashion.
657-
num_choices_made = db((db.experimental_assignments.phase==request.phase)
658-
&(db.experimental_assignments.study==request.study)).count()
659-
request.condition = condition_by_index(experimental_vars_vals(request.study),
660-
num_choices_made)
656+
# Choose a condition. First, give special conditions a shot
657+
for probability, condition in options[request.task]['special_conditions'] or []:
658+
if random.random() < probability:
659+
request.condition = condition.copy()
660+
break
661+
# If none of them match, grab the next condition in round-robin fashion.
662+
else:
663+
num_choices_made = db((db.experimental_assignments.phase==request.phase)
664+
&(db.experimental_assignments.study==request.study)).count()
665+
request.condition = condition_by_index(experimental_vars_vals(request.study),
666+
num_choices_made)
661667

662668
# Now add the singleton variables back into the condition... (need
663669
# to make this more consistent between singleton option variables

0 commit comments

Comments
 (0)