-
Notifications
You must be signed in to change notification settings - Fork 1
Groups
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 apayload
on a givenchannel
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, returnsNone
instead. -
get_end_time(self)
- returns a datetime.datetime object representing the time that the period ended. If the period hasn't ended yet, returnsNone
instead. Also will always returnNone
ifperiod_length
is not set.
Properties:
-
events
- This property is a Django Manager which allows retrieval of all redwoodEvent
models associated with this group. This allows you to retrieve all the messages sent inside a group. If you're usingDecisionGroup
then it usually makes more sense to useDecisionGroup.get_group_decisions_events
, as then you don't have to worry about database queries. For more information about redwoodEvent
s, see Output.
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. Ifnum_subperiods
returns something other than None, each period will be divided intonum_subperiods
intervals of lengthperiod_length / num_subperiods
seconds. Each sub-period the currentgroup_decisions
gets copied into thesubperiod_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 bytimestamp
, where each Event'svalue
was the value ofself.group_decisions
at that time. For more information about redwoodEvent
s, 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 whennum_subperiods
is used and subperiod behavior is enabled.