How do I create a customized abort_page for the al.ListRandomizer? #238
-
I would like to create a custom abort_page for participants trying to reach an experiment whose slots are currently filled. import alfred3 as al
exp = al.Experiment()
@exp.setup # Setup dass die Bedingungen generiert
def setup(exp):
exp.stud_randomizer = al.ListRandomizer(
# der randomizer lässt ine Listenrandomisierung zu hierbei wird ("Bedingung", Anzahl gewünschter Probenden angegeben)
("m_transact1", 1),
("m_transform1", 0),
("w_transact1", 0),
("w_transform1", 0),
name="stud_randomizer",
exp=exp,# hier wird das verwendete Experiment definiert. In diesem Fall eben unser exp
respect_version=True,
abort_page=abort_page
)
exp.condition = exp.stud_randomizer.get_condition()
exp.log.info(exp.condition)
@exp.member
class dummy_page(al.Page):
def on_exp_access(self):
self += al.Text("this is a dummy page")
class abort_page(al.Page):
def on_exp_access(self):
self += al.Text("Leider sind alle Teilnahmeslots für diese Erhebung belegt. ")
if __name__ == "__main__":
exp.run() |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The Here's a copy of that example: import alfred3 as al
exp = al.Experiment()
@exp.setup
def setup(exp):
full_page = al.Page(title="Experiment closed.", name="fullpage")
full_page += al.Text("Sorry, the experiment currently does not accept any further participants.")
randomizer = al.ListRandomizer(("cond1", 10), ("cond2", 10), exp=exp, abort_page=full_page)
exp.condition = randomizer.get_condition()
@exp.member
class DemoPage(al.Page):
def on_exp_access(self):
if self.exp.condition == "cond1":
lab = "label in condition 1"
elif self.exp.condition == "cond2":
lab = "label in condition 2"
self += al.TextEntry(leftlab=lab, name="t1") |
Beta Was this translation helpful? Give feedback.
The
abort_page
should be a page instance, but you are providing a page class. An example for correct usage can be found here: https://alfredo3.psych.bio.uni-goettingen.de/docs/generated/alfred3.randomizer.ListRandomizer.get_condition.html#alfred3.randomizer.ListRandomizer.get_conditionHere's a copy of that example: