import random import math import time from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class Welcome(Page): form_model = "player" form_fields = ["age", "gender", "school", "i_agree"] class Instructions1(Page): pass class Instructions2(Page): pass class Instructions3(Page): pass class Instructions4(Page): pass class Instructions5(Page): form_model = "player" form_fields = ["pre_test_q1", "pre_test_q2", "pre_test_q3"] def error_message(self, values): if not (values["pre_test_q1"] == "True" and values["pre_test_q2"] == "True" and values["pre_test_q3"] == "True"): return "אחת מהתשובות לא נכונות, יש לקרוא את ההוראות מחדש ולענות שוב" class InvestRound1(Page): form_model = "player" form_fields = ["invest_amount_r1"] def before_next_page(self): player = self.player if random.random() <= 1/3: player.earning_from_investment_lat_round = player.invest_amount_r1 * 3.5 player.asset_up_r1 = True else: player.earning_from_investment_lat_round = 0 player.asset_up_r1 = False player.total_score += player.earning_from_investment_lat_round + (100 - player.invest_amount_r1) if int(math.ceil(player.total_score / 15)) > 5: player.payoff = int(math.ceil(player.total_score / 15)) else: player.payoff = 5 player.participant.vars['total_payout'] = player.payoff def vars_for_template(self): player = self.player player.start_invest = time.time() return {} class InvestRound1Results(Page): def before_next_page(self): player = self.player player.finish_invest = time.time() def vars_for_template(self): player = self.player if player.asset_up_r1: asset_stat = "הנכס הניב רווחים" else: asset_stat = "הכסף שהושקע הופסד" coins_from_saving = 100 - player.invest_amount_r1 return dict(asset_stat=asset_stat, coins_from_saving=coins_from_saving) class Results(Page): pass page_sequence = [Welcome, Instructions1, Instructions2, Instructions3, Instructions4, Instructions5, InvestRound1, InvestRound1Results, Results]