import random
import pandas as pd
import numpy as np
import os
from otree.api import (
models,
widgets,
BaseConstants,
BaseSubsession,
BaseGroup,
BasePlayer,
Currency as c,
currency_range,
)
from .machine_learning_algo import prediction_human_expert, prediction_ml
doc = """
"""
############################################################
# definition of constant variables
############################################################
class Constants(BaseConstants):
# STANDARD VARIABLES
name_in_url = 'behavioral_study'
players_per_group = None
num_rounds = 15
df_ = pd.read_csv('/Users/kev/Desktop/oTree_/Mirror_mirror_exps/sythetic_data.csv', sep=',').sample(n=15)
#df_ = pd.read_csv('Mirror_mirror_exps/sythetic_data.csv', sep=';').sample(n=15).values
competitiveness_score = 'Auf einer Skala von 1 (trifft überhaupt nicht zu) bis 7 (trifft vollkommen zu):
Diese Person ist ein kompetitiver Mensch.'
openness_score = 'Auf einer Skala von 1 (trifft überhaupt nicht zu) bis 7 (trifft vollkommen zu):
Diese Person ist offen für neue Erfahrungen.'
conscentiousness_score = 'Auf einer Skala von 1 (trifft überhaupt nicht zu) bis 7 (trifft vollkommen zu):
Diese Person ist ein gewissenhafter Mensch.'
agreeableness_score = 'Auf einer Skala von 1 (trifft überhaupt nicht zu) bis 7 (trifft vollkommen zu):
Diese Person ist ein verträglicher Mensch.'
neuroticism_score = 'Auf einer Skala von 1 (trifft überhaupt nicht zu) bis 7 (trifft vollkommen zu):
Diese Person ist ein emotional labiler Mensch.'
extraversion_score = 'Auf einer Skala von 1 (trifft überhaupt nicht zu) bis 7 (trifft vollkommen zu):
Diese Person ist ein kontaktfreudiger/ geselliger Mensch.'
gender = 'Das biologische Geschlecht dieser Person'
risk_ = 'Auf einer Skala von 0 (extrem risiko avers) bis 10 (extrem risiko freudig):
Diese Person hat die folgende Risikoneigung.'
impat_ = 'Auf einer Skala von 0 (extrem ungeduldig) bis 10 (extrem geduldig):
Diese Person schätzt ihre Geduld wie folgt ein.'
age_ = 'Diese Person wurde im folgenden Zeitraum geboren.'
sob_ = 'Diese Person wurde im folgenden Bundesland geboren.'
lang_ = 'In dem Elternhaus dieser Person wird folgende Sprache gesprochen.'
choicesLikert = [[1, '1 (trifft überhaupt nicht zu)'],
[2, '2'],
[3, '3'],
[4, '4'],
[5, '5'],
[6, '6'],
[7, '7 (trifft vollkommen zu)']]
choicesGender = [[1, 'Weiblich'],
[2, 'Männlich']]
siblings = [[1, 'Keine Geschwister'],
[2, 'Jüngere Geschwister'],
[3, 'Ältere Geschwister'],
[4, 'Jüngere und ältere Geschwister']]
risk_score = [[0, '0 (Extrem risko-avers)'],
[1, '1'],
[2, '2'],
[3, '3'],
[4, '4'],
[5, '5 (Risko neutral)'],
[6, '6'],
[7, '7'],
[8, '8'],
[9, '9'],
[10, '10 (Extrem risko-freudig)']]
impatience = [[0, '0 (Äußerst ungeduldig)'],
[1, '1'],
[2, '2'],
[3, '3'],
[4, '4'],
[5, '5'],
[6, '6'],
[7, '7'],
[8, '8'],
[9, '9'],
[10, '10 (Äußerst geduldig)']]
parents_uni = [[1, 'Keiner der beiden'],
[2, 'Nur der Vater'],
[3, 'Nur die Mutter'],
[4, 'Beide']]
age = [[1, 'vor 1985'],
[2, '1985-1989'],
[3, '1990-1994'],
[4, '1995-1999'],
[5, '2000 oder später']]
# STATE OF BIRTH
state_birth = [[0, 'Baden-Wuerttemberg'],
[1, 'Bayern'],
[2, 'Hessen'],
[3, 'Nordrhein-Westfalen'],
[4, 'Rheinland-Pfalz'],
[5, 'Andere']]
# MATH LK
lk_ = [[0, 'Englisch'],
[1, 'Mathe'],
[2, 'Beide'],
[3, 'Keines der beiden']]
# PART HOME GERMAN
home_language = [[0, 'Deutsch'],
[1, 'Eine andere Sprache'],
[2, 'Deutsch und eine andere Sprache']]
############################################################
# RANDOM ASSIGNMENT OF TREATMENTS
# 1 = NO INFO
# 2 = MACHINE PRIVATE
# 3 = MACHINE PUBLIC
# 4 = HUMAN PRIVATE
# 5 = HUMAN PUBLIC
############################################################
class Subsession(BaseSubsession):
pass
############################################################
# GROUP LEVEL VARIABLES AND METHODS
############################################################
class Group(BaseGroup):
pass
############################################################
# SUBJECT LEVEL VARIABLES AND METHODS
############################################################
class Player(BasePlayer):
# VALUES IN CURRENT ROUND
ordering_ = models.LongStringField(initial=None)
trust_ = models.IntegerField(
choices=[[0, '...NICHT reziprok verhalten würde.'],
[1, '...reziprok verhalten würde.']],
widget=widgets.RadioSelect,
label='Bitte triff eine Entscheidung.
Ich erwarte, dass sich dieser second mover...'
)
female = models.IntegerField(label='Bitte nenne uns dein Geschlecht:',
choices=[
[0, 'Weiblich'],
[1, 'Männlich'],
[2, 'Nicht-binär']],
widget=widgets.RadioSelect)
academic = models.IntegerField(label='Bitte nenne uns deine Position:',
choices=[
[2, 'Professor'],
[1, 'Post-Doc'],
[0, 'Doktorand']],
widget=widgets.RadioSelect)
age = models.IntegerField(label='Wie alt bist du?',min=0,max=100,blank=True)
def setting_(self):
# BUILDING RANDOMIZATION
self.participant.vars['cases'] = []
for i in range(Constants.num_rounds):
# temp_ = [
# Constants.df_['Competitiveness_Score'].iloc[i],
# Constants.df_['Openness'].iloc[i],
# Constants.df_['Conscentiousness'].iloc[i],
# Constants.df_['Agreeableness'].iloc[i],
# Constants.df_['Neuroticism'].iloc[i],
# Constants.df_['Extraversion'].iloc[i],
# Constants.df_['gender'].iloc[i],
# Constants.df_['risksq001'].iloc[i],
# Constants.df_['impatiencesq001'].iloc[i]
# ]
#
# if np.array_equal(Constants.df_[['age_before_85', 'age_85_89', 'age_90_94', 'age_95_99', 'age_00_later']].iloc[i].values, np.array([1,0,0,0,0])):
# temp_.append(0)
# elif np.array_equal(Constants.df_[['age_before_85', 'age_85_89', 'age_90_94', 'age_95_99', 'age_00_later']].iloc[i].values, np.array([0,1,0,0,0])):
# temp_.append(1)
# elif np.array_equal(Constants.df_[['age_before_85', 'age_85_89', 'age_90_94', 'age_95_99', 'age_00_later']].iloc[i].values, np.array([0,0,1,0,0])):
# temp_.append(2)
# elif np.array_equal(Constants.df_[['age_before_85', 'age_85_89', 'age_90_94', 'age_95_99', 'age_00_later']].iloc[i].values, np.array([0,0,0,1,0])):
# temp_.append(3)
# else:
# temp_.append(4)
#
#
# if np.array_equal(Constants.df_[['birthplace_Baden-Wuerttemberg', 'birthplace_Bayern','birthplace_Hessen',
# 'birthplace_Nordrhein-Westfalen','birthplace_Rheinland-Pfalz',
# 'birthplace_other',]].iloc[i].values, np.array([1,0,0,0,0,0])):
# temp_.append(0)
# elif np.array_equal(Constants.df_[['birthplace_Baden-Wuerttemberg', 'birthplace_Bayern','birthplace_Hessen',
# 'birthplace_Nordrhein-Westfalen','birthplace_Rheinland-Pfalz',
# 'birthplace_other',]].iloc[i].values, np.array([0,1,0,0,0,0])):
# temp_.append(1)
# elif np.array_equal(Constants.df_[['birthplace_Baden-Wuerttemberg', 'birthplace_Bayern','birthplace_Hessen',
# 'birthplace_Nordrhein-Westfalen','birthplace_Rheinland-Pfalz',
# 'birthplace_other',]].iloc[i].values, np.array([0,0,1,0,0,0])):
# temp_.append(2)
# elif np.array_equal(Constants.df_[['birthplace_Baden-Wuerttemberg', 'birthplace_Bayern','birthplace_Hessen',
# 'birthplace_Nordrhein-Westfalen','birthplace_Rheinland-Pfalz',
# 'birthplace_other',]].iloc[i].values, np.array([0,0,0,1,0,0])):
# temp_.append(3)
# elif np.array_equal(Constants.df_[['birthplace_Baden-Wuerttemberg', 'birthplace_Bayern','birthplace_Hessen',
# 'birthplace_Nordrhein-Westfalen','birthplace_Rheinland-Pfalz',
# 'birthplace_other',]].iloc[i].values, np.array([0,0,0,0,1,0])):
# temp_.append(4)
# else:
# temp_.append(5)
#
#
# if np.array_equal(Constants.df_[['parental_home_german', 'parental_home_foreign_language']].iloc[i].values, np.array([1,0])):
# temp_.append(0)
# elif np.array_equal(Constants.df_[['parental_home_german', 'parental_home_foreign_language']].iloc[i].values, np.array([0,1])):
# temp_.append(1)
# else:
# temp_.append(2)
temp_ = [random.randint(1,7), # comp
random.randint(1, 7), # open
random.randint(1, 7), # consc
random.randint(1, 7), # agree
random.randint(1, 7), # neuro
random.randint(1, 7), # extra
random.randint(0, 1), # gender
random.randint(0, 10), # risk
random.randint(0, 10), # impatience
random.randint(0, 4), # age
random.randint(0, 5), # state of b
random.randint(0, 2), # language
]
#print(temp_)
self.participant.vars['cases'].append(temp_)
def fill_in_values(self):
# CURRENT VALUES THAT WILL BE SEEN
self.ordering_ = str(self.participant.vars['cases'][self.round_number - 1])
#str(Constants.df_.index.to_list())