from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants from random import randint class Introduction(Page): def is_displayed(self): return self.round_number == 1 class Forecast(Page): """This page is only for P1 P1 sends demand forecast to P2""" #timeout_seconds = 20 def vars_for_template(self): if self.round_number > 1: sent_back_list = [g.sent_back_amount for g in self.group.in_previous_rounds()] productionQuantity = sent_back_list[-1] else: productionQuantity=0 if self.session.config['certainty'] == True: certainty = 1 else: certainty = 0 return dict( certainty = certainty, productionQuantity = productionQuantity ) form_model = 'group' form_fields = ['sent_amount'] def is_displayed(self): return self.player.id_in_group == 1 class SendWaitPage(WaitPage): pass # ============================================================================= # class NextRoundPage(WaitPage): # after_all_players_arrive = 'sent_List' # pass # ============================================================================= class ProductionQuantity(Page): """This page is only for P2 P2 sends production quantity to P2""" #timeout_seconds = 20 def vars_for_template(self): if self.session.config['certainty'] == True: certainty = 1 else: certainty = 0 return dict( certainty = certainty ) form_model = 'group' form_fields = ['sent_back_amount'] def is_displayed(self): return self.player.id_in_group == 2 class jNM2(WaitPage): pass # ============================================================================= # class ResultsWaitPage(WaitPage): # after_all_players_arrive = 'calculate_Payoff' # pass # ============================================================================= class Results(Page): form_model = 'group' def vars_for_template(self): self.random(self) #### certainty #### if self.session.config['certainty'] == True: t = randint(1, Constants.num_rounds) #Get random number sent_list = [g.sent_amount for g in self.group.in_all_rounds()] # get list of all produced items sent_back_list = [g.sent_back_amount for g in self.group.in_all_rounds()] # get list of all produced items bt = sent_list[(t-1)] # choose aproduced items from random round at = sent_back_list[(t-1)] # choose a produced items from random round qt = self.group.rdmCurve Cfix = 191 summe = 0 for i in range(0,at+1): # Sales if ((20-i)>0 and i>0): summe = 20-i+summe else: summe = 0+summe PayoffSALES = summe summe2 = 0 for i in range(0,at+1): # Operations summe2 = i + summe2 if summe2 > 191: summe2 = 191 PayoffOPERATIONS = Cfix - summe2 #sum(i for (i < at) in co)#np.sum(co, np.arange(0,int(at))) if PayoffOPERATIONS < 0: #for idiots PayoffOPERATIONS = 0 else: #### uncertainty #### t = randint(1, Constants.num_rounds) #Get random number sent_list = [g.sent_amount for g in self.group.in_all_rounds()] # get list of all produced items sent_back_list = [g.sent_back_amount for g in self.group.in_all_rounds()] # get list of all produced items bt = sent_list[(t-1)] # choose aproduced items from random round at = sent_back_list[(t-1)] # choose a produced items from random round qt = self.group.rdmCurve # choose the random quantity from tghe random round Cfix = 191 summe = 0 for i in range(0,at+1): # Sales if (qt == 1 and (-1*i+21)>0 and i>0): summe = 21-i+summe if (qt == -1 and (-1*i+19)>0 and i>0): summe = 19-i+summe else: summe = 0+summe PayoffSALES = summe summe = 0 for i in range(0,at+1): # Operations if (qt == 0 and i>0): summe = i+1 + summe if (qt == 1 and i>0): summe = i-1 + summe else: summe = 0 + summe PayoffOPERATIONS = Cfix - summe if PayoffOPERATIONS < 0: #for idiots PayoffOPERATIONS = 0 return dict( at = at, bt = bt, qt = qt, Cfix = Cfix, t=t, PayoffSALES = PayoffSALES, PayoffOPERATIONS = PayoffOPERATIONS ) def is_displayed(self): return self.round_number == Constants.num_rounds page_sequence = [Introduction, SendWaitPage, Forecast, SendWaitPage, ProductionQuantity, SendWaitPage, Results, jNM2]