from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) from PIL import Image from random import randint from sklearn.utils import shuffle import numpy as np import math from collections import Counter author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'pd_questionnaire' players_per_group = None num_rounds = 1 pay_per_correct_matrix = 1 minutes_to_complete_raven = 10 exchange_rate_adjustment = 0.1*1/10 # THIS NEEDS TO BE ADJUSTED TO THE EXCHANGE RATE TO PRESERVE THE PER BALL TO EITHER 1 or 2 cents. num_tokens_at_adjusted_rate = 0 # given the adjusted exchange rate, 5 points are worth 10 cents # We have decided not to pay cooperation_payoff = 15 sucker_payoff = 0 temptation_payoff = 25 defection_payoff = 10 class Subsession(BaseSubsession): def determine_part_to_pay(self): self.which_between_part_one_and_two_we_pay = randint(0, 1) # Because of python language, 0 is Part 1 and 1 is Part 2 if self.which_between_part_one_and_two_we_pay ==0: self.we_dont_pay=1 elif self.which_between_part_one_and_two_we_pay ==1: self.we_dont_pay=0 players = self.get_players() for p in players: p.participant.vars['which_between_part_one_and_two_we_pay'] = self.which_between_part_one_and_two_we_pay p.participant.vars['we_dont_pay'] = self.we_dont_pay which_between_part_one_and_two_we_pay = models.IntegerField() we_dont_pay = models.IntegerField() class Group(BaseGroup): pass class Player(BasePlayer): def passing_payoffs(self): #self.participant.vars['payoffs_vector'].append(self.raven_payoff * Constants.exchange_rate_adjustment) self.conditional_choice_matters = self.participant.vars['conditional_choice_matters'] self.part_relevant_for_payment = self.participant.vars['which_between_part_one_and_two_we_pay'] + 1 self.total_payoff = sum(self.participant.vars['payoffs_vector']) - self.participant.vars['payoffs_vector'][self.participant.vars['we_dont_pay']] # Need to put this in the admin report for payments self.participant.payoff = self.total_payoff def raven_total(self): self.participant.vars['correct_raven'] = self.raven_total total_payoff = models.CurrencyField() part_relevant_for_payment = models.IntegerField() conditional_choice_matters = models.IntegerField() norm_following_payoff = models.CurrencyField() risk_taking = models.IntegerField( widget=widgets.RadioSelectHorizontal, label='', ) thorough_worker = models.IntegerField( widget=widgets.RadioSelectHorizontal, label='', ) communicative = models.IntegerField( widget=widgets.RadioSelectHorizontal, label='', ) rough = models.IntegerField( widget=widgets.RadioSelectHorizontal, label='', ) inventive = models.IntegerField( widget=widgets.RadioSelectHorizontal, label='', ) worries = models.IntegerField( widget=widgets.RadioSelectHorizontal, label='', ) forgive = models.IntegerField( widget=widgets.RadioSelectHorizontal, label='', ) lazy = models.IntegerField( widget=widgets.RadioSelectHorizontal, label='', ) extrovert = models.IntegerField( widget=widgets.RadioSelectHorizontal, label='', ) sense_for_art = models.IntegerField( widget=widgets.RadioSelectHorizontal, label='', ) nervous = models.IntegerField( widget=widgets.RadioSelectHorizontal, label='', ) efficient = models.IntegerField( widget=widgets.RadioSelectHorizontal, label='', ) reserved = models.IntegerField( widget=widgets.RadioSelectHorizontal, label='', ) respectful = models.IntegerField( widget=widgets.RadioSelectHorizontal, label='', ) vivid_imagination = models.IntegerField( widget=widgets.RadioSelectHorizontal, label='', ) stress_management = models.IntegerField( widget=widgets.RadioSelectHorizontal, label='', ) # reliable_answers = models.IntegerField( # widget=widgets.RadioSelectHorizontal, # label='Can we rely on your answers?', # # ) raven_01 = models.IntegerField( widget=widgets.RadioSelectHorizontal, label='', ) raven_02 = models.IntegerField( widget=widgets.RadioSelectHorizontal, label='', ) raven_03 = models.IntegerField( widget=widgets.RadioSelectHorizontal, label='', ) raven_04 = models.IntegerField( widget=widgets.RadioSelectHorizontal, label='', ) raven_05 = models.IntegerField( widget=widgets.RadioSelectHorizontal, label='', ) raven_06 = models.IntegerField( widget=widgets.RadioSelectHorizontal, label='', ) raven_07 = models.IntegerField( widget=widgets.RadioSelectHorizontal, label='', ) raven_08 = models.IntegerField( widget=widgets.RadioSelectHorizontal, label='', ) raven_09 = models.IntegerField( widget=widgets.RadioSelectHorizontal, label='', ) raven_10 = models.IntegerField( widget=widgets.RadioSelectHorizontal, label='', ) raven_total = models.IntegerField() raven_payoff = models.CurrencyField() female = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices= [[0, 'männlich'], [1, 'weiblich']])