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 a =[ [["2 2 2", "1 1", "1 3 3", "1 2 2 1", "2 1 2 1", "2 1 1", "1 2 1", "1 1 1 3", "2 5", "2 4 1"], ["3 3", "1 2 2", "1 1 1 1", "4 1 1", "1 1 1 1 1", "1 3 2", "1 2 1 2", "1 1 3", "1 2 1 2", "1 1 4"]], # test this on Prolific # [["2 1 2","2 5","3 1 1","2","1 4 1","3 3 1","1 5 2","1 1 1","5 2","1 2 1"], # ["3 2 1","3 1 2","1 3 1","1 1 1","3 3 2","1 6","2 3","5 2","1 3","3"]], #test this on Prolific # # [["1 1 1 1","2 1 2","2 2","2 4 1","1 2 1","2 3 1","2 7","1 1 2","2 2","2 3"], # ["1 1 2","3 2 2","6 3","1 1","1 2","1 2 1","1 1 2 1","1 1 4","2 3","7"]], #test this on Prolific ] a_sol = [ [[0, 1, 1, 0, 1, 1, 0, 1, 1, 0], [0, 0, 0, 1, 0, 0, 1, 0, 0, 0], [1, 0, 0, 1, 1, 1, 0, 1, 1, 1], [1, 0, 1, 1, 0, 1, 1, 0, 1, 0], [1, 1, 0, 1, 0, 1, 1, 0, 0, 1], [0, 1, 1, 0, 1, 0, 0, 0, 1, 0], [0, 0, 0, 1, 0, 0, 1, 1, 0, 1], [1, 0, 1, 0, 1, 0, 0, 1, 1, 1], [1, 1, 0, 0, 0, 1, 1, 1, 1, 1], [1, 1, 0, 1, 1, 1, 1, 0, 0, 1]], # [[1, 1, 0, 0, 1, 0, 1, 1, 0, 0], # [1, 1, 0, 1, 1, 1, 1, 1, 0, 0], # [1, 1, 1, 0, 1, 0, 0, 1, 0, 0], # [0, 0, 0, 0, 0, 0, 0, 1, 1, 0], # [0, 0, 1, 0, 1, 1, 1, 1, 0, 1], # [1, 1, 1, 0, 1, 1, 1, 0, 0, 1], # [1, 0, 1, 1, 1, 1, 1, 0, 1, 1], # [0, 1, 0, 0, 0, 1, 0, 0, 1, 0], # [0, 1, 1, 1, 1, 1, 0, 1, 1, 0], # [1, 0, 0, 0, 1, 1, 0, 1, 0, 0], ], # # [[1, 0, 1, 0, 0, 0, 0, 1, 0, 1], # [0, 1, 1, 0, 0, 0, 1, 0, 1, 1], # [0, 1, 1, 0, 0, 0, 0, 0, 1, 1], # [0, 1, 1, 0, 1, 1, 1, 1, 0, 1], # [1, 0, 1, 1, 0, 0, 0, 0, 0, 1], # [0, 1, 1, 0, 1, 1, 1, 0, 0, 1], # [1, 1, 0, 1, 1, 1, 1, 1, 1, 1], # [1, 0, 1, 0, 0, 0, 0, 1, 1, 0], # [0, 1, 1, 0, 0, 0, 0, 1, 1, 0], # [0, 1, 1, 0, 0, 1, 1, 1, 0, 0], ] ] green = [56, 54, 52] gray = [44, 46, 48] class Instructions(Page): form_model = 'player' timeout_seconds = 2 # def vars_for_template(player): # for i in range(1, 4): # if player.round_number == i: # player.participant.vars['game_number'] = i # # return dict( # game_number=player.participant.vars['game_number'], # #game_order=player.participant.vars['game_order'], # ) def before_next_page(self): self.participant.vars['sssss'] = time.time() class Game1(Page): form_model = 'player' timeout_seconds = 600 form_fields = ['points', 'total_wrong', 'total_right', 'wrong_green', 'wrong_gray', 'right_green', 'right_gray', 'time_between_moves', 'board_history', 'solve_order', 'total_green', 'total_gray'] def vars_for_template(player): for i in range(1, 4): if player.round_number == i: game = 0 #game = player.participant.vars['game_order'][i-1] - 1 player.participant.vars['row'] = a[game][0] player.participant.vars['column'] = a[game][1] player.participant.vars['solution_0'] = a_sol[game][0] player.participant.vars['solution_1'] = a_sol[game][1] player.participant.vars['solution_2'] = a_sol[game][2] player.participant.vars['solution_3'] = a_sol[game][3] player.participant.vars['solution_4'] = a_sol[game][4] player.participant.vars['solution_5'] = a_sol[game][5] player.participant.vars['solution_6'] = a_sol[game][6] player.participant.vars['solution_7'] = a_sol[game][7] player.participant.vars['solution_8'] = a_sol[game][8] player.participant.vars['solution_9'] = a_sol[game][9] player.participant.vars['total_green'] = green[game] player.participant.vars['total_gray'] = gray[game] return dict( #game_order=player.participant.vars['game_order'], #game_number=player.participant.vars['game_number'], r=[player.participant.vars['row'][h] for h in range(0, 10)], c=[player.participant.vars['column'][h] for h in range(0, 10)], sol_0=[player.participant.vars['solution_0'][h] for h in range(0, 10)], sol_1=[player.participant.vars['solution_1'][h] for h in range(0, 10)], sol_2=[player.participant.vars['solution_2'][h] for h in range(0, 10)], sol_3=[player.participant.vars['solution_3'][h] for h in range(0, 10)], sol_4=[player.participant.vars['solution_4'][h] for h in range(0, 10)], sol_5=[player.participant.vars['solution_5'][h] for h in range(0, 10)], sol_6=[player.participant.vars['solution_6'][h] for h in range(0, 10)], sol_7=[player.participant.vars['solution_7'][h] for h in range(0, 10)], sol_8=[player.participant.vars['solution_8'][h] for h in range(0, 10)], sol_9=[player.participant.vars['solution_9'][h] for h in range(0, 10)], total_green=player.participant.vars['total_green'], total_gray=player.participant.vars['total_gray'], ) def js_vars(player): return { 'total_green': player.participant.vars['total_green'], 'total_gray': player.participant.vars['total_gray'], } def before_next_page(self): self.participant.vars['points'] = self.player.points self.player.time_spent = math.floor(time.time() - self.participant.vars['sssss']) class results(Page): form_model = 'player' timeout_seconds = 3 def vars_for_template(self): return dict( points=self.participant.vars['points'], ) def js_vars(self): return { 'points': self.participant.vars['points'], } class payment(Page): form_model = 'player' # def is_displayed(self): # return self.round_number == 3 def vars_for_template(self): data = self.player.in_all_rounds() self.participant.vars['points_round1'] = data[0].points self.participant.vars['points_payment'] = self.participant.vars['points_round1'] # self.participant.vars['points_round2'] = data[1].points # self.participant.vars['points_round3'] = data[2].points # # if self.participant.vars['paying_round'] == 1: # self.participant.vars['points_payment'] = self.participant.vars['points_round1'] # if self.participant.vars['paying_round'] == 2: # self.participant.vars['points_payment'] = self.participant.vars['points_round2'] # if self.participant.vars['paying_round'] == 3: # self.participant.vars['points_payment'] = self.participant.vars['points_round3'] if self.participant.vars['points_payment'] > 0: self.player.payoff_nono = self.participant.vars['points_payment'] / 10 if self.participant.vars['points_payment'] <= 0: self.player.payoff_nono = 0 self.participant.vars['payoff_nono'] = self.player.payoff_nono self.player.final_payoff = self.player.payoff_nono + 3 self.participant.vars['final_payoff'] = self.player.final_payoff return dict( points_round1=self.participant.vars['points_round1'], # points_round2=self.participant.vars['points_round2'], # points_round3=self.participant.vars['points_round3'], # paying_round=self.participant.vars['paying_round'], points_payment=self.participant.vars['points_payment'], payoff_nono=self.participant.vars['payoff_nono'], final_payoff=self.participant.vars['final_payoff'], ) def js_vars(self): return { 'points_round1': self.participant.vars['points_round1'], # 'points_round2': self.participant.vars['points_round2'], # 'points_round3': self.participant.vars['points_round3'], # 'paying_round': self.participant.vars['paying_round'], 'points_payment':self.participant.vars['points_payment'], 'payoff_nono': self.participant.vars['payoff_nono'], 'final_payoff': self.participant.vars['final_payoff'], } class intro_survey(Page): form_model = 'player' # def is_displayed(self): # return self.round_number == 3 # class survey(Page): form_model = 'player' form_fields = ['nonogram_before', 'othergame_before'] # # def is_displayed(self): # return self.round_number == 3 page_sequence = [ Instructions, Game1, results, intro_survey, survey, payment, ]