from otree.api import Currency as c, currency_range from ._builtin import Page from .models import Constants import datetime, json, time import random import math import numpy as np # Set of games: a = [ [[82, 48, 34, 35, 36, 41, 64, 53, 13, 67], [55, 34, 43, 24, 11, 26, 27, 22, 19, 12], [59, 33, 12, 14, 47, 42, 41, 37, 28, 48], [94, 72, 75, 21, 12, 25, 28, 48, 82, 11], [71, 33, 57, 36, 44, 12, 39, 52, 27, 55], [55, 44, 19, 34, 41, 33, 11, 24, 32, 16], [93, 64, 24, 38, 52, 67, 66, 62, 55, 45], [62, 35, 9, 46, 31, 11, 18, 45, 44, 39], [59, 16, 47, 42, 44, 18, 41, 46, 36, 45], [65, 53, 43, 29, 13, 18, 47, 42, 41, 49]], [[78, 42, 59, 32, 25, 66, 12, 43, 64, 9], [94, 82, 26, 73, 17, 25, 9, 51, 68, 81], [89, 18, 76, 78, 45, 21, 11, 25, 35, 14], [52, 14, 38, 37, 34, 35, 9, 36, 13, 28], [86, 74, 27, 62, 67, 59, 69, 25, 49, 47], [59, 17, 48, 44, 27, 11, 45, 37, 31, 38], [85, 41, 44, 38, 16, 23, 32, 24, 43, 49], [97, 35, 54, 85, 21, 76, 51, 39, 75, 45], [79, 36, 55, 21, 33, 28, 51, 13, 61, 15], [89, 25, 33, 16, 56, 63, 11, 45, 37, 65]], [[64, 19, 45, 16, 17, 39, 15, 38, 31, 35], [97, 26, 31, 29, 59, 71, 74, 75, 53, 19], [81, 26, 43, 24, 68, 33, 59, 27, 37, 54], [98, 16, 15, 74, 45, 62, 44, 82, 67, 79], [71, 19, 59, 49, 27, 47, 44, 37, 29, 17], [55, 24, 41, 9, 38, 12, 33, 14, 34, 44], [97, 75, 86, 12, 19, 72, 35, 39, 32, 11], [84, 9, 67, 62, 28, 12, 46, 59, 25, 71], [85, 37, 47, 66, 11, 43, 38, 34, 32, 72], [73, 61, 24, 59, 19, 16, 29, 17, 36, 54]], [[94, 19, 67, 79, 23, 52, 18, 75, 68, 63], [56, 44, 15, 14, 18, 39, 29, 11, 32, 27], [98, 37, 41, 9, 23, 22, 16, 76, 69, 39], [74, 31, 41, 36, 32, 26, 57, 13, 61, 23], [64, 27, 25, 22, 52, 15, 36, 13, 17, 39], [55, 29, 36, 14, 44, 43, 39, 23, 26, 21], [58, 9, 41, 42, 12, 43, 47, 23, 21, 16], [78, 43, 51, 25, 36, 29, 31, 63, 61, 53], [52, 14, 33, 15, 11, 24, 17, 9, 19, 16], [95, 71, 26, 51, 56, 16, 53, 74, 49, 21]], [[75, 26, 52, 53, 14, 49, 36, 54, 63, 16], [83, 48, 56, 16, 26, 14, 64, 49, 57, 38], [68, 22, 57, 29, 36, 23, 46, 52, 42, 34], [72, 57, 45, 14, 49, 37, 48, 38, 58, 44], [51, 32, 33, 23, 15, 35, 38, 39, 18, 9], [82, 31, 11, 9, 36, 53, 24, 67, 37, 58], [67, 23, 14, 9, 51, 21, 31, 42, 32, 36], [88, 32, 55, 61, 53, 75, 54, 43, 22, 66], [86, 41, 43, 34, 9, 27, 35, 51, 12, 67], [88, 66, 59, 71, 47, 36, 63, 41, 62, 69]], [[64, 29, 42, 33, 12, 36, 13, 49, 15, 38], [53, 24, 25, 16, 14, 11, 17, 15, 21, 32], [72, 43, 25, 28, 36, 31, 54, 49, 47, 34], [61, 18, 14, 16, 34, 22, 44, 37, 32, 45], [89, 37, 21, 11, 63, 43, 12, 16, 47, 73], [77, 29, 48, 64, 63, 41, 46, 39, 54, 25], [54, 32, 38, 9, 45, 35, 25, 26, 31, 41], [91, 16, 12, 76, 18, 14, 65, 56, 46, 15], [53, 11, 15, 37, 31, 17, 34, 24, 25, 22], [59, 31, 13, 24, 48, 15, 45, 35, 22, 23]], [[72, 36, 39, 14, 49, 55, 21, 31, 58, 56], [81, 54, 23, 32, 69, 47, 27, 48, 65, 28], [62, 49, 19, 15, 37, 34, 39, 43, 17, 14], [72, 33, 58, 46, 39, 36, 25, 19, 43, 45], [74, 48, 23, 21, 35, 52, 59, 22, 36, 49], [76, 37, 55, 11, 22, 52, 62, 24, 48, 23], [54, 42, 11, 13, 19, 18, 15, 21, 9, 45], [68, 51, 27, 32, 17, 9, 34, 19, 13, 46], [64, 17, 49, 39, 42, 33, 29, 19, 18, 31], [79, 56, 57, 11, 42, 22, 51, 47, 35, 12]], [[94, 27, 52, 69, 78, 68, 22, 57, 55, 39], [86, 12, 38, 27, 24, 28, 51, 25, 58, 54], [89, 55, 12, 23, 14, 72, 48, 66, 33, 68], [62, 23, 29, 15, 38, 14, 36, 24, 17, 28], [84, 17, 55, 68, 43, 39, 59, 46, 25, 37], [58, 42, 39, 25, 13, 34, 14, 16, 36, 41], [54, 36, 19, 15, 11, 39, 28, 38, 23, 27], [98, 87, 9, 86, 82, 21, 89, 15, 17, 43], [61, 28, 19, 38, 46, 15, 34, 24, 9, 44], [97, 44, 12, 32, 53, 66, 41, 15, 79, 71]], [[78, 46, 13, 67, 65, 25, 34, 15, 47, 62], [68, 15, 42, 29, 27, 41, 19, 23, 36, 33], [76, 51, 48, 11, 47, 15, 65, 39, 35, 63], [91, 75, 69, 44, 64, 16, 35, 62, 33, 49], [68, 16, 17, 49, 14, 22, 41, 57, 19, 21], [91, 69, 25, 17, 55, 26, 13, 75, 22, 72], [55, 21, 17, 33, 26, 9, 41, 27, 34, 23], [93, 65, 58, 32, 79, 77, 31, 71, 76, 17], [84, 41, 72, 46, 26, 48, 35, 32, 49, 28], [85, 23, 54, 72, 42, 62, 49, 58, 38, 69]], [[61, 49, 34, 35, 19, 24, 28, 46, 36, 26], [58, 24, 36, 37, 43, 26, 44, 11, 19, 14], [82, 16, 29, 43, 57, 39, 31, 35, 56, 13], [74, 23, 47, 43, 48, 56, 28, 57, 49, 25], [51, 26, 24, 35, 14, 34, 23, 39, 22, 17], [74, 62, 16, 37, 9, 23, 51, 59, 52, 17], [62, 13, 23, 17, 31, 33, 15, 48, 49, 46], [87, 13, 32, 18, 25, 34, 73, 65, 74, 29], [86, 34, 12, 15, 13, 61, 53, 52, 75, 57], [79, 35, 52, 45, 12, 64, 17, 38, 44, 11]] ] def timeout_options(): choice1 = [60, 45, 30, 20, 15, 60, 45, 30, 20, 15] random.shuffle(choice1) return choice1 class Overall(Page): form_model = 'player' def is_displayed(self): return self.round_number == 1 class Instructions(Page): form_model = 'player' form_fields = ['my_page_timeout_seconds'] timeout_seconds = 3 def vars_for_template(self): if self.round_number == 1: self.participant.vars['timeout_options'] = timeout_options() for i in range(0, 11): if self.round_number == i: self.participant.vars['roundnumber'] = i self.player.my_page_timeout_seconds = self.participant.vars['timeout_options'][i - 1] return dict( roundnumber=self.participant.vars['roundnumber'], my_page_timeout_seconds=self.participant.vars['timeout_options'][i-1], ) def before_next_page(self): self.participant.vars['sssss'] = time.time() def js_vars(self): for i in range(0, 11): if self.round_number == i: return { 'my_page_timeout_seconds': self.participant.vars['timeout_options'][i-1], } class Game1(Page): form_model = 'player' form_fields = ['correct'] timeout_seconds = 300 def vars_for_template(self): if self.round_number == 1: self.participant.vars['set'] = a[1] if self.round_number == 1: return dict( roundnumber=self.participant.vars['roundnumber'], n=[self.participant.vars['set'][0][h] for h in range(0, 10)], payoff_unknown=10, my_page_timeout_seconds = self.participant.vars['timeout_options'][0], ) for i in range(2, 11): if self.round_number == i: return dict( roundnumber=self.participant.vars['roundnumber'], n=[self.participant.vars['set'][i-1][h] for h in range(0, 10)], payoff_unknown=self.player.in_round(i - 1).payoff_unknown, my_page_timeout_seconds = self.participant.vars['timeout_options'][i-1], ) def before_next_page(self): if self.round_number == 1: self.player.payoff_unknown = 10 for i in range(2, 11): if self.round_number == i: self.player.payoff_unknown = self.player.in_round(self.round_number - 1).payoff_unknown if self.player.correct == 1: self.player.time_spent = math.floor(time.time() - self.participant.vars['sssss']) if self.player.time_spent <= self.player.my_page_timeout_seconds: self.player.payoff_unknown = self.player.payoff_unknown else: self.player.payoff_unknown = self.player.payoff_unknown - 1 if self.player.correct == 0: self.player.time_spent = math.floor(time.time() - self.participant.vars['sssss']) self.player.payoff_unknown = self.player.payoff_unknown - 1 if self.timeout_happened: self.player.time_spent = self.player.my_page_timeout_seconds self.participant.vars['payoff_unknown'] = self.player.payoff_unknown self.participant.vars['time_spent'] = self.player.time_spent def js_vars(self): for i in range(0, 11): if self.round_number == i: return { 'n': [self.participant.vars['set'][i - 1][h] for h in range(0, 10)], 'my_page_timeout_seconds': self.participant.vars['timeout_options'][i-1], } class results(Page): form_model = 'player' form_fields = ['payoff_unknown', 'time_spent'] timeout_seconds = 3 def vars_for_template(self): self.participant.vars['correct'] = self.player.correct self.participant.vars['payoff_unknown'] = self.player.payoff_unknown self.participant.vars['time_spent'] = self.player.time_spent return dict( correct=self.participant.vars['correct'], payoff_unknown=self.participant.vars['payoff_unknown'], time_spent=self.participant.vars['time_spent'], my_page_timeout_seconds=self.participant.vars['timeout_options'], ) def js_vars(self): return { 'payoff_unknown': self.participant.vars['payoff_unknown'], 'time_spent': self.participant.vars['time_spent'], } class survey(Page): form_model = 'player' form_fields = ['survey'] def is_displayed(self): return self.round_number == 10 page_sequence = [ Overall, Instructions, Game1, results, survey ]