from django.utils.safestring import mark_safe
from django.template.defaulttags import register
from otree.api import Currency as c, currency_range
from ._builtin import Page, WaitPage
from .models import Constants
@register.simple_tag()
def blue():
return mark_safe('BLUE')
@register.simple_tag()
def green():
return mark_safe('GREEN')
CARDS = {
'Introduction1': ('Ground Rules', 'ground_rules.html'),
'Introduction2': ('How will you be compensated?', 'compensated.html'),
'Introduction3': ('Overview of session', 'overview_of_session.html'),
'Introduction4': ('Procedures', 'procedures.1.html'),
'Introduction5': ('Procedures', 'procedures.2.html'),
'Introduction6': ('Procedures', 'procedures.3.html'),
'Introduction7': ('Point Earnings', 'point_earnings.1.html'),
'Introduction8': ('Point Earnings', 'point_earnings.2.html'),
'Introduction9': ('Point Earnings', 'point_earnings.3.html'),
'Introduction10': ('Feedback, Questionnaire and Payment', 'feedback.html'),
}
class FirstRoundWaitPage(WaitPage):
title_text = "Wait"
body_text = "Please wait for the experiment to continue"
def is_displayed(self):
return self.round_number == 1
class GenericWaitPage(WaitPage):
title_text = "Wait"
body_text = "Please wait for the experiment to continue"
class SonaPage(Page):
form_model = 'player'
form_fields = ['sona_id']
def is_displayed(self):
return self.round_number == 1
class Introduction1(Page):
template_name = 'scrutiny/Introduction.html'
def is_displayed(self):
return self.round_number == 1
def vars_for_template(self):
title, card = CARDS[self.__class__.__name__]
return {'title': title, 'card': f'scrutiny/cards/{card}'}
class Introduction2(Introduction1):
form_model = 'player'
form_fields = ['compensated']
class Introduction3(Introduction1):
form_model = 'player'
form_fields = ['overview']
class Introduction4(Introduction1):
form_model = 'player'
form_fields = ['procedures_1']
class Introduction5(Introduction1):
form_model = 'player'
form_fields = ['procedures_2']
class Introduction6(Introduction1):
form_model = 'player'
form_fields = ['procedures_3']
class Introduction7(Introduction1):
pass
class Introduction8(Introduction1):
pass
class Introduction9(Introduction1):
form_model = 'player'
form_fields = ['point_earnings_1', 'point_earnings_2', 'point_earnings_3']
class Introduction10(Introduction1):
pass
class InstructionsPage1(Page):
def is_displayed(self):
return self.round_number == 1
def js_vars(self):
return {'timeout': self.session.config['green_decision_timeout']}
class InstructionsPage2(InstructionsPage1):
pass
class InstructionsPage3(InstructionsPage1):
pass
class GreenWaitPage(Page):
def is_displayed(self):
return self.round_number == 1 and \
self.player.color == Constants.green
def get_timeout_seconds(self):
return self.session.config['green_wait_timeout']
class RepeatPage(Page):
def is_displayed(self):
return self.round_number > 1
def get_timeout_seconds(self):
return self.session.config['repeat_timeout']
class BlueSignalPage(Page):
def is_displayed(self):
return self.player.color == Constants.blue
def js_vars(self):
return {'timeout': self.session.config['reporting_timeout']}
class ReportingPage(Page):
def _num_blues(self) -> int:
# This assumes even number of players, checked in Subsession
return int(len(self.subsession.get_players()) / 2)
def get_timeout_seconds(self):
return self.session.config['reporting_timeout'] * self._num_blues()
def is_displayed(self):
return self.session.config['high_public_scrutiny']
def js_vars(self):
return {
'num_blues': self._num_blues(),
'timeout': self.session.config['reporting_timeout'],
}
class BlueDecisionPage(Page):
form_model = 'player'
form_fields = ['decision']
def is_displayed(self):
return self.player.color == Constants.blue
def vars_for_template(self):
return {
'button_up': self.player.state != Constants.down,
'button_middle': True,
'button_down': self.player.state != Constants.up,
}
def js_vars(self):
return {'timeout': self.session.config['blue_decision_timeout']}
class GreenDecisionPage(Page):
form_model = 'player'
form_fields = ['decision']
def is_displayed(self):
return self.player.color == Constants.green
def vars_for_template(self):
decision = self.group.get_player_by_id(self.player.other_id).decision
return {'state': decision}
def js_vars(self):
return {'timeout': self.session.config['green_decision_timeout']}
class JudgementPage(Page):
form_model = 'player'
form_fields = ['judgement']
def is_displayed(self):
return self.player.color == Constants.blue or \
self.session.config['high_public_scrutiny']
def js_vars(self):
return {'timeout': self.session.config['green_judgement_timeout']}
class PayoffWaitPage(WaitPage):
after_all_players_arrive = 'set_payoffs'
class Results(Page):
def is_displayed(self):
return self.round_number == Constants.num_rounds
def vars_for_template(self):
totals = {Constants.up: 0, Constants.middle: 0, Constants.down: 0}
for player in self.player.in_all_rounds():
totals[player.state] += 1
additional = \
c(self.participant.payoff).to_real_world_currency(self.session)
return {
'totals': totals,
'additional': additional,
}
page_sequence = [
SonaPage,
Introduction1, FirstRoundWaitPage,
Introduction2, FirstRoundWaitPage,
Introduction3, FirstRoundWaitPage,
Introduction4, FirstRoundWaitPage,
Introduction5, FirstRoundWaitPage,
Introduction6, FirstRoundWaitPage,
Introduction7, FirstRoundWaitPage,
Introduction8, FirstRoundWaitPage,
Introduction9, FirstRoundWaitPage,
Introduction10, FirstRoundWaitPage,
InstructionsPage1, FirstRoundWaitPage,
InstructionsPage2, FirstRoundWaitPage,
InstructionsPage3, FirstRoundWaitPage,
GreenWaitPage, GenericWaitPage,
RepeatPage, GenericWaitPage,
BlueSignalPage, GenericWaitPage,
ReportingPage, GenericWaitPage,
BlueDecisionPage, GenericWaitPage,
GreenDecisionPage, GenericWaitPage,
JudgementPage, PayoffWaitPage,
Results
]