
from otree.api import *
import numpy as np
import random
c = cu

doc = ''
class C(BaseConstants):
    NAME_IN_URL = 'findec'
    PLAYERS_PER_GROUP = 3
    NUM_ROUNDS = 30
    INIT_CASH = cu(50)
    INIT_STOCK = 5
    INIT_STOCK_PRIZE = cu(5)
    MULTIPLIER = 1.8

class Subsession(BaseSubsession):
    stock_prize = models.CurrencyField(label="Current prize of stock", min=cu(0), initial=C.INIT_STOCK_PRIZE) #P* from supp mat from paper
class Group(BaseGroup):
    pass
def set_payoffs(group: Group):
    pass
class Player(BasePlayer):
    n_stock = models.IntegerField(label="current number of assets", min=0, initial=C.INIT_STOCK)
    cash = models.CurrencyField(label="current amount of cash", min=0, initial=C.INIT_CASH)
    choice_1 = models.StringField(
        choices=["Buy", "Hold", "Sell"],
        widget=widgets.RadioSelect,
        initial="Hold"
    )
    choice_2 = models.StringField(
        choices=["Buy", "Hold", "Sell"],
        widget=widgets.RadioSelect,
        initial="Hold"
    )
    choice_3 = models.StringField(
        choices=["Buy", "Hold", "Sell"],
        widget=widgets.RadioSelect,
        initial="Hold"
    )
    choice_4 = models.StringField(
        choices=["Buy", "Hold", "Sell"],
        widget=widgets.RadioSelect,
        initial="Hold"
    )
    choice_5 = models.StringField(
        choices=["Buy", "Hold", "Sell"],
        widget=widgets.RadioSelect,
        initial="Hold"
    )

class Decision1(Page):
    form_model = 'player'
    form_fields = ['choice_1']
    timeout_seconds = 10

    @staticmethod
    def vars_for_template(player: Player):
        return dict(
            n_stock=player.n_stock,
            cash=player.cash,
            total_stock_val=player.n_stock * player.subsession.stock_prize,
            offer=cu(np.round(np.random.normal(loc=player.subsession.stock_prize), decimals=2))

class Decision2(Page):
    form_model = 'player'
    form_fields = ['choice_2']
    timeout_seconds = 10

    @staticmethod
    def vars_for_template(player: Player):
        return dict(
            n_stock=player.n_stock,
            cash=player.cash,
            total_stock_val=player.n_stock * player.subsession.stock_prize,
            offer=cu(np.round(np.random.normal(loc=player.subsession.stock_prize), decimals=2))

class Decision3(Page):
    form_model = 'player'
    form_fields = ['choice_3']
    timeout_seconds = 10

    @staticmethod
    def vars_for_template(player: Player):
        return dict(
            n_stock=player.n_stock,
            cash=player.cash,
            total_stock_val=player.n_stock * player.subsession.stock_prize,
            offer=cu(np.round(np.random.normal(loc=player.subsession.stock_prize), decimals=2))

class Decision4(Page):
        form_model = 'player'
        form_fields = ['choice_4']
        timeout_seconds = 10

    @staticmethod
    def vars_for_template(player: Player):
        return dict(
            n_stock=player.n_stock,
            cash=player.cash,
            total_stock_val=player.n_stock * player.subsession.stock_prize,
            offer=cu(np.round(np.random.normal(loc=player.subsession.stock_prize), decimals=2))

class Decision5(Page):
    form_model = 'player'
    form_fields = ['choice_5']
    timeout_seconds = 10

    @staticmethod
    def vars_for_template(player: Player):
        return dict(
            n_stock=player.n_stock,
            cash=player.cash,
            total_stock_val=player.n_stock * player.subsession.stock_prize,
            offer=cu(np.round(np.random.normal(loc=player.subsession.stock_prize),decimals=2))
)

class ResultsWaitPage(WaitPage):
    after_all_players_arrive = set_payoffs

class Results(Page):
    form_model = 'player'

page_sequence = [Decision1, Decision2, Decision3, Decision4, Decision5, ResultsWaitPage, Results]




