162 lines
6.7 KiB
Python
162 lines
6.7 KiB
Python
![]() |
from otree.api import Currency as c, currency_range
|
||
|
from ._builtin import Page, WaitPage
|
||
|
from .models import Constants
|
||
|
import random
|
||
|
|
||
|
|
||
|
class Bienvenue(Page):
|
||
|
form_model = 'player'
|
||
|
form_fields = []
|
||
|
|
||
|
# def is_displayed(self):
|
||
|
# return self.participant.vars['versionexp'] == 2
|
||
|
|
||
|
def is_displayed(self):
|
||
|
return self.round_number == 1
|
||
|
|
||
|
def before_next_page(self):
|
||
|
self.player.game_num = self.player.participant.vars['game_num'] + 1
|
||
|
self.player.participant.vars['game_num'] = self.player.game_num
|
||
|
self.player.app_sequence_select = self.player.participant.vars['app_sequence_select']
|
||
|
self.player.app_sequence_select_n = self.player.participant.vars['app_sequence_select_n']
|
||
|
self.player.questionnaire_before = self.player.participant.vars['questionnaire_before']
|
||
|
|
||
|
class Introduction(Page):
|
||
|
form_model = 'player'
|
||
|
form_fields = ['r1','r2','r3','r4']
|
||
|
|
||
|
def is_displayed(self):
|
||
|
return self.round_number == 1
|
||
|
|
||
|
def error_message(self, values):
|
||
|
print('values is', values)
|
||
|
if values['r1'] != 98:
|
||
|
return 'Merci de corriger votre réponse 1 !!'
|
||
|
elif values['r2'] != 2:
|
||
|
return 'Merci de corriger votre réponse 2 !!'
|
||
|
elif values['r3'] != 110:
|
||
|
return 'Merci de corriger votre réponse 3 !!'
|
||
|
elif values['r4'] != 5:
|
||
|
return 'Merci de corriger votre réponse 4 !!'
|
||
|
|
||
|
def before_next_page(self):
|
||
|
# selection of random dotation/s/g and round to be paid
|
||
|
self.player.dgm_selected = random.randint(1, 5)
|
||
|
self.player.round_selected = random.randint(1, 8)
|
||
|
self.player.participant.vars['mdgasso_dgm_selected'] = self.player.dgm_selected
|
||
|
self.player.participant.vars['mdgasso_round_selected'] = self.player.round_selected
|
||
|
|
||
|
class NextPage(Page):
|
||
|
form_model = 'player'
|
||
|
form_fields = []
|
||
|
|
||
|
def vars_for_template(self):
|
||
|
return dict(
|
||
|
round = self.round_number,
|
||
|
)
|
||
|
|
||
|
|
||
|
def before_next_page(self):
|
||
|
self.player.dgm_selected = self.player.participant.vars['mdgasso_dgm_selected']
|
||
|
self.player.round_selected =self.player.participant.vars['mdgasso_round_selected']
|
||
|
self.player.dot1 = getattr(Constants, f'dgm{self.player.dgm_selected}')[self.round_number][0]
|
||
|
self.player.s1 = getattr(Constants, f'dgm{self.player.dgm_selected}')[self.round_number][1]
|
||
|
self.player.g1 = getattr(Constants, f'dgm{self.player.dgm_selected}')[self.round_number][2]
|
||
|
|
||
|
class Send(Page):
|
||
|
"""comment
|
||
|
"""
|
||
|
form_model = 'player'
|
||
|
form_fields = ['keep_amount', 'sent_amount']
|
||
|
|
||
|
def error_message(self, values):
|
||
|
print('values is', values)
|
||
|
if values['keep_amount'] < 0:
|
||
|
return 'the amount must be positive '
|
||
|
elif values['keep_amount'] > self.player.dot1 :
|
||
|
return f'please choose an amount less than {self.player.dot1}'
|
||
|
elif values['sent_amount'] < 0:
|
||
|
return 'the amount must be positive '
|
||
|
elif values['sent_amount'] + values['keep_amount'] != self.player.dot1:
|
||
|
return f'the sum of the two amounts must be equal to {self.player.dot1}'
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
def vars_for_template(self):
|
||
|
return dict(
|
||
|
dot1 = self.player.dot1,
|
||
|
s1 = self.player.s1,
|
||
|
g1 = self.player.g1,
|
||
|
round = self.round_number,
|
||
|
game_num = self.player.participant.vars['game_num']
|
||
|
)
|
||
|
|
||
|
def before_next_page(self):
|
||
|
self.player.participant.vars[f'dot1_r{self.round_number}'] = self.player.dot1
|
||
|
self.player.participant.vars[f's1_r{self.round_number}'] = self.player.s1
|
||
|
self.player.participant.vars[f'g1_r{self.round_number}'] = self.player.g1
|
||
|
self.player.participant.vars[f'keep_r{self.round_number}'] = self.player.keep_amount
|
||
|
self.player.participant.vars[f'sent_r{self.round_number}'] = self.player.sent_amount
|
||
|
|
||
|
if self.round_number == 8:
|
||
|
self.player.dot1_select = self.player.participant.vars[f'dot1_r{self.player.round_selected}']
|
||
|
self.player.s1_select = self.player.participant.vars[f's1_r{self.player.round_selected}']
|
||
|
self.player.g1_select = self.player.participant.vars[f'g1_r{self.player.round_selected}']
|
||
|
self.player.keep_select = self.player.participant.vars[f'keep_r{self.player.round_selected}']
|
||
|
self.player.sent_select = self.player.participant.vars[f'sent_r{self.player.round_selected}']
|
||
|
self.player.gain_dgm = self.player.keep_select * self.player.s1_select
|
||
|
self.player.gain_asso = self.player.sent_select * self.player.g1_select
|
||
|
self.player.gain_dgm_eur = round(self.player.gain_dgm * Constants.exchangerate,1)
|
||
|
self.player.gain_asso_eur = round(self.player.gain_asso * Constants.exchangerate,1)
|
||
|
self.player.payoff = round(self.player.gain_dgm_eur,1)
|
||
|
|
||
|
# to final page:
|
||
|
self.player.participant.vars['mdgasso_dot1_select'] = self.player.dot1_select
|
||
|
self.player.participant.vars['mdgasso_s1_select'] = self.player.s1_select
|
||
|
self.player.participant.vars['mdgasso_g1_select'] = self.player.g1_select
|
||
|
self.player.participant.vars['mdgasso_keep_select'] = self.player.keep_select
|
||
|
self.player.participant.vars['mdgasso_sent_select'] = self.player.sent_select
|
||
|
self.player.participant.vars['mdgasso_gain_dgm'] = self.player.gain_dgm
|
||
|
self.player.participant.vars['mdgasso_gain_asso'] = self.player.gain_asso
|
||
|
self.player.participant.vars['mdgasso_gain_dgm_eur'] = self.player.gain_dgm_eur
|
||
|
self.player.participant.vars['mdgasso_gain_asso_eur'] = self.player.gain_asso_eur
|
||
|
|
||
|
class Questionnaire(Page):
|
||
|
form_model = 'player'
|
||
|
form_fields = ['altruistic_assessment_das', 'confidence_level_das', 'memory_recall_das']
|
||
|
def is_displayed(self):
|
||
|
return self.round_number == 8
|
||
|
|
||
|
|
||
|
class Results(Page):
|
||
|
def is_displayed(self):
|
||
|
return self.round_number == 8
|
||
|
|
||
|
def vars_for_template(self):
|
||
|
#group = player.group
|
||
|
return dict(
|
||
|
dot1_select = self.player.dot1_select,
|
||
|
s1_select = self.player.s1_select,
|
||
|
g1_select = self.player.g1_select,
|
||
|
round = self.round_number,
|
||
|
round_selected = self.player.round_selected,
|
||
|
keep_select = self.player.keep_select,
|
||
|
sent_select = self.player.sent_select,
|
||
|
gain_dgm = self.player.gain_dgm,
|
||
|
gain_asso = self.player.gain_asso,
|
||
|
gain_dgm_eur = self.player.gain_dgm_eur,
|
||
|
gain_asso_eur = self.player.gain_asso_eur,
|
||
|
|
||
|
)
|
||
|
|
||
|
page_sequence = [
|
||
|
Bienvenue,
|
||
|
Introduction,
|
||
|
NextPage,
|
||
|
Send,
|
||
|
Questionnaire,
|
||
|
]
|
||
|
|
||
|
|