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 = [ [[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]] ] def timeout_options(): #timeee = [15, 15, 15, 15, 15, 15, 15, 15, 15, 15] #timeee = [25, 25, 25, 25, 25, 25, 25, 25, 25, 25] #timeee = [60, 60, 60, 60, 60, 60, 60, 60, 60, 60] timeee = [300, 300, 300, 300, 300, 300, 300, 300, 300, 300] return timeee class Instructions(Page): form_model = 'player' form_fields = ['my_page_timeout_seconds'] timeout_seconds = 5 def vars_for_template(self): if self.round_number == 1: self.participant.vars['timeout_options'] = timeout_options() for i in range(1, 11): if self.round_number % 10 == i: self.participant.vars['game_number'] = i if self.round_number % 10 == 0: self.participant.vars['game_number'] = 10 for i in range(1, 11): if self.round_number == i: return dict( timeout_options=self.participant.vars['timeout_options'][i - 1], game_number=self.participant.vars['game_number'], ) def before_next_page(self): self.participant.vars['sssss'] = time.time() def js_vars(self): for i in range(1, 11): if self.round_number == i: return { 'timeout_options': self.participant.vars['timeout_options'][i - 1], } class Game1(Page): form_model = 'player' form_fields = ['correct'] def get_timeout_seconds(self): return self.player.my_page_timeout_seconds def vars_for_template(self): if self.round_number == 1: self.participant.vars['set1'] = a[0] if self.round_number == 1: self.player.my_page_timeout_seconds = self.participant.vars['timeout_options'][0] return dict( game_number=self.participant.vars['game_number'], n=[self.participant.vars['set1'][0][h] for h in range(0, 10)], payoff1=2, my_page_timeout_seconds=self.participant.vars['timeout_options'][0], ) for i in range(2, 11): if self.round_number == i: self.player.my_page_timeout_seconds = self.participant.vars['timeout_options'][i - 1] return dict( game_number=self.participant.vars['game_number'], n=[self.participant.vars['set1'][i - 1][h] for h in range(0, 10)], payoff1=self.player.in_round(i - 1).payoff1, my_page_timeout_seconds=self.participant.vars['timeout_options'][i - 1], ) def before_next_page(self): self.player.time_spent = math.floor(time.time() - self.participant.vars['sssss']) if self.round_number < 11: if self.round_number == 1: self.player.payoff1 = 2 else: self.player.payoff1 = self.player.in_round(self.round_number - 1).payoff1 if self.player.correct == 1: self.player.payoff1 = self.player.payoff1 else: self.player.payoff1 = self.player.payoff1 - 0.2 self.participant.vars['payoff_round1'] = self.player.payoff1 self.participant.vars['payoff1'] = self.player.payoff1 self.participant.vars['time_spent'] = self.player.time_spent def js_vars(self): for i in range(1, 11): if self.round_number == i: return { 'n': [self.participant.vars['set1'][i - 1][h] for h in range(0, 10)], 'timeout_options': self.participant.vars['timeout_options'][i - 1], } class results(Page): form_model = 'player' form_fields = ['payoff1', 'time_spent'] timeout_seconds = 5 def vars_for_template(self): self.participant.vars['results'] = self.player.correct self.participant.vars['payoff1'] = self.player.payoff1 self.participant.vars['time_spent'] = self.player.time_spent for i in range(1, 11): if self.round_number == i: return dict( my_page_timeout_seconds=self.participant.vars['timeout_options'][i - 1], game_number=self.participant.vars['game_number'], result=self.participant.vars['results'], payoff1=self.participant.vars['payoff1'], time_spent=self.participant.vars['time_spent'], ) def js_vars(self): for i in range(1, 11): if self.round_number == i: return { 'payoff1': self.participant.vars['payoff1'], 'time_spent': self.participant.vars['time_spent'], 'my_page_timeout_seconds': self.participant.vars['timeout_options'][i - 1], } class End_of_Round(Page): form_model = 'player' def is_displayed(self): return self.round_number % 10 == 0 def vars_for_template(self): self.participant.vars['payoff1'] = self.player.payoff1 return dict( payoff1 = self.participant.vars['payoff1'] ) def js_vars(self): for i in range(1, 11): if self.round_number == i: return { 'payoff1': self.participant.vars['payoff1'], } page_sequence = [ Instructions, Game1, results, End_of_Round, ]