from otree.api import * import numpy as np from numpy import random from random import SystemRandom, sample from random import choices import pandas as pd import csv doc = """ Creates Table with Visual Tracing """ class Constants(BaseConstants): name_in_url = 'Main-Task' # Sustainability Sets lS1, lS2 = [[0,1],[1,2],[0,2]], [[0,0],[1,1],[2,2]] ## Quality Sets lQc,lQs, lQe= [[1,0],[2,0],[2,1]], [[0,1],[0,2],[1,2]], [[0,0],[1,1],[2,2]] ## Price Sets lPrices = [1,1.5,2,2.5,3,3] lPoe, lPse, lPeq = [],[],[] for x in lPrices: for y in lPrices: lPair = [x,y] if x>y: lPoe.append(lPair) elif x Constants.num_prounds): participant.iOutFocus = int(participant.iOutFocus) + player.iFocusLost participant.iFullscreenChanges = int(participant.iFullscreenChanges) + player.iFullscreenChange participant.dTimeOutFocus = float(participant.dTimeOutFocus) + player.dFocusLostT # If this is selected trial, save relevant variables if (participant.SelectedTrial==player.round_number): if (player.iDec==0): participant.Price = player.P0 participant.Q = player.Q0 participant.S = player.S0 else: participant.Price = player.P1 participant.Q = player.Q1 participant.S = player.S1 class Between(Page): form_model = 'player' form_fields = [ 'dRTbetween', ] @staticmethod def js_vars(player: Player): session = player.subsession.session p = player.participant return { 'StartLeft' : player.bStartLeft, 'bRequireFS' : session.config['bRequireFS'], 'bCheckFocus' : session.config['bCheckFocus'], 'dPixelRatio' : p.dPixelRatio, } class Infographics(Page): @staticmethod def vars_for_template(player): participant = player.participant # Pick images based on treatment for sustainability info if participant.treatment == 1: S2low, S2high, Sgraph = Constants.S2l_l, Constants.S2h_l, Constants.sPathS_l elif participant.treatment == 2: S2low, S2high, Sgraph = Constants.S2l_cv, Constants.S2h_cv, Constants.sPathS_cv else: S2low, S2high, Sgraph = Constants.S2l_cx, Constants.S2h_cx, Constants.sPathS_cx # Create Dictionary with all necessary info dicSustainabilityInfo = { 'Item' : 'Leaf-rating & trees planted', 'Graph' : Sgraph, 'Title' : 'Sustainability', 'p1' : 'leaf', 'p2' : 'sustainability', 'p3' : 'One tree planted', 'p4' : 'trees', 'Symbol' : Constants.imgLeaf_symbol, 'low1' : Constants.S1l, 'low2' : S2low, 'low3' : Constants.S3l, 'hi1' : Constants.S1h, 'hi2' : S2high, 'hi3' : Constants.S3h, 'disclaimer' : "We will sum the points of all participants to calculate how many trees we need to plant and round it up. Let's say you get 0.8 trees and I get 0.5, that means 1.3 trees in total. Then, we will plant 2 trees! Every point counts! ", } dicQualityInfo = { 'Item' : 'Star-rating & Bonus Payment', 'Graph' : Constants.sPathQ_l, 'Title' : 'Quality', 'p1' : 'star', 'p2' : 'quality', 'p3' : 'One pound (£)', 'p4' : Constants.Currency, 'Symbol' : Constants.imgStar_symbol, 'low1' : Constants.Q1l, 'low2' : Constants.Q2l, 'low3' : Constants.Q3l, 'hi1' : Constants.Q1h, 'hi2' : Constants.Q2h, 'hi3' : Constants.Q3h, 'disclaimer' : 'values will be rounded up to the next 50p', } # Pick images based on treatment for sustainability info if participant.PresOrder == 'Qual': dicFirst, dicSecond = dicQualityInfo, dicSustainabilityInfo else: dicFirst, dicSecond = dicSustainabilityInfo, dicQualityInfo return dict( First = dicFirst, Second = dicSecond, Slides = Constants.Slides, ) ## Show only in the middle of the experiment @staticmethod def is_displayed(player): return ((player.iBlock==2) & (player.iBlockTrial==1)) def js_vars(player: Player): session = player.subsession.session p = player.participant # Pick images based on treatment for sustainability info if p.PresOrder == 'Qual': first, second = Constants.Q3l, Constants.S1h else: first, second = Constants.S3l, Constants.Q1h return { 'StartLeft' : player.bStartLeft, 'bRequireFS' : session.config['bRequireFS'], 'bCheckFocus' : session.config['bCheckFocus'], 'dPixelRatio' : p.dPixelRatio, 'firstAnswer' : str(first), 'secondAnswer' : str(second), } class Ready(Page): @staticmethod def vars_for_template(player: Player): # Choose text depending round if (player.round_number==1): if (player.participant.iCurrentBlock==1): sText = 'Now, we will continue with the experiment.' else: sText = 'Now, we will start with the practice rounds.' else: sText = 'The practice rounds are over. Now, we will continue with the experiment.' # Return selected text return dict( text = sText ) @staticmethod def is_displayed(player): # Displayed on: First round of each block or first round after the trials return ( (player.round_number==1) or ((player.round_number==Constants.num_prounds+1) and (player.participant.iCurrentBlock==1)) ) page_sequence = [Ready, Between, Task]