from otree.api import * import pandas as pd from .utilities import * import random from io import StringIO from .src.Functions import * from .src.IntroductionPage import * from .src.WaitPages import * from .src.DiscussionPage1 import * from .src.LeaderPage import * from .src.AgentPage import * from .src.IndividualAnswerPage import * from .src.DiscussionPage2 import * from .src.InfluenceMatrixPage import * doc = """ This is a jeopardy trivia game. Players are placed into teams of four and are asked a series of intellective questions with regularly dispersed surveys on confidence and influence. """ class Subsession(BaseSubsession): pass class Player(BasePlayer): is_leader = models.BooleanField(initial=False) page_pass_time = models.IntegerField() nickname = models.StringField(initial='') color = models.StringField(initial='') button_pressed = models.StringField(initial='') correct_answer_selected = models.BooleanField() individual_answer = models.IntegerField( widget=widgets.RadioSelect ) player1_appraisal = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal ) player2_appraisal = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal ) player3_appraisal = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal ) player4_appraisal = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal ) group_answer = models.IntegerField( widget=widgets.RadioSelect ) group_confidence = models.IntegerField( label='How confident are you about your answer?', choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal ) player1_influence = models.IntegerField( widget=widgets.RadioSelect, choices=[1, 2, 3, 4, 5, 6, 7] ) player2_influence = models.IntegerField( widget=widgets.RadioSelect, choices=[1, 2, 3, 4, 5, 6, 7] ) player3_influence = models.IntegerField( widget=widgets.RadioSelect, choices=[1, 2, 3, 4, 5, 6, 7] ) player4_influence = models.IntegerField( widget=widgets.RadioSelect, choices=[1, 2, 3, 4, 5, 6, 7] ) ai_influence = models.IntegerField( widget=widgets.RadioSelect, choices=[1, 2, 3, 4, 5, 6, 7] ) def select_question(player, df_str): questions = json.loads(df_str) if len(questions) == 0: return None random_index = random.randint(0, len(questions) - 1) player.group.selected_question = json.dumps(questions[random_index]) questions.pop(random_index) return questions class Group(BaseGroup): # points = models.CurrencyField(initial=0) # Rasta: What is this for? leader_button_pressed = models.StringField() category_choice = models.StringField() difficulty_choice = models.StringField() selected_question = models.LongStringField() ai_answer = models.StringField() ai_confidence = models.StringField() score = models.IntegerField(initial=0) num_correct = models.IntegerField(initial=0) num_incorrect = models.IntegerField(initial=0) currentDiscussion1_channel = models.StringField() currentDiscussion2_channel = models.StringField() def get_selected_question(group): return json.loads(group.selected_question) def get_ai_answer(group, difficulty): p, mean, std = get_ai_accuarcy_confidence(difficulty) confidence = random.normalvariate(mean, std) confidence = confidence if confidence < 1 else 0.992 selected_question = group.get_selected_question() correct_answer = selected_question['Answer'] wrong_answers = [selected_question['A'], selected_question['B'], selected_question['C'], selected_question['D']] wrong_answers.remove(correct_answer) if random.random() < p: return correct_answer, "{:.1f}".format(confidence * 100) else: return random.choice(wrong_answers), "{:.1f}".format(confidence * 100) page_sequence = [ Introduction, EmptyWaitPage, DiscussionPage1, ResultsWaitPage, IndividualAnswer, IndividualAnswerWaitPage, DiscussionPage2, GroupAnswerWaitPage, InfluenceMatrix, ]