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 = ("Part2_type2/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, ) 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 = ("Part2_type2/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 D_Intro_Title_Part1(Page): form_model = 'player' form_fields = ['tab_intro_title_part1', 'focus_intro_title_part1', 'totaltime_intro_title_part1'] def is_displayed(self): return self.round_number == 1 # only display in the first round def vars_for_template(self): loc = ("Part2_type2/data/D_Intro_Title_Part1.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) confirm = sheet.cell_value(2, Constants.language_code) return dict( title=title.format(currency=Constants.currency,FixedPointsType3=Constants.FixedPointsType3), confirm=confirm ) class E_Description_Decision(Page): def is_displayed(self): return self.round_number == 1 and self.player.display # only display in the first round def vars_for_template(self): return dict( num_rounds=Constants.num_rounds, ) class F_Description_Options(Page): form_model = 'player' form_fields = ['ControlQuestion1', 'ControlQuestion2', 'ControlQuestion3', 'ControlQuestion4', 'counterWrong_page1', 'tab_desc_lotteries_part1', 'focus_desc_lotteries_part1', 'totaltime_desc_lotteries_part1'] 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, FixedPointsType3=Constants.FixedPointsType3, currency=Constants.currency, ) class I_Question(Page): form_model = 'player' form_fields = ['optionchoicetype2', 'tab_question_part1', 'focus_question_part1', 'totaltime_question_part1'] ## with open('Part2_type2/type2.csv') as decisions_file: ## questions= list(csv.DictReader(decisions_file)) def is_displayed(self): return self.player.in_round(1).display def before_next_page(self): return self.round_number == Constants.num_rounds 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, ) class G_Xclusion(Page): def is_displayed(self): return self.player.counterWrong_page1==3 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, D_Intro_Title_Part1, E_Description_Decision, F_Description_Options, G_Xclusion, H_preQuestion, I_Question, J_Results, ]