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 class instructions1(Page): form_model = 'player' form_fields = ['pressure_first'] def before_next_page(self): self.participant.vars['sssss'] = time.time() def vars_for_template(self): self.participant.vars['pressure_first'] = self.player.pressure_first return dict( pressure_first=self.participant.vars['pressure_first'], ) def js_vars(self): return { 'pressure_first': self.participant.vars['pressure_first'], } class Game1(Page): form_model = 'player' form_fields = ['puzzle_solved', 'time_spent', 'num_of_moves', 'min_num_of_moves', 'board_history', 'time_between_moves'] timeout_seconds = 300 def before_next_page(self): if self.player.puzzle_solved == 1: self.player.time_spent = math.floor(time.time() - self.participant.vars['sssss']) if self.timeout_happened: self.player.time_spent = self.timeout_seconds return dict( min_num_of_moves=8, ) def js_vars(self): if self.round_number == 1: # 8 steps return { 'timeout': self.timeout_seconds, 'game_id': self.round_number, 'min_num_of_moves': 8, 'player_id': self.player.id, 'board': [ [2, 5, 3], [1, 7, 6], [None, 4, 8], ] } if self.round_number == 2: # 6 steps return { 'timeout': self.timeout_seconds, 'game_id': self.round_number, 'min_num_of_moves': 8, 'player_id': self.player.id, 'board': [ [1, 3, 6], [4, 2, 8], [None, 7, 5], ] } def paying_round(self): choice3 = random.randint(1, 9) return choice3 def baseline(self): choice4 = random.randint(1, 7) return choice4 class Results(Page): form_model = 'player' form_fields = ['paying_round', 'baseline'] def vars_for_template(self): if self.round_number == 1: self.participant.vars['paying_round'] = paying_round(self) self.participant.vars['baseline'] = baseline(self) return dict( paying_round=self.participant.vars['paying_round'], baseline=self.participant.vars['baseline'], ) def js_vars(self): return { 'paying_round': self.participant.vars['paying_round'], 'baseline': self.participant.vars['baseline'], } class details(Page): pass page_sequence = [instructions1, Game1, Results, ]