ctreffe / alfred

Alfred - A library for rapid experiment development
MIT License
10 stars 1 forks source link

Improve SessionQuota documentation #217

Closed jbengelsdorf closed 6 months ago

jbengelsdorf commented 2 years ago

The SessionQuota is the basic building block also for the ListRandomizer, meaning it does all the counting (but non of the randomizing). The SessionQuota will abort new sessions when SessionQuota.count() is called, and the required number of slots are finished, or if there are enough active sessions, such that the required number of slots may get filled. It behaves like the ListRandomizer in this regard.

Therefore, the SessionQuota is a powerful tool and can be used, for instance, to achieve the collection of equally sized subpopulations within an experiment. For example, the collection of data from one student and one employee can be achieved by using this code:

import alfred3 as al

exp = al.Experiment()

@exp.member
class DemographicPage(al.Page):

    def on_exp_access(self):
        self += al.SingleChoiceBar(
            "Student", "Employed",
            name="job",
            toplab="Please enter your employment status"
        )

    def on_first_hide(self):
        if self.exp.values.get("job", None) == 1: # if student
            quota = al.SessionQuota(nslots=1, exp=self.exp, name="quota_student")
            quota.count()
        else: # if employed
            quota = al.SessionQuota(nslots=1, exp=self.exp, name="quota_employed")
            quota.count()

exp += al.Page(title="Second page", name="second_page")

if __name__ == "__main__":
    exp.run()

Unfortunately, as far as I can see, the SessionQuota is not described very prominently in the alfred3 documentation. Due to its versatile application possibilities, we should change this.

jobrachem commented 2 years ago

The source code is documented already. Mostly, I think the quota needs to be added to the API autosummary directive in docs/source/index.rst. Maybe also some more examples and a narrative description could be nice.