from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random import json import pandas as pd author = 'Kevin Trutmann' doc = """ The beauty contest game, where the player that submits the number closest to 2/3 of the mean of all answers wins. """ class Constants(BaseConstants): name_in_url = 'guessing_game_online' players_per_group = None bc_group_size = 100 # How many players will play in the beauty contest group? Should match the MTurk_results one! POINTS_PER_WIN = c(8500) # Should match the MTurk_results one! RANDOMIZE_QUESTIONS = True # Should the page sequence be randomized num_rounds = 1 # Not tested with more than one round class Subsession(BaseSubsession): # # Implementing a randomization method by Philipp Chapkovski # def creating_session(self): # from .pages import initial_page_sequence # pages = [i.__name__ for i in initial_page_sequence] # for p in self.get_players(): # pb = pages.copy() # if Constants.RANDOMIZE_QUESTIONS: # random.shuffle(pb) # p.page_sequence = json.dumps(pb) pass class Group(BaseGroup): pass class Player(BasePlayer): page_sequence = models.StringField() computer_submission = models.IntegerField(label='Your Number:', min=0, max=100) dyad_submission = models.IntegerField(label='Your Number:', min=0, max=100) group_submission = models.IntegerField(label='Your Number:', min=0, max=100) computer_23mean = models.FloatField() dyad_23mean = models.FloatField() group_23mean = models.FloatField() computer_human_submitted = models.IntegerField(default=0) dyad_human_submitted = models.IntegerField(default=0) group_human_submitted = models.IntegerField(default=0) def register_submissions(self): self.participant.vars['computer_submission'] = self.computer_submission self.participant.vars['dyad_submission'] = self.dyad_submission self.participant.vars['group_submission'] = self.group_submission