Groups

Base Group

Source: otree_redwood.models.Group

The otree-redwood base Group is a building block for more complex behavior. By default it uses a period_length function you implement to set a timer that will auto-advance subjects similar to oTree’s timeout_seconds variable.

You probably don’t want to extend this class directly - instead you can extend DecisionGroup.

from otree_redwood.models import Group as RedwoodGroup

class Group(RedwoodGroup):

send(self, channel, payload)

send broadcasts a payload on a given channel to all members of the group.

period_length(self)

The period_length function must return a number of seconds. This is analogous to the timeout_seconds in an oTree page. The difference is that periods are synchronized with the players in the group - The period will not start until all players have connected to the page.

when_all_players_ready(self)

when_all_players_ready is called when all players have connected to the page. The period starts immediately after the function returns. You can override this function to perform initialization and setup of the group.

when_player_disconnects(self, player)

when_player_disconnects is called when a player disconnects before the period has ended. Generally this means the player closed their browser window or turned off their machine. You can override this function to implement behavior like pausing the period and notifying group members.

DecisionGroup

Source: otree_redwood.models.DecisionGroup

DecisionGroup watches for changes on the decisions channel and sends updates to the group on the group_decisions channel. This works in with the redwood-decision component.

from otree_redwood.models import DecisionGroup

class Group(DecisionGroup):

num_subperiods(self)

The num_subperiods function can return an integer or None. If num_subperiods returns something other than None, each period will be divided into num_subperiods intervals of length period_length / num_subperiods seconds. Each sub-period the current group_decisions gets copied into the subperiod_group_decisions. Effectively this means the players can only make decisions at the boundary of every sub-period. E.g. if there are 12 sub-periods, players make 12 decisions during the course of the period. By default, num_subperiods returns None and this behavior is disabled.

group_decisions

group_decisions contains a dictionary mapping a participant code to their current decision value.

subperiod_group_decisions

subperiod_group_decisions contains a dictionary mapping a participant code to their decision value in the most recent subperiod. This field is only set when num_subperiods is used and subperiod behavior is enabled.