-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpages.py
145 lines (128 loc) · 4.88 KB
/
pages.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
from otree.api import Currency as c, currency_range
from ._builtin import Page, WaitPage
from .models import Constants
class Consent(Page):
def is_displayed(self):
return self.round_number == 1
def vars_for_template(self):
return {
'participation_fee': self.session.config['participation_fee'],
}
pass
class Coverstory(Page):
def is_displayed(self):
return self.round_number == 1
pass
class Coverstory_check(Page):
def is_displayed(self):
return self.round_number == 1
pass
class Incentives(Page):
def is_displayed(self):
return self.round_number == 1
def vars_for_template(self):
return {
'participation_fee': self.session.config['participation_fee'],
'real_world_currency_per_point': self.session.config['real_world_currency_per_point'],
'real_world_currency_per_success': self.session.config['real_world_currency_per_success']
}
pass
class ResultsWaitPage(WaitPage):
def after_all_players_arrive(self):
for p in self.subsession.get_players():
if self.round_number > 1:
p.successes = p.get_last_success()
if (not self.subsession.is_new_block()) & self.subsession.is_multitrial():
p.state = p.get_last_state()
class NewBlock(Page):
def is_displayed(self):
return (self.subsession.is_new_block() & self.subsession.is_multitrial())
def vars_for_template(self):
return {
'currentblock': self.player.block,
'currentstate': self.player.state,
'x1': self.participant.vars['actions'][self.player.block][0][ :2],
'p1': self.participant.vars['actions'][self.player.block][0][2:],
'x2': self.participant.vars['actions'][self.player.block][1][ :2],
'p2': self.participant.vars['actions'][self.player.block][1][2:],
'budget': self.player.budget,
'num_blocks': self.session.vars['num_blocks'],
'successes': self.player.successes
}
pass
class InstructionOneshot(Page):
def is_displayed(self):
return self.round_number == Constants.num_multitrial
pass
class Choices(Page):
form_model = 'player'
form_fields = ['choice']
def vars_for_template(self):
maxx = max(map(max, *self.participant.vars['actions'][self.player.block]))
max_earnings = max(maxx * Constants.num_trials, self.player.budget + .01)
return {
'x1': self.participant.vars['actions'][self.player.block][0][ :2],
'p1': self.participant.vars['actions'][self.player.block][0][2:],
'x2': self.participant.vars['actions'][self.player.block][1][ :2],
'p2': self.participant.vars['actions'][self.player.block][1][2:],
'state': self.player.state,
'budget': self.player.budget,
'choice': self.player.choice,
'chart_trial': [1] * self.player.trial,
'max_less_state': max_earnings - self.player.state,
'max_earning': max_earnings,
'num_blocks': self.session.vars['num_blocks'],
'multitrial': (self.round_number - 1) < Constants.num_multitrial,
'successes': self.player.successes
}
def before_next_page(self):
self.player.get_outcome()
self.player.update_successes()
pass
class Results(Page):
def is_displayed(self):
return self.round_number <= Constants.num_multitrial
def vars_for_template(self):
maxx = max(map(max, *self.participant.vars['actions'][self.player.block]))
max_earnings = max(maxx * Constants.num_trials, self.player.budget + .01)
return {
'state': self.player.state + self.player.outcome,
'required': self.player.budget - self.player.state,
'budget': self.player.budget,
'chart_trial': [1] * (self.player.trial),
'max_less_state': max_earnings - self.player.state,
'max_earning': max_earnings,
'num_blocks': self.session.vars['num_blocks'],
'successes': self.player.successes
}
pass
class ChoicesUncover(Page):
def is_displayed(self):
return self.round_number == 5
form_model = 'player'
form_fields = ['choice']
def vars_for_template(self):
return {
'HV': self.participant.vars['outcomes'][1],
'HP': self.participant.vars['probabilities'][1],
'LV': self.participant.vars['outcomes'][0],
'LP': self.participant.vars['probabilities'][0],
'state': sum([p.state for p in self.player.in_all_rounds()]),
'budget': self.player.budget,
'choice': self.player.choice,
'chart_trial': [1] * (self.participant.vars['trial'] + 1),
'max_less_state': int(max(self.participant.vars['outcomes'][1])) * Constants.num_rounds - sum([p.outcome for p in self.player.in_all_rounds()]),
'max_earning': int(max(self.participant.vars['outcomes'][1])) * Constants.num_rounds
}
pass
page_sequence = [
# Consent,
# Coverstory,
# Coverstory_check,
# Incentives,
ResultsWaitPage,
NewBlock,
Choices,
Results,
# InstructionOneshot,
]