from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants def choice_description(mychoice, pb1): pb2 = 100 - pb1 if mychoice == "S": return "商品 A: 您有" + str(pb1) + "% 機率得到 " + str(Constants.s_goodtime) + " 萬, " + str(pb2) + "% 機率得到 " + str(Constants.s_badtime) + " 萬" if mychoice == "R": return "商品 B: 您有" + str(pb1) + "% 機率得到 " + str(Constants.r_goodtime) + " 萬, " + str(pb2) + "% 機率得到 " + str(Constants.r_badtime) + " 萬" class Opening(Page): def vars_for_template(self): return { 'total_principal': Constants.principal * Constants.chance } class Instruction(Page): form_model = 'player' form_fields = ['asset_choice0', 'asset_choice1', 'asset_choice2', 'asset_choice3', 'asset_choice4'] def vars_for_template(self): return { 'total_principal': Constants.principal * Constants.chance } def before_next_page(self): self.player.draw() class Results(Page): def vars_for_template(self): return {'mychoice0': choice_description(self.player.asset_choice0, Constants.prob0), 'mychoice1': choice_description(self.player.asset_choice1, Constants.prob1), 'mychoice2': choice_description(self.player.asset_choice2, Constants.prob2), 'mychoice3': choice_description(self.player.asset_choice3, Constants.prob3), 'mychoice4': choice_description(self.player.asset_choice4, Constants.prob4), } def before_next_page(self): self.player.pass_cumchip() page_sequence = [ Opening, Instruction, Results ]