File size: 2,163 Bytes
3209e11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from otree.api import Currency as c, currency_range
from ._builtin import Page, WaitPage
from .models import Constants


from random import shuffle, sample


class Instructions(Page):

    def is_displayed(self):
        return self.subsession.round_number == 1


class Default_Task(Page):

    # timeout_seconds = 32

    def Input_choices(self):

        Choice_set = [
            (1, '{}'.format(self.player.Choice_1)),
            (2, '{}'.format(self.player.Choice_2)),
            (3, '{}'.format(self.player.Choice_3)),
            (0, '')
        ]
        return Choice_set

    def vars_for_template(self):
        return {'label_1': self.player.Choice_1,
                'label_2': self.player.Choice_2,
                'label_3': self.player.Choice_3
                }

    form_model = 'player'

    form_fields = ['Input', 'time_stamp_entered', 'time_stamp_click']

    def before_next_page(self):
        # if self.timeout_happened:
        #     post_dict = self.request.POST

        #     self.player.Input = post_dict.get('Input')
        #     if self.player.Input is None:
        #         self.player.Input = 0

        self.player.set_payoff()


class Results(Page):

    def is_displayed(self):
        return self.subsession.round_number == Constants.num_rounds

    def vars_for_template(self):
        player_in_all_rounds = self.player.in_all_rounds()
        total_payoff_default = sum(
            [p.default_correct for p in player_in_all_rounds])

        # random_players = sample(self.player.in_all_rounds(), 1)
        # self.player.payoff = sum([p.payoff_default for p in random_players])
        # + sum([p.payoff_load for p in random_players])

        return {'player_in_all_rounds': player_in_all_rounds,
                'total_payoff_default': total_payoff_default}


class NormalWaitPage(WaitPage):

    title_text = "Bitte warten Sie"
    body_text = "Bitte warten Sie. Das Experiment geht gleich weiter."

    def is_displayed(self):
        return self.subsession.round_number == Constants.num_rounds


page_sequence = [
    Instructions,
    Default_Task,
    # ResultsWaitPage,
    # Results
    NormalWaitPage

]