from otree.api import *
#============================================================================#
#
# IADB SURVEY
#
# - uses unifed otree new module structure (no django dependant)
#
# * comments are welcomed to pavel.ojeda@outlook.com
#============================================================================#
doc = """
Your app description
"""
import random
import csv
import json
#-----------------------------------------------------------------------------#
class Constants(BaseConstants):
name_in_url = 'trial_1'
players_per_group = None
num_rounds = 1
class Subsession(BaseSubsession):
pass
class Group(BaseGroup):
pass
class Player(BasePlayer):
# (a) General information ------------------------------------------------
name = models.StringField( label='Nombre(s)')
lastname_1 = models.StringField( label='Apellido Paterno')
lastname_2 = models.StringField( label='Apellido Materno')
age = models.IntegerField( label='Edad')
dep_born = models.StringField( label='¿En qué departamento naciste?',
choices = [
'Chuquisaca',
'La Paz',
'Cochabamba',
'Oruro',
'Potosí',
'Tarija',
'Santa Cruz',
'Beni',
'Pando',
'No nací en Bolivia'
],
)
dep_current = models.StringField( label='¿En qué departamento vives actualmente?',
choices = [
'Chuquisaca',
'La Paz',
'Cochabamba',
'Oruro',
'Potosí',
'Tarija',
'Santa Cruz',
'Beni',
'Pando'
],
)
city_current = models.StringField(label='¿En qué ciudad vives actualmente?')
hood = models.StringField(label='¿En qué zona vives actualmente?')
# (b) Highest level of education ------------------------------------------
highschool = models.IntegerField(label='¿Acabaste la escuela (eres bachiller)?',
choices = [
[1, 'Sí, de una escuela fiscal'],
[2, 'Sí, de una escuela privada/particular'],
[3, 'Todavía no acabo la escuela'],
[4, 'Nunca fui a la escuela'],
],
widget=widgets.RadioSelect()
)
edu_mom = models.IntegerField(label='¿Cuál es el nivel de educación más alto que tu madre alcanzó?',
choices = [
[1, 'Nunca fue a la escuela'],
[2, 'Primaria incompleta'],
[3, 'Primaria completa'],
[4, 'Secundaria incompleta'],
[5, 'Secundaria completa'],
[6, 'Superior: técnica'],
[6, 'Superior: licenciatura'],
[7, 'Superior: Posgrado'],
[8, 'Otra'],
[9, 'No tengo madre'],
],
widget=widgets.RadioSelect()
)
edu_dad = models.IntegerField(label='¿Cuál es el nivel de educación más alto que tu padre alcanzó?',
choices = [
[1, 'Nunca fue a la escuela'],
[2, 'Primaria incompleta'],
[3, 'Primaria completa'],
[4, 'Secundaria incompleta'],
[5, 'Secundaria completa'],
[6, 'Superior: técnica'],
[6, 'Superior: licenciatura'],
[7, 'Superior: Posgrado'],
[8, 'Otra'],
[9, 'No tengo padre'],
],
widget=widgets.RadioSelect()
)
#(d) Ethnic Affiliation --------------------------------------------------
ethnic0 = models.IntegerField(label='¿Tu o alguien en tu familia (padres o abuelos) hablan un idioma indigena?',
choices = [
[1, 'Sí'],
[2, 'No'],
],
widget=widgets.RadioSelect()
)
ethnic1 = models.IntegerField(label='¿Tu o alguien en tu familia (padres o abuelos) nacieron o pertenecen a alguna comunidad indigena?',
choices = [
[1, 'Sí'],
[2, 'No'],
],
widget=widgets.RadioSelect()
)
ethnic2 = models.IntegerField(label='¿Te consideras de ascendencia indigena?',
choices = [
[1, 'Sí'],
[2, 'No'],
],
widget=widgets.RadioSelect()
)
# (c) Labor -----------------------------------------------------------
occupation_mom = models.IntegerField(label='¿Cuál la ocupacion de tu madre?',
choices = [
[1, 'Asalariado'],
[2, 'Cuenta propia'],
[3, 'Trabaja en el estado'],
[4, 'Otro'],
[5, 'No trabaja'],
[6, 'No tengo madre'],
],
widget=widgets.RadioSelect()
)
occupation_dad = models.IntegerField(label='¿Cuál la ocupacion de tu padre?',
choices = [
[1, 'Asalariado'],
[2, 'Cuenta propia'],
[3, 'Trabaja en el estado'],
[4, 'Otro'],
[5, 'No trabaja'],
[6, 'No tengo padre'],
],
widget=widgets.RadioSelect()
)
#(e) Income and Wealth --------------------------------------------------
income = models.IntegerField(label='Aproximadamente, ¿Cuál es el ingreso TOTAL de tu hogar?',
choices = [
[1, 'Entre 0 y 19'],
[2, 'Entre 20 y 39'],
[3, 'Entre 40 y 59'],
[4, 'Entre 60 y 79'],
[5, 'Entre 80 y 99'],
],
widget=widgets.RadioSelect()
)
microwave = models.IntegerField(label='En su hogar, ¿usted tiene microondas?',
choices = [
[1, 'Sí'],
[2, 'No'],
],
widget=widgets.RadioSelectHorizontal()
)
laptop = models.IntegerField(label='En su hogar, ¿usted tiene Laptop? ',
choices = [
[1, 'Sí'],
[2, 'No'],
],
widget=widgets.RadioSelectHorizontal()
)
freezer = models.IntegerField(label='En su hogar, ¿usted tiene refrigerador?',
choices = [
[1, 'Sí'],
[2, 'No'],
],
widget=widgets.RadioSelectHorizontal()
)
tv = models.IntegerField(label='En su hogar, ¿usted tiene Televisor LCD/LED? ',
choices = [
[1, 'Sí'],
[2, 'No'],
],
widget=widgets.RadioSelectHorizontal()
)
washingmachine = models.IntegerField(label='En su hogar, ¿usted tiene maquina lavadora? ',
choices = [
[1, 'Sí'],
[2, 'No'],
],
widget=widgets.RadioSelectHorizontal()
)
bicycle = models.IntegerField(label='En su hogar, ¿usted tiene bicicleta? ',
choices = [
[1, 'Sí'],
[2, 'No'],
],
widget=widgets.RadioSelectHorizontal()
)
motorcycle = models.IntegerField(label='En su hogar, ¿usted tiene motocicleta? ',
choices = [
[1, 'Sí'],
[2, 'No'],
],
widget=widgets.RadioSelectHorizontal()
)
auto = models.IntegerField(label='En su hogar, ¿usted tiene auto? ',
choices = [
[1, 'Sí'],
[2, 'No'],
],
widget=widgets.RadioSelectHorizontal()
)
#(d) Political affiliation -----------------------------------------------
warm_party_1 = models.IntegerField()
warm_party_2 = models.IntegerField()
warm_party_3 = models.IntegerField()
warm_candidate_1 = models.IntegerField()
warm_candidate_2 = models.IntegerField()
warm_candidate_3 = models.IntegerField()
warm_candidate_4 = models.IntegerField()
warm_other_1 = models.IntegerField()
warm_other_2 = models.IntegerField()
warm_other_3 = models.IntegerField()
warm_other_4 = models.IntegerField()
warm_other_5 = models.IntegerField()
warm_other_6 = models.IntegerField()
#(f.1) Social distance --------------------------------------------------
confort_1 = models.IntegerField()
confort_2 = models.IntegerField()
confort_3 = models.IntegerField()
confort_4 = models.IntegerField()
#(f.2) social distance --------------------------------------------------
context_1 = models.IntegerField(label='Elija uno de los siguientes sentimientos:',
choices = [
[1, 'Con esperanza'],
[2, 'Sin esperanza'],
],
widget=widgets.RadioSelectHorizontal()
)
context_2 = models.IntegerField(label='Elija uno de los siguientes sentimientos:',
choices = [
[1, 'Calmada(o)'],
[2, 'Enojada(o)'],
],
widget=widgets.RadioSelectHorizontal()
)
context_3 = models.IntegerField(label='Elija uno de los siguientes sentimientos:',
choices = [
[1, 'Feliz'],
[2, 'Enojada(o)'],
],
widget=widgets.RadioSelectHorizontal()
)
context_4 = models.IntegerField(label='Elija uno de los siguientes sentimientos:',
choices = [
[1, 'Orgulloza(o)'],
[2, 'Avergonzada(o)'],
],
widget=widgets.RadioSelectHorizontal()
)
context_5 = models.IntegerField(label='Elija uno de los siguientes sentimientos:',
choices = [
[1, 'Segura(o)'],
[2, 'Asustada(o)'],
],
widget=widgets.RadioSelectHorizontal()
)
context_6 = models.IntegerField(label='Elija uno de los siguientes sentimientos:',
choices = [
[1, 'Intranquila(o)'],
[2, 'Nerviosa(o)'],
],
widget=widgets.RadioSelectHorizontal()
)
context_7 = models.IntegerField(label='Elija uno de los siguientes sentimientos:',
choices = [
[1, 'Calmada(o)'],
[2, 'Preocupada(o)'],
],
widget=widgets.RadioSelectHorizontal()
)
#(h.1) idological distance --------------------------------------------------
idea_0 = models.IntegerField(label='En una escala de izquierda a derecha ¿Con qué tendencia política te identificas mas?',
choices = [
[1, 'Extrema izquierda'],
[2, 'Izquierda'],
[3, 'Centro-izquierda'],
[4, 'Centro'],
[5, 'Centro-derecha'],
[6, 'Derecha'],
[7, 'Extrema derecha'],
],
widget=widgets.RadioSelect()
)
idea_1 = models.StringField(label='En la última elección, ¿por qué partido votaste?',
choices = [
'M.A.S.',
'Comunidad Ciudadana',
'Creemos',
'Otro',
'Blanco/Nulo',
'No voté'
],
widget=widgets.RadioSelect()
)
voting = models.StringField(label='Si las elecciones presidenciales fueran hoy, ¿por quién votarías?',
choices = [ 'Evo Morales Ayma',
'Carlos Mesa',
'Luis Fernando Camacho',
'Otro/Blanco/Nulo'
],
widget=widgets.RadioSelect()
)
idea_2 = models.IntegerField()
idea_3 = models.IntegerField()
idea_4 = models.IntegerField()
idea_5 = models.IntegerField()
idea_6 = models.IntegerField()
#(h.1) idological distance --------------------------------------------------
often_1 = models.IntegerField(label='Durante los conflictos de octubre-noviembre del 2019:',
choices = [
[1, 'Nunca'],
[2, 'Casi nunca'],
[3, 'A veces'],
[4, 'Frecuentemente'],
[5, 'Casi siempre/siempre']
],
widget=widgets.RadioSelect()
)
often_2 = models.IntegerField(label='Durante la elección presidencial del 2020:',
choices = [
[1, 'Nunca'],
[2, 'Casi nunca'],
[3, 'A veces'],
[4, 'Frecuentemente'],
[5, 'Casi siempre/siempre']
],
widget=widgets.RadioSelect()
)
often_3 = models.IntegerField(label='En los últimos 12 meses:',
choices = [
[1, 'Nunca'],
[2, 'Casi nunca'],
[3, 'A veces'],
[4, 'Frecuentemente'],
[5, 'Casi siempre/siempre']
],
widget=widgets.RadioSelect()
)
#-------------------------
often_4 = models.IntegerField(label='¿Cuanta atención le das a la coyuntura política y de gobierno?',
choices = [
[1, 'Siempre'],
[2, 'La mayoría del tiempo'],
[3, 'La mitad del tiempo'],
[4, 'A veces'],
[5, 'Nunca']
],
widget=widgets.RadioSelect()
)
often_5 = models.IntegerField(label='¿Cuán bien entiendes los problemas politicos importantes que encara nuestro país?.',
choices = [
[1, 'Extremadamente bien'],
[2, 'Muy bien'],
[3, 'Bien'],
[4, 'No tan bien'],
[5, 'No los entiendo']
],
widget=widgets.RadioSelect()
)
#(h.2) idological distance --------------------------------------------------
socmedia_1 = models.IntegerField(
label='En promedio, ¿Cuántas horas utilizas Facebook por día?',
choices = [
[0 , "0"],
[1 , "1"],
[1 , "2"],
[1 , "3"],
[1 , "4"],
[1 , "5"],
[1 , "6"],
[1 , "7"],
[1 , "8"],
[1 , "9"],
[1 , "10"],
[1 , "11"],
[1 , "12"],
[99 , "Más de 12"],
]
)
socmedia_2 = models.IntegerField(
label='En promedio, ¿Cuántas horas utilizas Whatsapp por día?',
choices = [
[0 , "0"],
[1 , "1"],
[1 , "2"],
[1 , "3"],
[1 , "4"],
[1 , "5"],
[1 , "6"],
[1 , "7"],
[1 , "8"],
[1 , "9"],
[1 , "10"],
[1 , "11"],
[1 , "12"],
[99 , "Más de 12"],
]
)
socmedia_3 = models.IntegerField(
label='En promedio, ¿Cuántas horas utilizas Instagram por día?',
choices = [
[0 , "0"],
[1 , "1"],
[1 , "2"],
[1 , "3"],
[1 , "4"],
[1 , "5"],
[1 , "6"],
[1 , "7"],
[1 , "8"],
[1 , "9"],
[1 , "10"],
[1 , "11"],
[1 , "12"],
[99 , "Más de 12"],
]
)
socmedia_4 = models.IntegerField(
label='En promedio, ¿Cuántas horas utilizas Twitter por día?',
choices = [
[0 , "0"],
[1 , "1"],
[1 , "2"],
[1 , "3"],
[1 , "4"],
[1 , "5"],
[1 , "6"],
[1 , "7"],
[1 , "8"],
[1 , "9"],
[1 , "10"],
[1 , "11"],
[1 , "12"],
[99 , "Más de 12"],
]
)
socmedia_5 = models.IntegerField(
label='En promedio, ¿Cuántas horas utilizas YouTube por día?',
choices = [
[0 , "0"],
[1 , "1"],
[1 , "2"],
[1 , "3"],
[1 , "4"],
[1 , "5"],
[1 , "6"],
[1 , "7"],
[1 , "8"],
[1 , "9"],
[1 , "10"],
[1 , "11"],
[1 , "12"],
[99 , "Más de 12"],
]
)
socmedia_6 = models.IntegerField(
label='En promedio, ¿Cuántas horas utilizas TikTok por día?',
choices = [
[0 , "0"],
[1 , "1"],
[1 , "2"],
[1 , "3"],
[1 , "4"],
[1 , "5"],
[1 , "6"],
[1 , "7"],
[1 , "8"],
[1 , "9"],
[1 , "10"],
[1 , "11"],
[1 , "12"],
[99 , "Más de 12"],
]
)
color = models.StringField(
label = 'Entre negro y blanco, ¿Cual es tu color favorito?',
choices = [ 'Blanco',
'Negro'
]
)
#----------------------------------------------------------------------------#
# PAGES
class GeneralInformation(Page):
form_model = 'player'
form_fields = [
'name',
'lastname_1',
'lastname_2',
'age',
'dep_born',
'dep_current',
'city_current',
'hood',
'color'
]
class Education(Page):
form_model = 'player'
form_fields = [
'highschool',
'edu_mom',
'edu_dad'
]
class Labor(Page):
form_model = 'player'
form_fields=[
'occupation_mom',
'occupation_dad',
]
class EthnicAffiliation(Page):
form_model = 'player'
form_fields = [
'ethnic0',
'ethnic1',
'ethnic2'
]
@staticmethod
def is_displayed(player):
return player.age > 0
class Durables(Page):
form_model = 'player'
form_fields = [
'microwave',
'laptop',
'freezer',
'tv',
'washingmachine',
'bicycle',
'motorcycle',
'auto'
]
#-------------------------------------------------#
class WarmP1(Page):
form_model = 'player'
form_fields = [
'warm_party_1'
]
class WarmP2(Page):
form_model = 'player'
form_fields = [
'warm_party_2'
]
class WarmP3(Page):
form_model = 'player'
form_fields = [
'warm_party_3'
]
#-------------------------------------------------#
class WarmC1(Page):
form_model = 'player'
form_fields = [
'warm_candidate_1'
]
#Lucho (out)
class WarmC3(Page):
form_model = 'player'
form_fields = [
'warm_candidate_3'
]
class WarmC4(Page):
form_model = 'player'
form_fields = [
'warm_candidate_4'
]
#-------------------------------------------------#
class WarmO1(Page):
form_model = 'player'
form_fields = [
'warm_other_1'
]
class WarmO2(Page):
form_model = 'player'
form_fields = [
'warm_other_2'
]
class WarmO3(Page):
form_model = 'player'
form_fields = [
'warm_other_3'
]
class WarmO4(Page):
form_model = 'player'
form_fields = [
'warm_other_4'
]
class WarmO5(Page):
form_model = 'player'
form_fields = [
'warm_other_5'
]
class WarmO6(Page):
form_model = 'player'
form_fields = [
'warm_other_6'
]
#-------------------------------------------------#
class Conf1(Page):
form_model = 'player'
form_fields = [
'confort_1'
]
class Conf2(Page):
form_model = 'player'
form_fields = [
'confort_2'
]
class Conf3(Page):
form_model = 'player'
form_fields = [
'confort_3'
]
class Conf4(Page):
form_model = 'player'
form_fields = [
'confort_4'
]
#-------------------------------------------------#
class Context(Page):
form_model = 'player'
form_fields = [
'context_1',
'context_2',
'context_3',
'context_4',
'context_5',
'context_6',
'context_7'
]
#-------------------------------------------------#
class Idea(Page):
form_model = 'player'
form_fields = [
'idea_0',
'idea_1',
'voting'
]
class Idea_2(Page):
form_model = 'player'
form_fields = [
'idea_2'
]
class Idea_3(Page):
form_model = 'player'
form_fields = [
'idea_3'
]
class Idea_4(Page):
form_model = 'player'
form_fields = [
'idea_4'
]
class Idea_5(Page):
form_model = 'player'
form_fields = [
'idea_5'
]
class Idea_6(Page):
form_model = 'player'
form_fields = [
'idea_6'
]
#-------------------------------------------------#
class Often1(Page):
form_model = 'player'
form_fields = [
'often_1',
'often_2',
'often_3'
]
class Often2(Page):
form_model = 'player'
form_fields = [
'often_4',
'often_5'
]
class SocMedia(Page):
form_model = 'player'
form_fields = [
'socmedia_1',
'socmedia_2',
'socmedia_3',
'socmedia_4',
'socmedia_5',
'socmedia_6'
]
class Results(Page):
@staticmethod
def before_next_page(player, timeout_happened):
player.participant.name = player.name
player.participant.lastname_1 = player.lastname_1
player.participant.lastname_2 = player.lastname_2
player.participant.color = player.color
player.participant.dep_born = player.dep_born
player.participant.dep_current = player.dep_current
player.participant.city_current = player.city_current
player.participant.hood = player.hood
player.participant.voting = player.voting
page_sequence = [GeneralInformation,
Education,
Labor,
EthnicAffiliation,
Durables,
WarmP1,WarmP2,WarmP3,
WarmC1,WarmC3,WarmC4,
WarmO1,WarmO2,WarmO3,WarmO4,WarmO5,WarmO6,
Context,
Conf1,Conf2,Conf3,Conf4,
Idea,
Often1,Often2,
SocMedia,
Results]