from otree.api import * import socket from datetime import datetime class C(BaseConstants): NAME_IN_URL = 'survey' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): age = models.IntegerField(label='What is your age?', min=13, max=125) gender = models.StringField( choices=[['Male', 'Male'], ['Female', 'Female']], label='What is your gender?', widget=widgets.RadioSelect, ) crt_bat = models.IntegerField( label=''' A bat and a ball cost 22 dollars in total. The bat costs 20 dollars more than the ball. How many dollars does the ball cost?''' ) crt_widget = models.IntegerField( label=''' If it takes 5 machines 5 minutes to make 5 widgets, how many minutes would it take 100 machines to make 100 widgets? ''' ) crt_lake = models.IntegerField( label=''' In a lake, there is a patch of lily pads. Every day, the patch doubles in size. If it takes 48 days for the patch to cover the entire lake, how many days would it take for the patch to cover half of the lake? ''' ) survey1 = models.IntegerField(label="How happy were you with your breakfast this morning? 1 - not at all, 5 - extremely", choices=[1,2,3,4,5]) survey2 = models.IntegerField(label="How bored are you at the moment? 1 - not at all, 5 - extremely", choices=[1,2,3,4,5]) survey3 = models.IntegerField(label="How much do you enjoy doing experiments? 1 - not at all, 5 - extremely", choices=[1,2,3,4,5]) page1_timestamp = models.IntegerField() page2_timestamp = models.IntegerField() page3_timestamp = models.IntegerField() page4_timestamp = models.IntegerField() page5_timestamp = models.IntegerField() # PAGES class Introduction(Page): @staticmethod def vars_for_template(player: Player): UDP_IP = '127.0.0.1' # UDP_PORT = "127.0.0.1" UDP_PORT = 1011 MESSAGE = b":" + str(player.id_in_group).encode() + b";1;." # print("UDP target IP: %s" % UDP_IP) # print("UDP target port: %s" % UDP_PORT) # print("message: %s" % MESSAGE) sock = socket.socket(socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP sock.sendto(MESSAGE, (UDP_IP, UDP_PORT)) @staticmethod def before_next_page(player: Player, timeout_happened): now = datetime.now() timestamp = int(datetime.timestamp(now)) player.page1_timestamp = timestamp class Demographics(Page): form_model = 'player' form_fields = ['age', 'gender'] @staticmethod def vars_for_template(player: Player): UDP_IP = '10.200.10.3' # UDP_PORT = "127.0.0.1" UDP_PORT = 1011 MESSAGE = b":" + str(player.id_in_group).encode() + b";1;." # print("UDP target IP: %s" % UDP_IP) # print("UDP target port: %s" % UDP_PORT) # print("message: %s" % MESSAGE) sock = socket.socket(socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP sock.sendto(MESSAGE, (UDP_IP, UDP_PORT)) @staticmethod def before_next_page(player: Player, timeout_happened): now = datetime.now() timestamp = int(datetime.timestamp(now)) player.page2_timestamp = timestamp class CognitiveReflectionTest(Page): form_model = 'player' form_fields = ['crt_bat', 'crt_widget', 'crt_lake'] class Survey1(Page): form_model = 'player' form_fields = ['survey1'] @staticmethod def vars_for_template(player: Player): UDP_IP = '127.0.0.1' # UDP_PORT = "127.0.0.1" UDP_PORT = 1011 MESSAGE = b":" + str(player.id_in_group).encode() + b";1;." # print("UDP target IP: %s" % UDP_IP) # print("UDP target port: %s" % UDP_PORT) # print("message: %s" % MESSAGE) sock = socket.socket(socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP sock.sendto(MESSAGE, (UDP_IP, UDP_PORT)) @staticmethod def before_next_page(player: Player, timeout_happened): now = datetime.now() timestamp = int(datetime.timestamp(now)) player.page3_timestamp = timestamp class Survey2(Page): form_model = 'player' form_fields = ['survey2'] @staticmethod def vars_for_template(player: Player): UDP_IP = '127.0.0.1' # UDP_PORT = "127.0.0.1" UDP_PORT = 1011 MESSAGE = b":" + str(player.id_in_group).encode() + b";1;." # print("UDP target IP: %s" % UDP_IP) # print("UDP target port: %s" % UDP_PORT) # print("message: %s" % MESSAGE) sock = socket.socket(socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP sock.sendto(MESSAGE, (UDP_IP, UDP_PORT)) @staticmethod def before_next_page(player: Player, timeout_happened): now = datetime.now() timestamp = int(datetime.timestamp(now)) player.page4_timestamp = timestamp class Survey3(Page): form_model = 'player' form_fields = ['survey3'] @staticmethod def vars_for_template(player: Player): UDP_IP = '127.0.0.1' # UDP_PORT = "127.0.0.1" UDP_PORT = 1011 MESSAGE = b":" + str(player.id_in_group).encode() + b";1;." # print("UDP target IP: %s" % UDP_IP) # print("UDP target port: %s" % UDP_PORT) # print("message: %s" % MESSAGE) sock = socket.socket(socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP sock.sendto(MESSAGE, (UDP_IP, UDP_PORT)) @staticmethod def before_next_page(player: Player, timeout_happened): now = datetime.now() timestamp = int(datetime.timestamp(now)) player.page5_timestamp = timestamp page_sequence = [ Introduction, Demographics, CognitiveReflectionTest, Survey1, Survey2, Survey3 ]