Skip to content
Morgan Grant edited this page Jul 10, 2020 · 7 revisions

Groups

BaseGroup

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.

Most use cases for redwood will probably work better with DecisionGroup, though BaseGroup can be useful for experiments based around message passing such as markets or chats.

from otree_redwood.models import Group as RedwoodGroup

class Group(RedwoodGroup):

Methods:

  • send(self, channel, payload) - Broadcasts a payload on a given channel to all members of the group.

  • period_length(self) - This method must return a number of seconds. This is analogous to 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) - 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) - 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.

  • get_start_time(self) - returns a datetime.datetime object representing the time that the period started. If the period hasn't started yet, returns None instead.

  • get_end_time(self) - returns a datetime.datetime object representing the time that the period ended. If the period hasn't ended yet, returns None instead. Also will always return None if period_length is not set.

Properties:

  • events - This property is a Django Manager which allows retrieval of all redwood Event models associated with this group. This allows you to retrieve all the messages sent inside a group. If you're using DecisionGroup then it usually makes more sense to use DecisionGroup.get_group_decisions_events, as then you don't have to worry about database queries. For more information about redwood Events, see Output.

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.

Click here to view a slideshow detailing the way this system works.

from otree_redwood.models import DecisionGroup

class Group(DecisionGroup):

Methods:

  • num_subperiods(self) - This method 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.

  • get_group_decisions_events(self) - This method returns a list of redwood Event models which give the complete history decision history of this group. This list contains Event objects sorted by timestamp, where each Event's value was the value of self.group_decisions at that time. For more information about redwood Events, see Output.

Properties:

  • group_decisions - Contains a dictionary mapping a participant code to their current decision value.

  • 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.

Clone this wiki locally