oTree Forum >

Storing subject responses and displaying relative performance between rounds in group

#1 by ekmallory (edited )

I'm putting together a public goods game with treatments which involve both within and between group competition. I've been trying to figure out how to access and display each subject's / team's relative contributions to each participant intermittently between rounds. Does anyone have experience with something similar or have any ideas about how to do it?

Thank you for your help,

#2 by Daniel_Frey

Hi Erik

I'd suggest you use participant variables / fields: https://otree.readthedocs.io/en/latest/rounds.html#participant-fields

If you have a value that is the same for each player in the group and you are in a group function, you can store it like this:

def some_group_function(group)
    for p in group.get_players()
        player.participant.vars['your_variable'] = value

#3 by ekmallory (edited )

Thank you Daniel, your bit of code is very helpful, I think that I'm starting to understand the structure. I am trying to avoid using the participant fields though so that I don't mix things up across treatments/apps, if my understanding is correct.

Do you happen to know if I can access a player's contribution, for example from a specific round with something like:

under group, defining a function that includes the following:

players_in_round = self.in_round(1).get_players()
round_contributions = [p.contribution for p in players_in_round]
highest_cont = max(self.round_contributions)
for p in self.players_in_round:
    if p.round_contributions == highest_cont
       p.hi_contributor = 1
       p.hi_contributor = 0
highest_contibutors = [p.id_in_group for p in players if p.hi_contributors == 1]

#4 by Daniel_Frey

I'm not sure, but I think your first line does not work: get_players() returns a list of all players in the group, and it cannot select a specific round (I think).

Try this:

all_players = self.get_players()
round_contributions = [p.in_round(1).contribution for p in all_players]

and leave the rest.

Btw, are you using oTree Lite that you wrote self in your code?

If yes, I'd suggest you upgrade to oTree 5 if possible, it's so much cleaner :)


#5 by Daniel_Frey

Addition: The if-condition should be changed as well:

for p in self.all_players:
    if p.in_round(1).contribution == highest_cont:
        p.hi_contributor = 1
        p.hi_contributor = 0

Write a reply

Set forum username