oTree Forum >

Group treatment payment

#1 by Anwesha

Hi there,

Hope you are well. I know that lately, I have posted several queries and I would like to apologise for the inconvenience. Being a first time programmer, while programming my experiment, I am still learning. I don't have any colleagues who knows otree or Python that works in my field as well. Hence, I pretty much depend on your wonderful support system. 

The question I have today is mainly two parts. 

1) I have designed a group treatment. However, the payoff for each player is always coming to be zero. The codes are mentioned below. 
from otree.api import *
import numpy as np

cu = Currency


class C(BaseConstants):
    NAME_IN_URL = 'group_esg'
    PLAYERS_PER_GROUP = 2
    NUM_ROUNDS = 1
    ENDOWMENT_PER_PLAYER = 100
    payment_assetA = 110
    payment_assetB = 115
    payment_otherwise = 30


class Subsession(BaseSubsession):
    pass


class Group(BaseGroup):
    get_payoff = models.IntegerField()

class Player(BasePlayer):
    decision1 = models.BooleanField(
        label="Please make a selection between Asset A and Asset B",
        choices=[
            [True, "Asset A"],
            [False, "Asset B"],
        ],
        widget=widgets.RadioSelectHorizontal
    )
    decision2 = models.BooleanField(
        label="Please make a selection between Asset A and Asset B",
        choices=[
            [True, "Asset A"],
            [False, "Asset B"],
        ],
        widget=widgets.RadioSelectHorizontal
    )


# PAGES
class OriginalDecision(Page):
    form_model = "player"
    form_fields = ["decision1"]
    time = models.FloatField()

    @staticmethod
    def vars_for_template(player: Player):
        return dict(
            image_path='esg_wealth/flag2.jpg',
            pdf_path='Environmental report.pdf'
        )

    @staticmethod
    def live_method(player, data):
        player.time = data

class ResultsWaitPage(WaitPage):
    pass

class Revision(Page):
    @staticmethod
    def vars_for_template(player: Player):
        opponent = player.get_others_in_group()[0]
        return dict(
            opponent=opponent,
            same_choice=player.decision1 == opponent.decision1,
            my_decision=player.field_display('decision1'),
            opponent_decision=opponent.field_display('decision1'),
        )

class RevisedDecision(Page):
    form_model = "player"
    form_fields = ["decision2"]
    time = models.FloatField()

    @staticmethod
    def vars_for_template(player: Player):
        return dict(
            image_path='esg_wealth/flag2.jpg',
            pdf_path='Environmental report.pdf'
        )

    @staticmethod
    def live_method(player, data):
        player.time = data



class Results(Page):
    @staticmethod
    def after_all_players_arrive(player: Player):
        pchoice = np.random.random()
        if pchoice <= 0.5:
            Group.get_payoff = 1
        else:
            Group.get_payoff = 0
        if player.decision2 == True:
            player.payoff += C.payment_assetA * Group.get_payoff
        if player.decision2 == False:
            player.payoff += C.payment_assetB * Group.get_payoff
        if Group.get_payoff == 0:
            player.payoff += C.payment_otherwise

page_sequence = [OriginalDecision, ResultsWaitPage, Revision, RevisedDecision, ResultsWaitPage, Results]

2) My problem is with the rounding up of my payoff. So, £11.50 becomes £12.00. I tried my best to figure out a way to stop this but haven't been able to figure out anything yet. I have created a separate app for this. This is the code I am using:
class Payment(Page):
    @staticmethod
    def vars_for_template(player: Player):
        participant = player.participant
        return dict(
            redemption_code=participant.label or participant.code,
            earning = format(float(participant.payoff / 10), '.2f')
        )

#2 by Fanist

Q1: do not write models under Page:
like the code:
# PAGES
class OriginalDecision(Page):
    form_model = "player"
    form_fields = ["decision1"]
    time = models.FloatField()
  
 write the line "time = models.FloatField()" in Player field. 

Q2: write two time vars in Player
In the Player field, now we have a "time" var in Player field. But the time is rewrittern in the RevisedDecision Page. So add "time1" and "time2" to differ. 

Q3: for payoff always = 0 issue, try to add a new page before Results Page. In this new page, add your code for determining payoff here. And in Results Page, just show the number to subjects.

#3 by Anwesha

Hi Fanist,

Thank you for your reply. Unfortunately payoff = 0 problem still persists. Another quick question. I have created time1 and time2.In that case, any mention of time in html pages should also be time 1 and time2, is that correct?

#4 by Anwesha

Hi Fanist,

So I have been able to solve the problem. I didn't add a new page before Results page. Just did this:
class Results(Page):
    @staticmethod
    def vars_for_template(player: Player):
        pchoice = np.random.random()
        if pchoice <= 0.5:
            Group.get_payoff = 1
        else:
            Group.get_payoff = 0
        if player.decision2 == True:
            player.payoff += C.payment_assetA * Group.get_payoff
        if player.decision2 == False:
            player.payoff += C.payment_assetB * Group.get_payoff
        if Group.get_payoff == 0:
            player.payoff += C.payment_otherwise

Write a reply

Set forum username