from otree.api import Currency as c, currency_range from . import models from ._builtin import Page, WaitPage from .models import Constants from django.apps import apps import random import math import re from datetime import datetime class einleitungstext(Page): template_name = 'bedarfsgerechtigkeit3/einleitungstext.html' def is_displayed(self): return True def before_next_page(self): self.player.time_started = datetime.utcnow() page_sequence = [einleitungstext] class ueberuntereinleitung(Page): def vars_for_template(self): question_data = self.participant.vars['questions_ueberunter'][int(self.player.participant.vars['num_question_ueberunter']) -1] return { 'treatment_nummer': self.player.treatment_number, } class ueberunterstich(Page): def is_displayed(self): return True class ueberunteruebersicht(Page): def vars_for_template(self): question_data = self.participant.vars['questions_ueberunter'] question_reihenfolge = range(0, Constants.num_total_questions_ueberunter) num_scenario = 1 tabellenseite1 = '' version_number = self.player.participant.vars['version_number'] for i in question_reihenfolge: if version_number == 2: tabellenseite1 += '''

Szenario '''+str(num_scenario)+'''

Cehdorf

Das Regionalparlament hat entschieden, dass der Haushalt Folgendes bekommt.

Behdorf

Das Regionalparlament hat entschieden, dass die Haushalte Folgendes bekommen.

Haushalt
A
Haushalt
B
Haushalt
A
braucht
'''+question_data[i]['scen_2_household_A_need']+'''
'''+question_data[i]['scen_2_household_B_need']+'''
braucht
'''+question_data[i]['scen_1_household_A_need']+'''
bekommt
'''+question_data[i]['scen_2_household_A_endowment']+'''
'''+question_data[i]['scen_2_household_B_endowment']+'''
bekommt
'''+question_data[i]['scen_1_household_A_endowment']+'''


''' else: tabellenseite1 += '''

Szenario '''+str(num_scenario)+'''

Behdorf

Das Regionalparlament hat entschieden, dass der Haushalt Folgendes bekommt.

Cehdorf

Das Regionalparlament hat entschieden, dass die Haushalte Folgendes bekommen.

Haushalt
A
Haushalt
A
Haushalt
B
braucht
'''+question_data[i]['scen_1_household_A_need']+'''
braucht
'''+question_data[i]['scen_2_household_A_need']+'''
'''+question_data[i]['scen_2_household_B_need']+'''
bekommt
'''+question_data[i]['scen_1_household_A_endowment']+'''
bekommt
'''+question_data[i]['scen_2_household_A_endowment']+'''
'''+question_data[i]['scen_2_household_B_endowment']+'''


''' num_scenario += 1 return { 'tabellenseite1': tabellenseite1, 'question_data': question_data, 'num_uebersicht': self.participant.vars['num_uebersicht'], } class ueberunterfragen(Page): form_model = 'player' def get_form_fields(self): if self.player.participant.vars['version_number'] == 1: return ('{}ueberunter1'.format(self.player.participant.vars['situation_id_ueberunter']), '{}ueberunter2'.format(self.player.participant.vars['situation_id_ueberunter']),) else: return ('{}ueberunter2'.format(self.player.participant.vars['situation_id_ueberunter']), '{}ueberunter1'.format(self.player.participant.vars['situation_id_ueberunter']),) def is_displayed(self): return True def vars_for_template(self): question_data = self.participant.vars['questions_ueberunter'][int(self.player.participant.vars['num_question_ueberunter']) -1] return { 'slider_1': "#id_{}ueberunter1".format(question_data['situation_id']), 'slider_2': "#id_{}ueberunter2".format(question_data['situation_id']), 'treatment_nummer': self.player.treatment_number, 'frage_nummer': self.player.participant.vars['num_question_ueberunter'], 'scen_1_household_A_need': question_data['scen_1_household_A_need'], 'scen_1_household_A_endowment': question_data['scen_1_household_A_endowment'], 'version_number': self.player.participant.vars['version_number'], 'scen_2_household_A_need': question_data['scen_2_household_A_need'], 'scen_2_household_B_need': question_data['scen_2_household_B_need'], 'scen_2_household_A_endowment': question_data['scen_2_household_A_endowment'], 'scen_2_household_B_endowment': question_data['scen_2_household_B_endowment'], } class ueberuntersicher(Page): form_model = 'player' def get_form_fields(self): if self.player.participant.vars['version_number'] == 1: return ('{}ueberuntersicher1'.format(self.player.participant.vars['situation_id_ueberunter']), '{}ueberuntersicher2'.format(self.player.participant.vars['situation_id_ueberunter']),) else: return ('{}ueberuntersicher2'.format(self.player.participant.vars['situation_id_ueberunter']), '{}ueberuntersicher1'.format(self.player.participant.vars['situation_id_ueberunter']),) def vars_for_template(self): question_data = self.participant.vars['questions_ueberunter'][int(self.player.participant.vars['num_question_ueberunter']) -1] return { 'slider_1': "#id_{}ueberunter1".format(question_data['situation_id']), 'slider_2': "#id_{}ueberunter2".format(question_data['situation_id']), 'treatment_nummer': self.player.treatment_number, 'frage_nummer': self.player.participant.vars['num_question_ueberunter'], 'scen_1_household_A_need': question_data['scen_1_household_A_need'], 'scen_1_household_A_endowment': question_data['scen_1_household_A_endowment'], 'version_number': self.player.participant.vars['version_number'], 'scen_2_household_A_need': question_data['scen_2_household_A_need'], 'scen_2_household_B_need': question_data['scen_2_household_B_need'], 'scen_2_household_A_endowment': question_data['scen_2_household_A_endowment'], 'scen_2_household_B_endowment': question_data['scen_2_household_B_endowment'], } def is_displayed(self): return True def before_next_page(self): self.player.reihenfolge_ueberunter += 'ueberunter{} '.format(self.player.participant.vars['num_question_ueberunter']) if self.player.participant.vars['num_question_ueberunter'] != Constants.num_total_questions_ueberunter: self.player.participant.vars['num_question_ueberunter'] += 1 self.player.question_data_ueberunter = self.player.current_question_ueberunter() self.player.participant.vars['situation_id_ueberunter'] = self.player.question_data_ueberunter['situation_id'] class ueberunterfrei(Page): form_model = 'player' form_fields = ['ueberunterfrei'] def is_displayed(self): return True class verteileinleitung(Page): def vars_for_template(self): treatment_number = self.player.treatment_number return{ 'treatment_number': treatment_number } class verteilstich(Page): def vars_for_template(self): treatment_number = self.player.treatment_number return{ 'treatment_number': treatment_number } class verteil(Page): form_model = 'player' def get_form_fields(self): if self.player.participant.vars['version_number'] == 1: return ('{}verteil1'.format(self.player.participant.vars['situation_id_verteil']), '{}verteil2'.format(self.player.participant.vars['situation_id_verteil'])) else: return ('{}verteil2'.format(self.player.participant.vars['situation_id_verteil']), '{}verteil1'.format(self.player.participant.vars['situation_id_verteil'])) def error_message(self, values): question_data = self.participant.vars['questions_verteil'][self.player.participant.vars['num_question_verteil'] - 1] blah = question_data['allocation'] if ((values["{}verteil1".format(self.player.participant.vars['situation_id_verteil'])] + values["{}verteil2".format(self.player.participant.vars['situation_id_verteil'])]) % 10) > 0: return 'Bitte geben Sie in beiden Feldern einen Wert ein, der durch 10 teilbar oder 0 ist.' elif ((values["{}verteil1".format(self.player.participant.vars['situation_id_verteil'])]) % 10) > 0: return 'Bitte geben Sie für Haushalt A einen Wert ein, der durch 10 teilbar oder 0 ist.' elif (( values["{}verteil2".format(self.player.participant.vars['situation_id_verteil'])]) % 10) > 0: return 'Bitte geben Sie für Haushalt B einen Wert ein, der durch 10 teilbar oder 0 ist.' elif values["{}verteil1".format(self.player.participant.vars['situation_id_verteil'])] + values["{}verteil2".format(self.player.participant.vars['situation_id_verteil'])] > int(blah): return 'Die Summe beider Eingaben darf ' + blah + ' nicht übersteigen.' def vars_for_template(self): question_data = self.participant.vars['questions_verteil'][self.player.participant.vars['num_question_verteil'] -1] treatment_number = self.player.treatment_number return{ 'treatment_number': treatment_number, 'version_number': self.player.participant.vars['version_number'], 'allocation': question_data['allocation'], 'household_A_need': question_data['household_A_need'], 'household_B_need': question_data['household_B_need'], 'verteil1': "#id_{}verteil1".format(question_data['situation_id']), 'verteil2': "#id_{}verteil2".format(question_data['situation_id']), } def before_next_page(self): self.player.reihenfolge_verteil += 'verteil{} '.format(self.player.participant.vars['num_question_verteil'] -1) if self.player.participant.vars['num_question_verteil'] != Constants.num_total_questions_verteil: self.player.participant.vars['num_question_verteil'] += 1 self.player.question_data_verteil = self.player.current_question_verteil() self.player.participant.vars['situation_id_verteil'] = self.player.question_data_verteil['situation_id'] class verteilauswahl(Page): form_model = 'player' def get_form_fields(self): return ('verteilauswahl',) #('{}verteil1'.format(self.player.participant.vars['situation_id_verteil']), # '{}verteil2'.format(self.player.participant.vars['situation_id_verteil'])) # def error_message(self, values): # question_data = self.participant.vars['questions_verteil'][self.player.participant.vars['num_question_verteil'] - 1] # blah = question_data['allocation'] # if ((values["{}verteil1".format(self.player.participant.vars['situation_id_verteil'])] + values["{}verteil2".format(self.player.participant.vars['situation_id_verteil'])]) % 10) > 0: # return 'Bitte geben Sie in beiden Feldern einen Wert ein, der durch 10 teilbar oder 0 ist.' # elif values["{}verteil1".format(self.player.participant.vars['situation_id_verteil'])] + values["{}verteil2".format(self.player.participant.vars['situation_id_verteil'])] > int(blah): # return 'Die Summe beider Eingaben darf ' + blah + ' nicht übersteigen.' def vars_for_template(self): question_data = self.participant.vars['questions_verteil'][self.player.participant.vars['num_question_verteil'] -1] treatment_number = self.player.treatment_number return{ 'version_number': self.player.participant.vars['version_number'], 'treatment_number': treatment_number, 'allocation': question_data['allocation'], 'household_A_need': question_data['household_A_need'], 'household_B_need': question_data['household_B_need'], 'verteil1': "#id_{}verteil1".format(question_data['situation_id']), 'verteil2': "#id_{}verteil2".format(question_data['situation_id']), } # def before_next_page(self): # self.player.reihenfolge_verteil += 'verteil{} '.format(self.player.participant.vars['num_question_verteil'] -1) # if self.player.participant.vars['num_question_verteil'] != Constants.num_total_questions_verteil: # self.player.participant.vars['num_question_verteil'] += 1 # self.player.question_data_verteil = self.player.current_question_verteil() # self.player.participant.vars['situation_id_verteil'] = self.player.question_data_verteil['situation_id'] class verteilfrei(Page): form_model = 'player' form_fields = ['verteilfrei'] def vars_for_template(self): treatment_number = self.player.treatment_number return{ 'treatment_number': treatment_number } class assoziationen(Page): form_model = 'player' form_fields = ['assoquadrat','assopersonen'] class kabinennummer(Page): form_model = 'player' form_fields = ['kabinennummer'] class Results(Page): def vars_for_template(self): return { 'treatment_nummer': self.player.treatment_number, 'auszahlung': self.session.config['participation_fee'] } page_sequence.extend([verteileinleitung,verteilstich]) for verteil_iterator in Constants.total_questions_verteil: page_sequence.extend([verteil]) page_sequence.extend([verteilauswahl,verteilfrei,ueberuntereinleitung,ueberunterstich,ueberunteruebersicht]) for ueberunter_iterator in Constants.total_questions_ueberunter: page_sequence.extend([ueberunterfragen,ueberuntersicher]) page_sequence.extend([ueberunterfrei,assoziationen,kabinennummer,Results])