from otree.api import * import time import random import math from decimal import Decimal import psycopg2 class C(BaseConstants): NAME_IN_URL = 'project_work' PLAYERS_PER_GROUP = 3 NUM_ROUNDS = 1 class Group(BaseGroup): pass class Subsession(BaseSubsession): pass class Player(BasePlayer): session_active = models.IntegerField(initial=0) worker_id = models.CharField(initial='e') mturk_dupe = models.IntegerField(initial=0) participant_number = models.IntegerField(default=0) total_compensation = models.StringField(default='Not Finished') group_number = models.IntegerField() # For no/low/high coworker effort info conditions when I have groups of 18 condition = models.IntegerField() condition_label = models.StringField() informed_consent = models.StringField(initial=None, choices=[('Yes', 'Yes'), ('No', 'No')], verbose_name='', widget=widgets.RadioSelect()) kc1 = models.StringField(initial=None, choices=['True', 'False'], verbose_name='', widget=widgets.RadioSelect()) kc2 = models.StringField(initial=None, choices=['True', 'False'], verbose_name='', widget=widgets.RadioSelect()) kc3 = models.StringField(initial=None, choices=['True', 'False'], verbose_name='', widget=widgets.RadioSelect()) s1_contribution = models.FloatField(verbose_name='') s1_decision_time = models.StringField() s1_pay = models.FloatField() s1_coworker_1_contribution = models.FloatField() s1_coworker_2_contribution = models.FloatField() s1_team_contribution = models.FloatField() #FUNCTIONS def creating_session(subsession): session = subsession.session for player in subsession.get_players(): player.condition = session.config['condition'] player.participant.label = 'e' # PAGES class IC(Page): form_model = 'player' form_fields = ['informed_consent'] #def before_next_page(player, timeout_happened): # See if that worker ID already appears in players, in which case they at least started the experiment #if player.participant.label != 'e': # worker_match = [w for w in OnlineWorkers.filter() if (w.worker_id == player.participant.label)] # if not worker_match: # OnlineWorkers.create(worker_id=player.participant.label) # player.worker_id = player.participant.label # else: # player.mturk_dupe = 1 class IC_Decline(Page): @staticmethod def is_displayed(player: Player): return player.informed_consent == "No" class DuplicateWorker(Page): @staticmethod def is_displayed(player: Player): return player.mturk_dupe == 1 class GenInstructions(Page): @staticmethod def before_next_page(player, timeout_happened): conn = psycopg2.connect(database="d843cclkr6ovgn", user="uigdr2bmq9irl", password="pc314696db376127251d8f370b2d74d5c429ca12e964769f21ac05c08fc6b7ef6", host="cf9gid2f6uallg.cluster-czrs8kj4isg7.us-east-1.rds.amazonaws.com", port=5432) #conn = sqlite3.connect("db.sqlite3") str_id = str(player.participant_id) cursor = conn.cursor() if player.condition == 1: # Separate table/app for the no info/low c.e./high c.e. conditions cursor.execute( 'update knowledge_of_effort_employee_s2_lh_player set active_flag=1 where participant_id=' + str_id) # In case some people get ahead a bit and to help with stage 2 checks conn.commit() else: cursor.execute( 'update knowledge_of_effort_employee_s2_player set active_flag=1 where participant_id=' + str_id) # In case some people get ahead a bit and to help with stage 2 checks conn.commit() cursor.close() conn.commit() conn.close() class TaskInstructions1(Page): form_model = 'player' form_fields = ['kc1', 'kc2', 'kc3'] class TaskInstructions2(Page): pass class KnowledgeCheck1(Page): form_model = 'player' form_fields = ['kc1', 'kc2', 'kc3'] class Decision1(Page): form_model = 'player' form_fields = ['s1_contribution', 's1_decision_time'] def before_next_page(player, timeout_happened): player.s1_pay = 2.00 - player.s1_contribution player.participant_number = player.id player.participant.s1_contribution = player.s1_contribution player.participant.s1_decision_time = player.s1_decision_time player.participant.s1_pay = player.s1_pay player.participant.participant_number = player.participant_number # player.participant.manager_id = player.manager_id class PostTask1(Page): @staticmethod def vars_for_template(player): return dict(s1_contribution='{0:.2f}'.format(player.s1_contribution), s1_pay='{0:.2f}'.format(player.s1_pay)) def before_next_page(player, timeout_happened): player.participant_number = player.id player.participant.s1_contribution = player.s1_contribution player.participant.s1_decision_time = player.s1_decision_time player.participant.s1_pay = player.s1_pay player.participant.participant_number = player.participant_number # player.participant.manager_id = player.manager_id page_sequence = \ [ IC, IC_Decline, DuplicateWorker, GenInstructions, TaskInstructions1, Decision1 ]