from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants from datetime import datetime import csv import random import time import math import itertools import xlrd # for reading XLS-files # import xlsxwriter module import xlsxwriter class A_Consent_Form(Page): def is_displayed(self): return self.round_number == 1 # only display in the first round def vars_for_template(self): loc = ("Type3_part2/data/A_ConsentForm.xlsx") # To open Workbook wb = xlrd.open_workbook(loc) sheet = wb.sheet_by_index(0) # Get all titles & paragraphs title = sheet.cell_value(1, Constants.language_code) warning = sheet.cell_value(2, Constants.language_code) subtitle1 = sheet.cell_value(3, Constants.language_code) paragraph1 = sheet.cell_value(4, Constants.language_code) subtitle2 = sheet.cell_value(5, Constants.language_code) paragraph2 = sheet.cell_value(6, Constants.language_code) subtitle3 = sheet.cell_value(7, Constants.language_code) paragraph3 = sheet.cell_value(8, Constants.language_code) subtitle4 = sheet.cell_value(9, Constants.language_code) paragraph4 = sheet.cell_value(10, Constants.language_code) subtitle5 = sheet.cell_value(11, Constants.language_code) paragraph5 = sheet.cell_value(12, Constants.language_code) subtitle6 = sheet.cell_value(13, Constants.language_code) paragraph6 = sheet.cell_value(14, Constants.language_code) subtitle7 = sheet.cell_value(15, Constants.language_code) paragraph7 = sheet.cell_value(16, Constants.language_code) consent = sheet.cell_value(17, Constants.language_code) confirm = sheet.cell_value(18, Constants.language_code) return dict( title=title, warning=warning, subtitle1=subtitle1, subtitle2=subtitle2, subtitle3=subtitle3, subtitle4=subtitle4, subtitle5=subtitle5, subtitle6=subtitle6, subtitle7=subtitle7, paragraph1=paragraph1, paragraph2=paragraph2, paragraph3=paragraph3, paragraph4=paragraph4.format(showup_fee = Constants.showup_fee, currency_real = Constants.currency_real, currency = Constants.currency), # showup_fee is only a placeholder in the excel-string: set value here paragraph5=paragraph5, paragraph6=paragraph6, paragraph7=paragraph7, consent=consent, confirm=confirm ) class A2_prolificID(Page): form_model = 'player' form_fields = ['prolificID'] def is_displayed(self): return self.round_number == 1 # only display in the first round def before_next_page(self): self.participant.vars['prolificID'] = self.player.prolificID class B_Instructions_General(Page): def is_displayed(self): self.player.display = False if self.round_number == 1: try: if self.player.participant.vars['selectedType2'] == 1: self.player.display = True else: self.player.display = True except: self.player.display = True else: self.player.display = False return self.player.display # only display in the first round and if player was selected as type2 def vars_for_template(self): return dict( currency=Constants.currency, currency_real=Constants.currency_real, XR=Constants.XR, showup_fee=Constants.showup_fee, ) return self.player.display class C_Intro_Types(Page): form_model = 'player' def is_displayed(self): return self.round_number == 1 # only display in the first round def vars_for_template(self): loc = ("Type3_part2/data/C_Intro_Types.xlsx") # To open Workbook wb = xlrd.open_workbook(loc) sheet = wb.sheet_by_index(0) # Get all titles & paragraphs title = sheet.cell_value(1, Constants.language_code) paragraph1 = sheet.cell_value(2, Constants.language_code) confirm = sheet.cell_value(3, Constants.language_code) return dict( title=title, paragraph1=paragraph1, confirm=confirm, ) class F_Description_Options(Page): form_model = 'player' def is_displayed(self): return self.round_number == 1 # only display in the first round def vars_for_template(self): return dict( num_rounds=Constants.num_rounds, FixedPointsType2=Constants.FixedPointsType2, currency=Constants.currency, ) class J_Results(Page): def is_displayed(self): return self.round_number == Constants.num_rounds #only display in the last round def vars_for_template(self): player_in_all_rounds = self.player.in_all_rounds() return dict( player_in_all_rounds=player_in_all_rounds, TotalPayoffType2=Constants.TotalPayoffType2, currency_real=Constants.currency_real, currency=Constants.currency, FixedPointsType1=Constants.FixedPointsType1, ) class H_preQuestion(Page): def is_displayed(self): return self.round_number == 1 # only display in the first round page_sequence = [ A_Consent_Form, A2_prolificID, B_Instructions_General, C_Intro_Types, F_Description_Options, H_preQuestion, J_Results, ]