from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random import pandas as pd from datetime import date #from django import forms norms_table = pd.read_excel('survey/norms_table.xlsx') norms_table_id = norms_table['id'].tolist() class Constants(BaseConstants): name_in_url = 'survey_DE' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): def creating_session(self): # randomize to treatments for player in self.get_players(): player.choice_order = random.choice(['take first','give first']) player.treatment_group = random.choice(['baseline','full signal','diluted signal']) if player.treatment_group == 'diluted signal': player.diluted_selection = random.choice(['add take','add give']) if player.treatment_group == 'full signal': player.norm_group = ' '.join([str(elem) for elem in random.sample(norms_table_id, 10)]) elif player.treatment_group == 'diluted signal': player.norm_group = ' '.join([str(elem) for elem in random.sample(norms_table_id, 7)]) pass class Group(BaseGroup): pass class Player(BasePlayer): # vacc_intent_order = models.StringField() choice_order = models.StringField() treatment_group = models.StringField() diluted_selection = models.StringField() norm_group = models.StringField() group_give_count = models.IntegerField() group_statusquo_count = models.IntegerField() group_take_count = models.IntegerField() charity_decision_take = models.StringField(choices=[['Take', 'Take from Charity'], ['Status Quo', 'No Change'], ['Give', 'Give to Charity']], label='You now have to decide whether you want to...', widget=widgets.RadioSelect) charity_decision_give = models.StringField(choices=[['Give', 'Give to Charity'], ['Status Quo', 'No Change'], ['Take', 'Take from Charity']], label='You now have to decide whether you want to...', widget=widgets.RadioSelect) charity_decision_full_take = models.StringField(choices=[['Take', 'Take from Charity'], ['Status Quo','No Change'], ['Give', 'Give to Charity']], label='You now have to decide whether you want to...', widget=widgets.RadioSelect) charity_decision_full_give = models.StringField(choices=[['Give', 'Give to Charity'], ['Status Quo', 'No Change'], ['Take', 'Take from Charity']], label='You now have to decide whether you want to...', widget=widgets.RadioSelect) charity_decision_diluted_take = models.StringField(choices=[['Take', 'Take from Charity'], ['Status Quo', 'No Change'], ['Give', 'Give to Charity']], label='You now have to decide whether you want to...', widget=widgets.RadioSelect) charity_decision_diluted_give = models.StringField(choices=[['Give', 'Give to Charity'], ['Status Quo', 'No Change'], ['Take', 'Take from Charity']], label='You now have to decide whether you want to...', widget=widgets.RadioSelect) def make_tenscale_field(label): return models.IntegerField(choices=[[0,''], [1,''], [2,''], [3,''], [4,''], [5,''], [6,''], [7,''], [8,''], [9,''], [10,'']], label=label, widget=widgets.RadioSelectHorizontal) def make_krupka_field(label): return models.IntegerField(choices=[[1, ''], [2, ''], [3, ''], [4, '']], label=label, widget=widgets.RadioSelect) def make_slider_field(label): return models.IntegerField(min=0,max=10, label=label, widget=widgets.Slider, initial=0) krupka1_take = make_krupka_field('Take from charity') krupka1_statusquo = make_krupka_field('No change') krupka1_give = make_krupka_field('Give to charity') krupka2_take = make_krupka_field('Take from charity') krupka2_statusquo = make_krupka_field('No change') krupka2_give = make_krupka_field('Give to charity') empirical1_take = models.IntegerField(min=0, max=100, initial=0) empirical1_statusquo = models.IntegerField(min=0, max=100, initial=0) empirical1_give = models.IntegerField(min=0, max=100, initial=0) empirical2_take = models.IntegerField(min=0, max=100, initial=0) empirical2_statusquo = models.IntegerField(min=0, max=100, initial=0) empirical2_give = models.IntegerField(min=0, max=100, initial=0) empiricalelicitation1_sum = models.IntegerField() empiricalelicitation1_incorrect = models.IntegerField(initial=0, blank = True) empiricalelicitation2_sum = models.IntegerField() empiricalelicitation2_incorrect = models.IntegerField(initial=0, blank=True) def empiricalelicitation1_sum_error_message(player, value): print('value is', value) if value != 100: player.empiricalelicitation1_incorrect += 1 return 'Percentages need to sum to 100%' def empiricalelicitation2_sum_error_message(player, value): print('value is', value) if value != 100: player.empiricalelicitation2_incorrect += 1 return 'Percentages need to sum to 100%' # COVID_infection_certain = make_slider_field("Auf einer Skala von 0 (sehr unsicher) bis 10 (sehr sicher), wie sicher sind Sie sich bei dieser Antwort?") # risk = make_tenscale_field("") # SOEP_1 = make_likert_field('... gründlich arbeitet.') Introduction00_time = models.FloatField() Introduction01_time = models.FloatField() Introduction02_time = models.FloatField() Decision_time = models.FloatField() GroupChoices_time = models.FloatField() KrupkaElicitation1_time = models.FloatField() EmpiricalElicitation1_time = models.FloatField() KrupkaElicitation2_time = models.FloatField() EmpiricalElicitation2_time = models.FloatField() ThankYou_time = models.FloatField()