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.session.config['certainty'] == True: certainty = 1 else: certainty = 0 return dict( image_path_certainty='pictures/Sales - Period ' + str(self.round_number) + '.png'.format(self.round_number), image_path_uncertainty='pictures/Sales - Period ' + str(self.round_number) + ' - Kopie.png'.format(self.round_number), certainty = certainty ) form_model = 'group' form_fields = ['sent_amount'] def is_displayed(self): return self.player.id_in_group == 1 class SendWaitPage(WaitPage): pass class ProductionReply(Page): """This page is only for P1 P1 gets production amount from P2""" def is_displayed(self): return self.player.id_in_group == 1 # ============================================================================= # 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): self.group.random() if self.session.config['certainty'] == True: certainty = 1 else: certainty = 0 return dict( image_path_certainty='pictures/Operations - Period ' + str(self.round_number) + '.png'.format(self.round_number), image_path_uncertainty='pictures/Operations - Period ' + str(self.round_number) + ' - Kopie.png'.format(self.round_number), certainty = certainty ) form_model = 'group' form_fields = ['sent_back_amount'] def is_displayed(self): return self.player.id_in_group == 2 "pictures/Operations - Period 1.png" 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): t = self.group.rdmRound #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 = Constants.Cfix fSales = [14,11,15,12,16,13,17] fOp = [8,5,9,6,10,7,11] summe1 = 0 for i in range(0,at+1): # Sales if (qt == 1 and (-1*i+fSales[t-1]+1)>0 and i>0): summe1 = fSales[t-1]+1-i+summe1 if (qt == 0 and (-1*i+fSales[t-1])>0 and i>0): summe1 = fSales[t-1]-i+summe1 if (qt == -1 and (-1*i+fSales[t-1]-1)>0 and i>0): summe1 = fSales[t-1]-1-i+summe1 else: summe1 = 0+summe1 PayoffSALES = summe1 summe2 = 0 for i in range(0,at+1): # Operations if (qt == +1 and i>0): summe2 = i + fOp[t-1] + 1 + summe2 if (qt == 0 and i>0): summe2 = i + fOp[t-1] + summe2 if (qt == -1 and i>0): summe2 = i + fOp[t-1] - 1 + summe2 else: summe2 = 0 + summe2 PayoffOPERATIONS = Cfix - summe2 + summe1 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, ProductionReply, SendWaitPage, Results, jNM2]