import numpy as np import os from otree.api import * import pandas as pd doc = """ Experiment 2 for Social Inference project """ # OTREE CLASSES -------------------------------------------------------------------------------------------------------- class C(BaseConstants): NAME_IN_URL = 'SI_Exp2_TestPhase' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 # I think I may need 4 subsessions: 1) instructions + test, 2) MAB, 3) What do you think this was about? 4) Demographics + payment questionnaire class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): page_name = models.StringField() counter = models.IntegerField(default=0) transfer_cell1_index = models.StringField() transfer_cell1_value = models.IntegerField() transfer_cell2_index = models.StringField() transfer_cell2_value = models.IntegerField() transfer_cell3_index = models.StringField() transfer_cell3_value = models.IntegerField() transfer_cell4_index = models.StringField() transfer_cell4_value = models.IntegerField() transfer_cell5_index = models.StringField() transfer_cell5_value = models.IntegerField() transfer_cell6_index = models.StringField() transfer_cell6_value = models.IntegerField() transfer_cell7_index = models.StringField() transfer_cell7_value = models.IntegerField() transfer_cell8_index = models.StringField() transfer_cell8_value = models.IntegerField() transfer_cell9_index = models.StringField() transfer_cell9_value = models.IntegerField() transfer_cell10_index = models.StringField() transfer_cell10_value = models.IntegerField() transfer_cell11_index = models.StringField() transfer_cell11_value = models.IntegerField() transfer_cell12_index = models.StringField() transfer_cell12_value = models.IntegerField() transfer_cell13_index = models.StringField() transfer_cell13_value = models.IntegerField() #RT_cell1 = models.FloatField(initial=None) #RT_cell2 = models.FloatField(initial=None) round_data_field = models.IntegerField() order_cellPrompts = models.StringField() #VenmoUsername = models.StringField() #VenmoPhone = models.StringField() #Reward = models.FloatField() def store_round_data(self): self.round_data_field = self.round_number # Storing round number as an example def before_next_page(self): self.store_round_data() def increment_counter(self): self.counter += 1 return self.counter # PAGES (ASK ABOUT TOP CHOICES: SELECT & INDICATE) --------------------------------------------------------------------- class TransferInstructions(Page): template_name = 'SI_Exp2_TestPhase/TransferInstructions.html' # VERY IMPORTANT! vars_for_template seems to have some sort of meaning or hidden function. As soon as I change it into vars_for_grid, the html file does not recognize the names in the dictionary anymore! # I think this is because this is not a FUNCTION but a METHOD? def vars_for_template(self): my_array = np.empty((11, 11)) grid_number = my_array.tolist() return {'grid_number': grid_number} # I need to get the trial and trial_type out of the csv file #def before_next_page(player: Player, timeout_happened): # for now. this calculates the 3 smallest rewards. on only on one trial # and then it saves the values in participant vars so that they are accessible across apps # I could also change the folder structure, which I probably should at some point and store the demonstrator and page sequences in separate folders on a higher level so that they are accessible from SI_Exp1 and SX_Exp1_Part3 # but for now, this should work and I may change this once C was able to test #if player.counter == 0: #smallest_index_row, smallest_index_column, sec_smallest_index_row, sec_smallest_index_column, third_smallest_index_row, third_smallest_index_column = calcs_for_part3(player) #player.participant.vars['smallest_index_row'] = smallest_index_row #player.participant.vars['smallest_index_column'] = smallest_index_column #player.participant.vars['sec_smallest_index_row'] = sec_smallest_index_row #player.participant.vars['sec_smallest_index_column'] = sec_smallest_index_column #player.participant.vars['third_smallest_index_row'] = third_smallest_index_row #player.participant.vars['third_smallest_index_column'] = third_smallest_index_column # Access and increment the counter from the Player object #player.counter = player.increment_counter() class Last(Page): template_name = 'SI_Exp2_TestPhase/Last.html' def before_next_page(player, timeout_happened): player.order_cellPrompts = str(player.participant.vars['order']) timeout_seconds = .0001 # Here I'll do the calculations for the reward calculation # For both choice and reward predictions and inferences, I'll take the distance between the indices in a list. Have to do that on every trial # 1. import participant's choice and reward predictions/inferences # 2. import demonstrator's choices incl. the list [0 0 0 1 0 ...] and reward index and list [.5 .6 .2 ... .1 .9] (maybe don't import as list but pandas df as I can sort according to value and still keep the index) # 3. see "how far away" the participant's choice/reward is from demonstrator's choice and reward. # Assuming we have 7 choice/reward predictions/inferences each, leading to 28 queries, we can award up to 11 cents per trial. that means 0.001 (rounded up, assuming participants don't do too well) per index closer # difficulty: I would have to download and calculate the lists etc. from the database, which I can't do "live" as it would take too long. so I have to calculate the payment beforehand, in the main part of the experiment and "just share" the one value with this End page/across sessions class Cell1_Highest_Free(Page): template_name = 'SI_Exp2_TestPhase/Cell1_Highest_Free.html' # Define form fields form_model = 'player' form_fields = ['transfer_cell1_index', 'transfer_cell1_value'] #, 'RT_cell1' def vars_for_template(self): my_array = np.empty((11, 11)) grid_number = my_array.tolist() return {'grid_number': grid_number} def before_next_page(player, timeout_happened): player.transfer_cell1_index = player.transfer_cell1_index player.transfer_cell1_value = player.transfer_cell1_value class Cell2_Lowest_Free(Page): template_name = 'SI_Exp2_TestPhase/Cell2_Lowest_Free.html' # Define form fields form_model = 'player' form_fields = ['transfer_cell2_index', 'transfer_cell2_value'] def vars_for_template(self): grid_numbers = np.empty((11, 11)) # Example grid numbers # Restructure data to include indices grid_data = [] for row_idx, row in enumerate(grid_numbers): grid_row = [] for col_idx, value in enumerate(row): # I cheated here. This is very unclean, because it saves the value selected by the participant for every cell. But I didn't know how else to access it in html (the below didn't work) cell = {'value_cell1': self.transfer_cell1_value, 'row_index': row_idx, 'column_index': col_idx} grid_row.append(cell) grid_data.append(grid_row) # problem: this gets imported as string. highlight_index_row_cell1, highlight_index_column_cell1= string_to_integer(self.transfer_cell1_index) return {'grid_data': grid_data, 'highlight_index_row_cell1': int(highlight_index_row_cell1),'highlight_index_column_cell1': int(highlight_index_column_cell1)} # FORCED PAGES (ASK ABOUT WORST CHOICES: ONLY INDICATE) ---------------------------------------------------------------- # I still need an if loop, making sure that if it hasn't been selected so far... class Cell3_Forced(Page): template_name = 'SI_Exp2_TestPhase/Cell3_Forced.html' # Define form fields form_model = 'player' form_fields = ['transfer_cell3_index', 'transfer_cell3_value'] def vars_for_template(self): grid_numbers = np.empty((11, 11)) # Example grid numbers # Restructure data to include indices grid_data = [] for row_idx, row in enumerate(grid_numbers): grid_row = [] for col_idx, value in enumerate(row): cell = {'value_cell1': self.transfer_cell1_value, 'value_cell2': self.transfer_cell2_value, 'row_index': row_idx, 'column_index': col_idx} grid_row.append(cell) grid_data.append(grid_row) # problem: this gets imported as string. highlight_index_row_cell1, highlight_index_column_cell1= string_to_integer(self.transfer_cell1_index) highlight_index_row_cell2, highlight_index_column_cell2= string_to_integer(self.transfer_cell2_index) already_selected_cells = [[highlight_index_row_cell1,highlight_index_column_cell1], [highlight_index_row_cell2,highlight_index_column_cell2]] # This will be the list of forced choice cells we ask the participant for forced_choice_query = [] # now I need to get the row and column grid index based on the flat index number # ideally I do that for all 3 possible values that I had previously selected (hence up to range 3) # Create a flat list of values (just for demonstration) flat_list = np.arange(121) # Reshape the flat list into a 2D array array_2d = np.reshape(flat_list, (11, 11)) # Previously (on empty_grid page), I randomly drew 3 values/indices from 11 sorted groups of rewards (i.e., lowest reward group, second lowest reward group etc.) # I did that because I assume that we only has participants for the best and worst option (hence 2), so it could be that, by accident the participant chose exactly those 2 values that I wanted to ask them about # hence I need a third fall back option in case the participant had selected the two cells I wanted to ask about # here I import all three of them forced_choice_0_flat_index_0 = self.participant.vars['forced_choice_0'][0] forced_choice_0_flat_index_1 = self.participant.vars['forced_choice_0'][1] forced_choice_0_flat_index_2 = self.participant.vars['forced_choice_0'][2] # Find the indices of the flat index in the 2D array # Just need to make sure that both start indexing at the same number (0 or 1) --> yup, both start at 0 row_index_0, column_index_0 = np.where(array_2d == forced_choice_0_flat_index_0) row_index_1, column_index_1 = np.where(array_2d == forced_choice_0_flat_index_1) row_index_2, column_index_2 = np.where(array_2d == forced_choice_0_flat_index_2) # compare whether [row_index, column_index] had already been selected by the participant # if it had been selected, go for next randomly selected forced choice from that category if [row_index_0, column_index_0] not in already_selected_cells: forced_choice_query.append([row_index_0, column_index_0]) elif [row_index_1, column_index_1] not in already_selected_cells: forced_choice_query.append([row_index_1, column_index_1]) elif [row_index_2, column_index_2] not in already_selected_cells: forced_choice_query.append([row_index_2, column_index_2]) # Forced choice format: # print('forced_choice_query', forced_choice_query) # = forced_choice_query [[array([2], dtype=int64), array([1], dtype=int64)]] # This is the column index # print('forced_choice_query column', forced_choice_query[0][1][0]) # = forced_choice_query column 1 # This is the row index # print('forced_choice_query row', forced_choice_query[0][0][0], type(forced_choice_query[0][0][0]), int(forced_choice_query[0][0])) #=forced_choice_query row 2 2 return { 'grid_data': grid_data, 'highlight_index_row_cell1': int(highlight_index_row_cell1), 'highlight_index_column_cell1': int(highlight_index_column_cell1), 'highlight_index_row_cell2': int(highlight_index_row_cell2), 'highlight_index_column_cell2': int(highlight_index_column_cell2), 'highlight_index_row_cell3': int(forced_choice_query[0][0]), 'highlight_index_column_cell3': int(forced_choice_query[0][1]), 'transfer_cell1_value': self.transfer_cell1_value, # Pass the value from player object 'transfer_cell2_value': self.transfer_cell2_value, } class Cell4_Forced(Page): template_name = 'SI_Exp2_TestPhase/Cell4_Forced.html' form_model = 'player' form_fields = ['transfer_cell4_index', 'transfer_cell4_value'] def vars_for_template(self): grid_numbers = np.empty((11, 11)) grid_data = [] for row_idx, row in enumerate(grid_numbers): grid_row = [] for col_idx, value in enumerate(row): cell = {'value_cell1': self.transfer_cell1_value, 'value_cell2': self.transfer_cell2_value, 'value_cell3': self.transfer_cell3_value, 'row_index': row_idx, 'column_index': col_idx} grid_row.append(cell) grid_data.append(grid_row) highlight_index_row_cell1, highlight_index_column_cell1= string_to_integer(self.transfer_cell1_index) highlight_index_row_cell2, highlight_index_column_cell2= string_to_integer(self.transfer_cell2_index) highlight_index_row_cell3, highlight_index_column_cell3= string_to_integer(self.transfer_cell3_index) already_selected_cells = [[highlight_index_row_cell1,highlight_index_column_cell1], [highlight_index_row_cell2,highlight_index_column_cell2]] forced_choice_query = [] flat_list = np.arange(121) array_2d = np.reshape(flat_list, (11, 11)) forced_choice_1_flat_index_0 = self.participant.vars['forced_choice_1'][0] forced_choice_1_flat_index_1 = self.participant.vars['forced_choice_1'][1] forced_choice_1_flat_index_2 = self.participant.vars['forced_choice_1'][2] row_index_0, column_index_0 = np.where(array_2d == forced_choice_1_flat_index_0) row_index_1, column_index_1 = np.where(array_2d == forced_choice_1_flat_index_1) row_index_2, column_index_2 = np.where(array_2d == forced_choice_1_flat_index_2) if [row_index_0, column_index_0] not in already_selected_cells: forced_choice_query.append([row_index_0, column_index_0]) elif [row_index_1, column_index_1] not in already_selected_cells: forced_choice_query.append([row_index_1, column_index_1]) elif [row_index_2, column_index_2] not in already_selected_cells: forced_choice_query.append([row_index_2, column_index_2]) return { 'grid_data': grid_data, 'highlight_index_row_cell1': int(highlight_index_row_cell1), 'highlight_index_column_cell1': int(highlight_index_column_cell1), 'highlight_index_row_cell2': int(highlight_index_row_cell2), 'highlight_index_column_cell2': int(highlight_index_column_cell2), 'highlight_index_row_cell3': highlight_index_row_cell3, 'highlight_index_column_cell3': highlight_index_column_cell3, 'highlight_index_row_cell4': int(forced_choice_query[0][0]), 'highlight_index_column_cell4': int(forced_choice_query[0][1]), 'transfer_cell1_value': self.transfer_cell1_value, 'transfer_cell2_value': self.transfer_cell2_value, 'transfer_cell3_value': self.transfer_cell3_value, } class Cell5_Forced(Page): template_name = 'SI_Exp2_TestPhase/Cell5_Forced.html' form_model = 'player' form_fields = ['transfer_cell5_index', 'transfer_cell5_value'] def vars_for_template(self): grid_numbers = np.empty((11, 11)) grid_data = [] for row_idx, row in enumerate(grid_numbers): grid_row = [] for col_idx, value in enumerate(row): cell = {'value_cell1': self.transfer_cell1_value, 'value_cell2': self.transfer_cell2_value, 'value_cell3': self.transfer_cell3_value, 'value_cell4': self.transfer_cell4_value, 'row_index': row_idx, 'column_index': col_idx} grid_row.append(cell) grid_data.append(grid_row) highlight_index_row_cell1, highlight_index_column_cell1= string_to_integer(self.transfer_cell1_index) highlight_index_row_cell2, highlight_index_column_cell2= string_to_integer(self.transfer_cell2_index) highlight_index_row_cell3, highlight_index_column_cell3= string_to_integer(self.transfer_cell3_index) highlight_index_row_cell4, highlight_index_column_cell4= string_to_integer(self.transfer_cell4_index) already_selected_cells = [[highlight_index_row_cell1,highlight_index_column_cell1], [highlight_index_row_cell2,highlight_index_column_cell2]] forced_choice_query = [] flat_list = np.arange(121) array_2d = np.reshape(flat_list, (11, 11)) forced_choice_1_flat_index_0 = self.participant.vars['forced_choice_2'][0] forced_choice_1_flat_index_1 = self.participant.vars['forced_choice_2'][1] forced_choice_1_flat_index_2 = self.participant.vars['forced_choice_2'][2] row_index_0, column_index_0 = np.where(array_2d == forced_choice_1_flat_index_0) row_index_1, column_index_1 = np.where(array_2d == forced_choice_1_flat_index_1) row_index_2, column_index_2 = np.where(array_2d == forced_choice_1_flat_index_2) if [row_index_0, column_index_0] not in already_selected_cells: forced_choice_query.append([row_index_0, column_index_0]) elif [row_index_1, column_index_1] not in already_selected_cells: forced_choice_query.append([row_index_1, column_index_1]) elif [row_index_2, column_index_2] not in already_selected_cells: forced_choice_query.append([row_index_2, column_index_2]) return { 'grid_data': grid_data, 'highlight_index_row_cell1': int(highlight_index_row_cell1), 'highlight_index_column_cell1': int(highlight_index_column_cell1), 'highlight_index_row_cell2': int(highlight_index_row_cell2), 'highlight_index_column_cell2': int(highlight_index_column_cell2), 'highlight_index_row_cell3': highlight_index_row_cell3, 'highlight_index_column_cell3': highlight_index_column_cell3, 'highlight_index_row_cell4': highlight_index_row_cell4, 'highlight_index_column_cell4': highlight_index_column_cell4, 'highlight_index_row_cell5': int(forced_choice_query[0][0]), 'highlight_index_column_cell5': int(forced_choice_query[0][1]), 'transfer_cell1_value': self.transfer_cell1_value, 'transfer_cell2_value': self.transfer_cell2_value, 'transfer_cell3_value': self.transfer_cell3_value, 'transfer_cell4_value': self.transfer_cell4_value, } class Cell6_Forced(Page): template_name = 'SI_Exp2_TestPhase/Cell6_Forced.html' form_model = 'player' form_fields = ['transfer_cell6_index', 'transfer_cell6_value'] def vars_for_template(self): grid_numbers = np.empty((11, 11)) grid_data = [] for row_idx, row in enumerate(grid_numbers): grid_row = [] for col_idx, value in enumerate(row): cell = {'value_cell1': self.transfer_cell1_value, 'value_cell2': self.transfer_cell2_value, 'value_cell3': self.transfer_cell3_value, 'value_cell4': self.transfer_cell4_value, 'value_cell5': self.transfer_cell5_value, 'row_index': row_idx, 'column_index': col_idx} grid_row.append(cell) grid_data.append(grid_row) highlight_index_row_cell1, highlight_index_column_cell1= string_to_integer(self.transfer_cell1_index) highlight_index_row_cell2, highlight_index_column_cell2= string_to_integer(self.transfer_cell2_index) highlight_index_row_cell3, highlight_index_column_cell3= string_to_integer(self.transfer_cell3_index) highlight_index_row_cell4, highlight_index_column_cell4= string_to_integer(self.transfer_cell4_index) highlight_index_row_cell5, highlight_index_column_cell5= string_to_integer(self.transfer_cell5_index) already_selected_cells = [[highlight_index_row_cell1,highlight_index_column_cell1], [highlight_index_row_cell2,highlight_index_column_cell2]] forced_choice_query = [] flat_list = np.arange(121) array_2d = np.reshape(flat_list, (11, 11)) forced_choice_1_flat_index_0 = self.participant.vars['forced_choice_3'][0] forced_choice_1_flat_index_1 = self.participant.vars['forced_choice_3'][1] forced_choice_1_flat_index_2 = self.participant.vars['forced_choice_3'][2] row_index_0, column_index_0 = np.where(array_2d == forced_choice_1_flat_index_0) row_index_1, column_index_1 = np.where(array_2d == forced_choice_1_flat_index_1) row_index_2, column_index_2 = np.where(array_2d == forced_choice_1_flat_index_2) if [row_index_0, column_index_0] not in already_selected_cells: forced_choice_query.append([row_index_0, column_index_0]) elif [row_index_1, column_index_1] not in already_selected_cells: forced_choice_query.append([row_index_1, column_index_1]) elif [row_index_2, column_index_2] not in already_selected_cells: forced_choice_query.append([row_index_2, column_index_2]) return { 'grid_data': grid_data, 'highlight_index_row_cell1': int(highlight_index_row_cell1), 'highlight_index_column_cell1': int(highlight_index_column_cell1), 'highlight_index_row_cell2': int(highlight_index_row_cell2), 'highlight_index_column_cell2': int(highlight_index_column_cell2), 'highlight_index_row_cell3': highlight_index_row_cell3, 'highlight_index_column_cell3': highlight_index_column_cell3, 'highlight_index_row_cell4': highlight_index_row_cell4, 'highlight_index_column_cell4': highlight_index_column_cell4, 'highlight_index_row_cell5': highlight_index_row_cell5, 'highlight_index_column_cell5': highlight_index_column_cell5, 'highlight_index_row_cell6': int(forced_choice_query[0][0]), 'highlight_index_column_cell6': int(forced_choice_query[0][1]), 'transfer_cell1_value': self.transfer_cell1_value, 'transfer_cell2_value': self.transfer_cell2_value, 'transfer_cell3_value': self.transfer_cell3_value, 'transfer_cell4_value': self.transfer_cell4_value, 'transfer_cell5_value': self.transfer_cell5_value, } class Cell7_Forced(Page): template_name = 'SI_Exp2_TestPhase/Cell7_Forced.html' form_model = 'player' form_fields = ['transfer_cell7_index', 'transfer_cell7_value'] def vars_for_template(self): grid_numbers = np.empty((11, 11)) grid_data = [] for row_idx, row in enumerate(grid_numbers): grid_row = [] for col_idx, value in enumerate(row): cell = {'value_cell1': self.transfer_cell1_value, 'value_cell2': self.transfer_cell2_value, 'value_cell3': self.transfer_cell3_value, 'value_cell4': self.transfer_cell4_value, 'value_cell5': self.transfer_cell5_value, 'value_cell6': self.transfer_cell6_value, 'row_index': row_idx, 'column_index': col_idx} grid_row.append(cell) grid_data.append(grid_row) highlight_index_row_cell1, highlight_index_column_cell1= string_to_integer(self.transfer_cell1_index) highlight_index_row_cell2, highlight_index_column_cell2= string_to_integer(self.transfer_cell2_index) highlight_index_row_cell3, highlight_index_column_cell3= string_to_integer(self.transfer_cell3_index) highlight_index_row_cell4, highlight_index_column_cell4= string_to_integer(self.transfer_cell4_index) highlight_index_row_cell5, highlight_index_column_cell5= string_to_integer(self.transfer_cell5_index) highlight_index_row_cell6, highlight_index_column_cell6= string_to_integer(self.transfer_cell6_index) already_selected_cells = [[highlight_index_row_cell1,highlight_index_column_cell1], [highlight_index_row_cell2,highlight_index_column_cell2]] forced_choice_query = [] flat_list = np.arange(121) array_2d = np.reshape(flat_list, (11, 11)) forced_choice_1_flat_index_0 = self.participant.vars['forced_choice_4'][0] forced_choice_1_flat_index_1 = self.participant.vars['forced_choice_4'][1] forced_choice_1_flat_index_2 = self.participant.vars['forced_choice_4'][2] row_index_0, column_index_0 = np.where(array_2d == forced_choice_1_flat_index_0) row_index_1, column_index_1 = np.where(array_2d == forced_choice_1_flat_index_1) row_index_2, column_index_2 = np.where(array_2d == forced_choice_1_flat_index_2) if [row_index_0, column_index_0] not in already_selected_cells: forced_choice_query.append([row_index_0, column_index_0]) elif [row_index_1, column_index_1] not in already_selected_cells: forced_choice_query.append([row_index_1, column_index_1]) elif [row_index_2, column_index_2] not in already_selected_cells: forced_choice_query.append([row_index_2, column_index_2]) return { 'grid_data': grid_data, 'highlight_index_row_cell1': int(highlight_index_row_cell1), 'highlight_index_column_cell1': int(highlight_index_column_cell1), 'highlight_index_row_cell2': int(highlight_index_row_cell2), 'highlight_index_column_cell2': int(highlight_index_column_cell2), 'highlight_index_row_cell3': highlight_index_row_cell3, 'highlight_index_column_cell3': highlight_index_column_cell3, 'highlight_index_row_cell4': highlight_index_row_cell4, 'highlight_index_column_cell4': highlight_index_column_cell4, 'highlight_index_row_cell5': highlight_index_row_cell5, 'highlight_index_column_cell5': highlight_index_column_cell5, 'highlight_index_row_cell6': highlight_index_row_cell6, 'highlight_index_column_cell6': highlight_index_column_cell6, 'highlight_index_row_cell7': int(forced_choice_query[0][0]), 'highlight_index_column_cell7': int(forced_choice_query[0][1]), 'transfer_cell1_value': self.transfer_cell1_value, 'transfer_cell2_value': self.transfer_cell2_value, 'transfer_cell3_value': self.transfer_cell3_value, 'transfer_cell4_value': self.transfer_cell4_value, 'transfer_cell5_value': self.transfer_cell5_value, 'transfer_cell6_value': self.transfer_cell6_value, } class Cell8_Forced(Page): template_name = 'SI_Exp2_TestPhase/Cell8_Forced.html' form_model = 'player' form_fields = ['transfer_cell8_index', 'transfer_cell8_value'] def vars_for_template(self): grid_numbers = np.empty((11, 11)) grid_data = [] for row_idx, row in enumerate(grid_numbers): grid_row = [] for col_idx, value in enumerate(row): cell = {'value_cell1': self.transfer_cell1_value, 'value_cell2': self.transfer_cell2_value, 'value_cell3': self.transfer_cell3_value, 'value_cell4': self.transfer_cell4_value, 'value_cell5': self.transfer_cell5_value, 'value_cell6': self.transfer_cell6_value, 'value_cell7': self.transfer_cell7_value, 'row_index': row_idx, 'column_index': col_idx} grid_row.append(cell) grid_data.append(grid_row) highlight_index_row_cell1, highlight_index_column_cell1= string_to_integer(self.transfer_cell1_index) highlight_index_row_cell2, highlight_index_column_cell2= string_to_integer(self.transfer_cell2_index) highlight_index_row_cell3, highlight_index_column_cell3= string_to_integer(self.transfer_cell3_index) highlight_index_row_cell4, highlight_index_column_cell4= string_to_integer(self.transfer_cell4_index) highlight_index_row_cell5, highlight_index_column_cell5= string_to_integer(self.transfer_cell5_index) highlight_index_row_cell6, highlight_index_column_cell6= string_to_integer(self.transfer_cell6_index) highlight_index_row_cell7, highlight_index_column_cell7= string_to_integer(self.transfer_cell7_index) already_selected_cells = [[highlight_index_row_cell1,highlight_index_column_cell1], [highlight_index_row_cell2,highlight_index_column_cell2]] forced_choice_query = [] flat_list = np.arange(121) array_2d = np.reshape(flat_list, (11, 11)) forced_choice_1_flat_index_0 = self.participant.vars['forced_choice_5'][0] forced_choice_1_flat_index_1 = self.participant.vars['forced_choice_5'][1] forced_choice_1_flat_index_2 = self.participant.vars['forced_choice_5'][2] row_index_0, column_index_0 = np.where(array_2d == forced_choice_1_flat_index_0) row_index_1, column_index_1 = np.where(array_2d == forced_choice_1_flat_index_1) row_index_2, column_index_2 = np.where(array_2d == forced_choice_1_flat_index_2) if [row_index_0, column_index_0] not in already_selected_cells: forced_choice_query.append([row_index_0, column_index_0]) elif [row_index_1, column_index_1] not in already_selected_cells: forced_choice_query.append([row_index_1, column_index_1]) elif [row_index_2, column_index_2] not in already_selected_cells: forced_choice_query.append([row_index_2, column_index_2]) return { 'grid_data': grid_data, 'highlight_index_row_cell1': int(highlight_index_row_cell1), 'highlight_index_column_cell1': int(highlight_index_column_cell1), 'highlight_index_row_cell2': int(highlight_index_row_cell2), 'highlight_index_column_cell2': int(highlight_index_column_cell2), 'highlight_index_row_cell3': highlight_index_row_cell3, 'highlight_index_column_cell3': highlight_index_column_cell3, 'highlight_index_row_cell4': highlight_index_row_cell4, 'highlight_index_column_cell4': highlight_index_column_cell4, 'highlight_index_row_cell5': highlight_index_row_cell5, 'highlight_index_column_cell5': highlight_index_column_cell5, 'highlight_index_row_cell6': highlight_index_row_cell6, 'highlight_index_column_cell6': highlight_index_column_cell6, 'highlight_index_row_cell7': highlight_index_row_cell7, 'highlight_index_column_cell7': highlight_index_column_cell7, 'highlight_index_row_cell8': int(forced_choice_query[0][0]), 'highlight_index_column_cell8': int(forced_choice_query[0][1]), 'transfer_cell1_value': self.transfer_cell1_value, 'transfer_cell2_value': self.transfer_cell2_value, 'transfer_cell3_value': self.transfer_cell3_value, 'transfer_cell4_value': self.transfer_cell4_value, 'transfer_cell5_value': self.transfer_cell5_value, 'transfer_cell6_value': self.transfer_cell6_value, 'transfer_cell7_value': self.transfer_cell7_value, } class Cell9_Forced(Page): template_name = 'SI_Exp2_TestPhase/Cell9_Forced.html' form_model = 'player' form_fields = ['transfer_cell9_index', 'transfer_cell9_value'] def vars_for_template(self): grid_numbers = np.empty((11, 11)) grid_data = [] for row_idx, row in enumerate(grid_numbers): grid_row = [] for col_idx, value in enumerate(row): cell = {'value_cell1': self.transfer_cell1_value, 'value_cell2': self.transfer_cell2_value, 'value_cell3': self.transfer_cell3_value, 'value_cell4': self.transfer_cell4_value, 'value_cell5': self.transfer_cell5_value, 'value_cell6': self.transfer_cell6_value, 'value_cell7': self.transfer_cell7_value, 'value_cell8': self.transfer_cell8_value, 'row_index': row_idx, 'column_index': col_idx} grid_row.append(cell) grid_data.append(grid_row) highlight_index_row_cell1, highlight_index_column_cell1= string_to_integer(self.transfer_cell1_index) highlight_index_row_cell2, highlight_index_column_cell2= string_to_integer(self.transfer_cell2_index) highlight_index_row_cell3, highlight_index_column_cell3= string_to_integer(self.transfer_cell3_index) highlight_index_row_cell4, highlight_index_column_cell4= string_to_integer(self.transfer_cell4_index) highlight_index_row_cell5, highlight_index_column_cell5= string_to_integer(self.transfer_cell5_index) highlight_index_row_cell6, highlight_index_column_cell6= string_to_integer(self.transfer_cell6_index) highlight_index_row_cell7, highlight_index_column_cell7= string_to_integer(self.transfer_cell7_index) highlight_index_row_cell8, highlight_index_column_cell8= string_to_integer(self.transfer_cell8_index) already_selected_cells = [[highlight_index_row_cell1,highlight_index_column_cell1], [highlight_index_row_cell2,highlight_index_column_cell2]] forced_choice_query = [] flat_list = np.arange(121) array_2d = np.reshape(flat_list, (11, 11)) forced_choice_1_flat_index_0 = self.participant.vars['forced_choice_6'][0] forced_choice_1_flat_index_1 = self.participant.vars['forced_choice_6'][1] forced_choice_1_flat_index_2 = self.participant.vars['forced_choice_6'][2] row_index_0, column_index_0 = np.where(array_2d == forced_choice_1_flat_index_0) row_index_1, column_index_1 = np.where(array_2d == forced_choice_1_flat_index_1) row_index_2, column_index_2 = np.where(array_2d == forced_choice_1_flat_index_2) if [row_index_0, column_index_0] not in already_selected_cells: forced_choice_query.append([row_index_0, column_index_0]) elif [row_index_1, column_index_1] not in already_selected_cells: forced_choice_query.append([row_index_1, column_index_1]) elif [row_index_2, column_index_2] not in already_selected_cells: forced_choice_query.append([row_index_2, column_index_2]) return { 'grid_data': grid_data, 'highlight_index_row_cell1': int(highlight_index_row_cell1), 'highlight_index_column_cell1': int(highlight_index_column_cell1), 'highlight_index_row_cell2': int(highlight_index_row_cell2), 'highlight_index_column_cell2': int(highlight_index_column_cell2), 'highlight_index_row_cell3': highlight_index_row_cell3, 'highlight_index_column_cell3': highlight_index_column_cell3, 'highlight_index_row_cell4': highlight_index_row_cell4, 'highlight_index_column_cell4': highlight_index_column_cell4, 'highlight_index_row_cell5': highlight_index_row_cell5, 'highlight_index_column_cell5': highlight_index_column_cell5, 'highlight_index_row_cell6': highlight_index_row_cell6, 'highlight_index_column_cell6': highlight_index_column_cell6, 'highlight_index_row_cell7': highlight_index_row_cell7, 'highlight_index_column_cell7': highlight_index_column_cell7, 'highlight_index_row_cell8': highlight_index_row_cell8, 'highlight_index_column_cell8': highlight_index_column_cell8, 'highlight_index_row_cell9': int(forced_choice_query[0][0]), 'highlight_index_column_cell9': int(forced_choice_query[0][1]), 'transfer_cell1_value': self.transfer_cell1_value, 'transfer_cell2_value': self.transfer_cell2_value, 'transfer_cell3_value': self.transfer_cell3_value, 'transfer_cell4_value': self.transfer_cell4_value, 'transfer_cell5_value': self.transfer_cell5_value, 'transfer_cell6_value': self.transfer_cell6_value, 'transfer_cell7_value': self.transfer_cell7_value, 'transfer_cell8_value': self.transfer_cell8_value, } class Cell10_Forced(Page): template_name = 'SI_Exp2_TestPhase/Cell10_Forced.html' form_model = 'player' form_fields = ['transfer_cell10_index', 'transfer_cell10_value'] def vars_for_template(self): grid_numbers = np.empty((11, 11)) grid_data = [] for row_idx, row in enumerate(grid_numbers): grid_row = [] for col_idx, value in enumerate(row): cell = {'value_cell1': self.transfer_cell1_value, 'value_cell2': self.transfer_cell2_value, 'value_cell3': self.transfer_cell3_value, 'value_cell4': self.transfer_cell4_value, 'value_cell5': self.transfer_cell5_value, 'value_cell6': self.transfer_cell6_value, 'value_cell7': self.transfer_cell7_value, 'value_cell8': self.transfer_cell8_value, 'value_cell9': self.transfer_cell9_value, 'row_index': row_idx, 'column_index': col_idx} grid_row.append(cell) grid_data.append(grid_row) highlight_index_row_cell1, highlight_index_column_cell1= string_to_integer(self.transfer_cell1_index) highlight_index_row_cell2, highlight_index_column_cell2= string_to_integer(self.transfer_cell2_index) highlight_index_row_cell3, highlight_index_column_cell3= string_to_integer(self.transfer_cell3_index) highlight_index_row_cell4, highlight_index_column_cell4= string_to_integer(self.transfer_cell4_index) highlight_index_row_cell5, highlight_index_column_cell5= string_to_integer(self.transfer_cell5_index) highlight_index_row_cell6, highlight_index_column_cell6= string_to_integer(self.transfer_cell6_index) highlight_index_row_cell7, highlight_index_column_cell7= string_to_integer(self.transfer_cell7_index) highlight_index_row_cell8, highlight_index_column_cell8= string_to_integer(self.transfer_cell8_index) highlight_index_row_cell9, highlight_index_column_cell9= string_to_integer(self.transfer_cell9_index) already_selected_cells = [[highlight_index_row_cell1,highlight_index_column_cell1], [highlight_index_row_cell2,highlight_index_column_cell2]] forced_choice_query = [] flat_list = np.arange(121) array_2d = np.reshape(flat_list, (11, 11)) forced_choice_1_flat_index_0 = self.participant.vars['forced_choice_7'][0] forced_choice_1_flat_index_1 = self.participant.vars['forced_choice_7'][1] forced_choice_1_flat_index_2 = self.participant.vars['forced_choice_7'][2] row_index_0, column_index_0 = np.where(array_2d == forced_choice_1_flat_index_0) row_index_1, column_index_1 = np.where(array_2d == forced_choice_1_flat_index_1) row_index_2, column_index_2 = np.where(array_2d == forced_choice_1_flat_index_2) if [row_index_0, column_index_0] not in already_selected_cells: forced_choice_query.append([row_index_0, column_index_0]) elif [row_index_1, column_index_1] not in already_selected_cells: forced_choice_query.append([row_index_1, column_index_1]) elif [row_index_2, column_index_2] not in already_selected_cells: forced_choice_query.append([row_index_2, column_index_2]) return { 'grid_data': grid_data, 'highlight_index_row_cell1': int(highlight_index_row_cell1), 'highlight_index_column_cell1': int(highlight_index_column_cell1), 'highlight_index_row_cell2': int(highlight_index_row_cell2), 'highlight_index_column_cell2': int(highlight_index_column_cell2), 'highlight_index_row_cell3': highlight_index_row_cell3, 'highlight_index_column_cell3': highlight_index_column_cell3, 'highlight_index_row_cell4': highlight_index_row_cell4, 'highlight_index_column_cell4': highlight_index_column_cell4, 'highlight_index_row_cell5': highlight_index_row_cell5, 'highlight_index_column_cell5': highlight_index_column_cell5, 'highlight_index_row_cell6': highlight_index_row_cell6, 'highlight_index_column_cell6': highlight_index_column_cell6, 'highlight_index_row_cell7': highlight_index_row_cell7, 'highlight_index_column_cell7': highlight_index_column_cell7, 'highlight_index_row_cell8': highlight_index_row_cell8, 'highlight_index_column_cell8': highlight_index_column_cell8, 'highlight_index_row_cell9': highlight_index_row_cell9, 'highlight_index_column_cell9': highlight_index_column_cell9, 'highlight_index_row_cell10': int(forced_choice_query[0][0]), 'highlight_index_column_cell10': int(forced_choice_query[0][1]), 'transfer_cell1_value': self.transfer_cell1_value, 'transfer_cell2_value': self.transfer_cell2_value, 'transfer_cell3_value': self.transfer_cell3_value, 'transfer_cell4_value': self.transfer_cell4_value, 'transfer_cell5_value': self.transfer_cell5_value, 'transfer_cell6_value': self.transfer_cell6_value, 'transfer_cell7_value': self.transfer_cell7_value, 'transfer_cell8_value': self.transfer_cell8_value, 'transfer_cell9_value': self.transfer_cell9_value, } class Cell11_Forced(Page): template_name = 'SI_Exp2_TestPhase/Cell11_Forced.html' form_model = 'player' form_fields = ['transfer_cell11_index', 'transfer_cell11_value'] def vars_for_template(self): grid_numbers = np.empty((11, 11)) grid_data = [] for row_idx, row in enumerate(grid_numbers): grid_row = [] for col_idx, value in enumerate(row): cell = {'value_cell1': self.transfer_cell1_value, 'value_cell2': self.transfer_cell2_value, 'value_cell3': self.transfer_cell3_value, 'value_cell4': self.transfer_cell4_value, 'value_cell5': self.transfer_cell5_value, 'value_cell6': self.transfer_cell6_value, 'value_cell7': self.transfer_cell7_value, 'value_cell8': self.transfer_cell8_value, 'value_cell9': self.transfer_cell9_value, 'value_cell10': self.transfer_cell10_value, 'row_index': row_idx, 'column_index': col_idx} grid_row.append(cell) grid_data.append(grid_row) highlight_index_row_cell1, highlight_index_column_cell1= string_to_integer(self.transfer_cell1_index) highlight_index_row_cell2, highlight_index_column_cell2= string_to_integer(self.transfer_cell2_index) highlight_index_row_cell3, highlight_index_column_cell3= string_to_integer(self.transfer_cell3_index) highlight_index_row_cell4, highlight_index_column_cell4= string_to_integer(self.transfer_cell4_index) highlight_index_row_cell5, highlight_index_column_cell5= string_to_integer(self.transfer_cell5_index) highlight_index_row_cell6, highlight_index_column_cell6= string_to_integer(self.transfer_cell6_index) highlight_index_row_cell7, highlight_index_column_cell7= string_to_integer(self.transfer_cell7_index) highlight_index_row_cell8, highlight_index_column_cell8= string_to_integer(self.transfer_cell8_index) highlight_index_row_cell9, highlight_index_column_cell9= string_to_integer(self.transfer_cell9_index) highlight_index_row_cell10, highlight_index_column_cell10= string_to_integer(self.transfer_cell10_index) already_selected_cells = [[highlight_index_row_cell1,highlight_index_column_cell1], [highlight_index_row_cell2,highlight_index_column_cell2]] forced_choice_query = [] flat_list = np.arange(121) array_2d = np.reshape(flat_list, (11, 11)) forced_choice_1_flat_index_0 = self.participant.vars['forced_choice_8'][0] forced_choice_1_flat_index_1 = self.participant.vars['forced_choice_8'][1] forced_choice_1_flat_index_2 = self.participant.vars['forced_choice_8'][2] row_index_0, column_index_0 = np.where(array_2d == forced_choice_1_flat_index_0) row_index_1, column_index_1 = np.where(array_2d == forced_choice_1_flat_index_1) row_index_2, column_index_2 = np.where(array_2d == forced_choice_1_flat_index_2) if [row_index_0, column_index_0] not in already_selected_cells: forced_choice_query.append([row_index_0, column_index_0]) elif [row_index_1, column_index_1] not in already_selected_cells: forced_choice_query.append([row_index_1, column_index_1]) elif [row_index_2, column_index_2] not in already_selected_cells: forced_choice_query.append([row_index_2, column_index_2]) return { 'grid_data': grid_data, 'highlight_index_row_cell1': int(highlight_index_row_cell1), 'highlight_index_column_cell1': int(highlight_index_column_cell1), 'highlight_index_row_cell2': int(highlight_index_row_cell2), 'highlight_index_column_cell2': int(highlight_index_column_cell2), 'highlight_index_row_cell3': highlight_index_row_cell3, 'highlight_index_column_cell3': highlight_index_column_cell3, 'highlight_index_row_cell4': highlight_index_row_cell4, 'highlight_index_column_cell4': highlight_index_column_cell4, 'highlight_index_row_cell5': highlight_index_row_cell5, 'highlight_index_column_cell5': highlight_index_column_cell5, 'highlight_index_row_cell6': highlight_index_row_cell6, 'highlight_index_column_cell6': highlight_index_column_cell6, 'highlight_index_row_cell7': highlight_index_row_cell7, 'highlight_index_column_cell7': highlight_index_column_cell7, 'highlight_index_row_cell8': highlight_index_row_cell8, 'highlight_index_column_cell8': highlight_index_column_cell8, 'highlight_index_row_cell9': highlight_index_row_cell9, 'highlight_index_column_cell9': highlight_index_column_cell9, 'highlight_index_row_cell10': highlight_index_row_cell10, 'highlight_index_column_cell10': highlight_index_column_cell10, 'highlight_index_row_cell11': int(forced_choice_query[0][0]), 'highlight_index_column_cell11': int(forced_choice_query[0][1]), 'transfer_cell1_value': self.transfer_cell1_value, 'transfer_cell2_value': self.transfer_cell2_value, 'transfer_cell3_value': self.transfer_cell3_value, 'transfer_cell4_value': self.transfer_cell4_value, 'transfer_cell5_value': self.transfer_cell5_value, 'transfer_cell6_value': self.transfer_cell6_value, 'transfer_cell7_value': self.transfer_cell7_value, 'transfer_cell8_value': self.transfer_cell8_value, 'transfer_cell9_value': self.transfer_cell9_value, 'transfer_cell10_value': self.transfer_cell10_value, } class Cell12_Forced(Page): template_name = 'SI_Exp2_TestPhase/Cell12_Forced.html' form_model = 'player' form_fields = ['transfer_cell12_index', 'transfer_cell12_value'] def vars_for_template(self): grid_numbers = np.empty((11, 11)) grid_data = [] for row_idx, row in enumerate(grid_numbers): grid_row = [] for col_idx, value in enumerate(row): cell = {'value_cell1': self.transfer_cell1_value, 'value_cell2': self.transfer_cell2_value, 'value_cell3': self.transfer_cell3_value, 'value_cell4': self.transfer_cell4_value, 'value_cell5': self.transfer_cell5_value, 'value_cell6': self.transfer_cell6_value, 'value_cell7': self.transfer_cell7_value, 'value_cell8': self.transfer_cell8_value, 'value_cell9': self.transfer_cell9_value, 'value_cell10': self.transfer_cell10_value, 'value_cell11': self.transfer_cell11_value, 'row_index': row_idx, 'column_index': col_idx} grid_row.append(cell) grid_data.append(grid_row) highlight_index_row_cell1, highlight_index_column_cell1= string_to_integer(self.transfer_cell1_index) highlight_index_row_cell2, highlight_index_column_cell2= string_to_integer(self.transfer_cell2_index) highlight_index_row_cell3, highlight_index_column_cell3= string_to_integer(self.transfer_cell3_index) highlight_index_row_cell4, highlight_index_column_cell4= string_to_integer(self.transfer_cell4_index) highlight_index_row_cell5, highlight_index_column_cell5= string_to_integer(self.transfer_cell5_index) highlight_index_row_cell6, highlight_index_column_cell6= string_to_integer(self.transfer_cell6_index) highlight_index_row_cell7, highlight_index_column_cell7= string_to_integer(self.transfer_cell7_index) highlight_index_row_cell8, highlight_index_column_cell8= string_to_integer(self.transfer_cell8_index) highlight_index_row_cell9, highlight_index_column_cell9= string_to_integer(self.transfer_cell9_index) highlight_index_row_cell10, highlight_index_column_cell10= string_to_integer(self.transfer_cell10_index) highlight_index_row_cell11, highlight_index_column_cell11= string_to_integer(self.transfer_cell11_index) already_selected_cells = [[highlight_index_row_cell1,highlight_index_column_cell1], [highlight_index_row_cell2,highlight_index_column_cell2]] forced_choice_query = [] flat_list = np.arange(121) array_2d = np.reshape(flat_list, (11, 11)) forced_choice_1_flat_index_0 = self.participant.vars['forced_choice_9'][0] forced_choice_1_flat_index_1 = self.participant.vars['forced_choice_9'][1] forced_choice_1_flat_index_2 = self.participant.vars['forced_choice_9'][2] row_index_0, column_index_0 = np.where(array_2d == forced_choice_1_flat_index_0) row_index_1, column_index_1 = np.where(array_2d == forced_choice_1_flat_index_1) row_index_2, column_index_2 = np.where(array_2d == forced_choice_1_flat_index_2) if [row_index_0, column_index_0] not in already_selected_cells: forced_choice_query.append([row_index_0, column_index_0]) elif [row_index_1, column_index_1] not in already_selected_cells: forced_choice_query.append([row_index_1, column_index_1]) elif [row_index_2, column_index_2] not in already_selected_cells: forced_choice_query.append([row_index_2, column_index_2]) return { 'grid_data': grid_data, 'highlight_index_row_cell1': int(highlight_index_row_cell1), 'highlight_index_column_cell1': int(highlight_index_column_cell1), 'highlight_index_row_cell2': int(highlight_index_row_cell2), 'highlight_index_column_cell2': int(highlight_index_column_cell2), 'highlight_index_row_cell3': highlight_index_row_cell3, 'highlight_index_column_cell3': highlight_index_column_cell3, 'highlight_index_row_cell4': highlight_index_row_cell4, 'highlight_index_column_cell4': highlight_index_column_cell4, 'highlight_index_row_cell5': highlight_index_row_cell5, 'highlight_index_column_cell5': highlight_index_column_cell5, 'highlight_index_row_cell6': highlight_index_row_cell6, 'highlight_index_column_cell6': highlight_index_column_cell6, 'highlight_index_row_cell7': highlight_index_row_cell7, 'highlight_index_column_cell7': highlight_index_column_cell7, 'highlight_index_row_cell8': highlight_index_row_cell8, 'highlight_index_column_cell8': highlight_index_column_cell8, 'highlight_index_row_cell9': highlight_index_row_cell9, 'highlight_index_column_cell9': highlight_index_column_cell9, 'highlight_index_row_cell10': highlight_index_row_cell10, 'highlight_index_column_cell10': highlight_index_column_cell10, 'highlight_index_row_cell11': highlight_index_row_cell11, 'highlight_index_column_cell11': highlight_index_column_cell11, 'highlight_index_row_cell12': int(forced_choice_query[0][0]), 'highlight_index_column_cell12': int(forced_choice_query[0][1]), 'transfer_cell1_value': self.transfer_cell1_value, 'transfer_cell2_value': self.transfer_cell2_value, 'transfer_cell3_value': self.transfer_cell3_value, 'transfer_cell4_value': self.transfer_cell4_value, 'transfer_cell5_value': self.transfer_cell5_value, 'transfer_cell6_value': self.transfer_cell6_value, 'transfer_cell7_value': self.transfer_cell7_value, 'transfer_cell8_value': self.transfer_cell8_value, 'transfer_cell9_value': self.transfer_cell9_value, 'transfer_cell10_value': self.transfer_cell10_value, 'transfer_cell11_value': self.transfer_cell11_value, } class Cell13_Forced(Page): template_name = 'SI_Exp2_TestPhase/Cell13_Forced.html' form_model = 'player' form_fields = ['transfer_cell13_index', 'transfer_cell13_value'] def vars_for_template(self): grid_numbers = np.empty((11, 11)) grid_data = [] for row_idx, row in enumerate(grid_numbers): grid_row = [] for col_idx, value in enumerate(row): cell = {'value_cell1': self.transfer_cell1_value, 'value_cell2': self.transfer_cell2_value, 'value_cell3': self.transfer_cell3_value, 'value_cell4': self.transfer_cell4_value, 'value_cell5': self.transfer_cell5_value, 'value_cell6': self.transfer_cell6_value, 'value_cell7': self.transfer_cell7_value, 'value_cell8': self.transfer_cell8_value, 'value_cell9': self.transfer_cell9_value, 'value_cell10': self.transfer_cell10_value, 'value_cell11': self.transfer_cell11_value, 'value_cell12': self.transfer_cell12_value, 'row_index': row_idx, 'column_index': col_idx} grid_row.append(cell) grid_data.append(grid_row) highlight_index_row_cell1, highlight_index_column_cell1= string_to_integer(self.transfer_cell1_index) highlight_index_row_cell2, highlight_index_column_cell2= string_to_integer(self.transfer_cell2_index) highlight_index_row_cell3, highlight_index_column_cell3= string_to_integer(self.transfer_cell3_index) highlight_index_row_cell4, highlight_index_column_cell4= string_to_integer(self.transfer_cell4_index) highlight_index_row_cell5, highlight_index_column_cell5= string_to_integer(self.transfer_cell5_index) highlight_index_row_cell6, highlight_index_column_cell6= string_to_integer(self.transfer_cell6_index) highlight_index_row_cell7, highlight_index_column_cell7= string_to_integer(self.transfer_cell7_index) highlight_index_row_cell8, highlight_index_column_cell8= string_to_integer(self.transfer_cell8_index) highlight_index_row_cell9, highlight_index_column_cell9= string_to_integer(self.transfer_cell9_index) highlight_index_row_cell10, highlight_index_column_cell10= string_to_integer(self.transfer_cell10_index) highlight_index_row_cell11, highlight_index_column_cell11= string_to_integer(self.transfer_cell11_index) highlight_index_row_cell12, highlight_index_column_cell12= string_to_integer(self.transfer_cell12_index) already_selected_cells = [[highlight_index_row_cell1,highlight_index_column_cell1], [highlight_index_row_cell2,highlight_index_column_cell2]] forced_choice_query = [] flat_list = np.arange(121) array_2d = np.reshape(flat_list, (11, 11)) forced_choice_1_flat_index_0 = self.participant.vars['forced_choice_10'][0] forced_choice_1_flat_index_1 = self.participant.vars['forced_choice_10'][1] forced_choice_1_flat_index_2 = self.participant.vars['forced_choice_10'][2] row_index_0, column_index_0 = np.where(array_2d == forced_choice_1_flat_index_0) row_index_1, column_index_1 = np.where(array_2d == forced_choice_1_flat_index_1) row_index_2, column_index_2 = np.where(array_2d == forced_choice_1_flat_index_2) if [row_index_0, column_index_0] not in already_selected_cells: forced_choice_query.append([row_index_0, column_index_0]) elif [row_index_1, column_index_1] not in already_selected_cells: forced_choice_query.append([row_index_1, column_index_1]) elif [row_index_2, column_index_2] not in already_selected_cells: forced_choice_query.append([row_index_2, column_index_2]) return { 'grid_data': grid_data, 'highlight_index_row_cell1': int(highlight_index_row_cell1), 'highlight_index_column_cell1': int(highlight_index_column_cell1), 'highlight_index_row_cell2': int(highlight_index_row_cell2), 'highlight_index_column_cell2': int(highlight_index_column_cell2), 'highlight_index_row_cell3': highlight_index_row_cell3, 'highlight_index_column_cell3': highlight_index_column_cell3, 'highlight_index_row_cell4': highlight_index_row_cell4, 'highlight_index_column_cell4': highlight_index_column_cell4, 'highlight_index_row_cell5': highlight_index_row_cell5, 'highlight_index_column_cell5': highlight_index_column_cell5, 'highlight_index_row_cell6': highlight_index_row_cell6, 'highlight_index_column_cell6': highlight_index_column_cell6, 'highlight_index_row_cell7': highlight_index_row_cell7, 'highlight_index_column_cell7': highlight_index_column_cell7, 'highlight_index_row_cell8': highlight_index_row_cell8, 'highlight_index_column_cell8': highlight_index_column_cell8, 'highlight_index_row_cell9': highlight_index_row_cell9, 'highlight_index_column_cell9': highlight_index_column_cell9, 'highlight_index_row_cell10': highlight_index_row_cell10, 'highlight_index_column_cell10': highlight_index_column_cell10, 'highlight_index_row_cell11': highlight_index_row_cell11, 'highlight_index_column_cell11': highlight_index_column_cell11, 'highlight_index_row_cell12': highlight_index_row_cell12, 'highlight_index_column_cell12': highlight_index_column_cell12, 'highlight_index_row_cell13': int(forced_choice_query[0][0]), 'highlight_index_column_cell13': int(forced_choice_query[0][1]), 'transfer_cell1_value': self.transfer_cell1_value, 'transfer_cell2_value': self.transfer_cell2_value, 'transfer_cell3_value': self.transfer_cell3_value, 'transfer_cell4_value': self.transfer_cell4_value, 'transfer_cell5_value': self.transfer_cell5_value, 'transfer_cell6_value': self.transfer_cell6_value, 'transfer_cell7_value': self.transfer_cell7_value, 'transfer_cell8_value': self.transfer_cell8_value, 'transfer_cell9_value': self.transfer_cell9_value, 'transfer_cell10_value': self.transfer_cell10_value, 'transfer_cell11_value': self.transfer_cell11_value, 'transfer_cell12_value': self.transfer_cell12_value, } # CUSTOM FUNCTION------------------------------------------------------------------------------------------------------- def string_to_integer(str): str = str.split(",") str = [eval(i) for i in str] highlight_index_row_cell = str[0] highlight_index_column_cell = str[1] return highlight_index_row_cell, highlight_index_column_cell def calcs_for_part3(player: Player): current_script_directory = os.path.dirname(os.path.abspath(__file__)) #print('current_script_directory', current_script_directory) parent_directory = os.path.dirname(current_script_directory) #print('parent_directory', parent_directory) file_name = 'SI_DemonstratorPlaceholder_' + str(int(player.participant.label)) + '.csv' file_path = os.path.join(parent_directory + '/SI_Exp2/', file_name) print('file_path', file_path) demonstrator = read_csv(file_path, Player) #demonstrator = read_csv(__name__ + '/SI_DemonstratorPlaceholder_' + str(int(player.participant.label)) + '.csv', Player) # print('demonstrator', demonstrator, type(demonstrator)) all_rewards = [] for r in range(0, 40): # print('round', r) this_trials_demonstrator_data = demonstrator[r] this_trials_demonstrator_rewards_string = this_trials_demonstrator_data['demonstrator_rewards'].replace("[","").replace( "]", "") # delete the brackets. need to ensure can re-create matrix list structure later this_trials_demonstrator_rewards_list = [int(ele) for ele in this_trials_demonstrator_rewards_string.split()] # this_trials_demonstrator_rewards_list = np.array(res) # print('demonstrator_rewards_matrix', this_trials_demonstrator_rewards_list, type(this_trials_demonstrator_rewards_list)) # all_rewards = np.concatenate((all_rewards, this_trials_demonstrator_rewards_list), axis=1) # demonstrator_rewards_matrix = np.reshape(demonstrator_rewards_matrix, (11,11)) all_rewards.append(this_trials_demonstrator_rewards_list) # now I know the x smallest rewards, on average. # maybe it's enough to determine which cells to ask for an expected reward based on how small they are # e.g., given the smallest and the second smallest and then the 9th smallest shouldn't be directly next to the lowest cell but who knows... # or just the three smallest plus a random selection of 7 that haven't been selected already # I hope this is the right "format", i.e. every index in sublist is one column. should check manually df = pd.DataFrame(all_rewards) df_mean_list = list(df.mean()) print('df_mean_list', df_mean_list) sml = np.argsort(df_mean_list)[:3] # get the three smallest rewards, on average sml_index = str(list(sml)) # now I have the indicies for the smallest three rewards, on average # how do I now get the respective index for the matrix structure? # just transform into numpy matrix in the usual way? and then sml_matrix = np.reshape(df_mean_list, (11, 11)) idx = np.argsort(sml_matrix, axis=None) # give me the indices of the three smallest values # print('idx', idx) idx_matrix = np.reshape(idx, (11, 11)) # print('idx_matrix', idx_matrix) smallest_index = np.where(idx_matrix == 0) sec_smallest_index = np.where(idx_matrix == 1) third_smallest_index = np.where(idx_matrix == 2) # print('smallest_index', smallest_index, smallest_index[0][0], smallest_index[1][0], type(smallest_index[0][0]), type(int(smallest_index[0][0]))) return (smallest_index[0][0], smallest_index[1][0], sec_smallest_index[0][0], sec_smallest_index[1][0], third_smallest_index[0][0], third_smallest_index[1][0]) # EXECUTE--------------------------------------------------------------------------------------------------------------- page_sequence = [TransferInstructions, Cell1_Highest_Free, Cell2_Lowest_Free, Cell3_Forced, Cell4_Forced, Cell5_Forced, Cell6_Forced, Cell7_Forced, Cell8_Forced, Cell9_Forced, Cell10_Forced, Cell11_Forced, Cell12_Forced, Cell13_Forced, Last] #, Cell12_Forced2 # TO DOs --------------------------------------------------------------------------------------------------------------- # Show grey area around highest/lowest cell? # Find a solution for calculating, displaying and paying the reward # Debriefing # what exact questions do get asked? # Approach: ask about lowest cells that have not been selected so far # need to identify lowest reward on average (probably in separate py file? but no long-term solution as I would need to do that for every participant? check how many kernels I have...) # identify cells with smallest reward from demonstrator_model. but I probably not only want lowest reward... # check whether participant already selected them for highest reward (should highest reward stay on screen? I guess so, would be easiest. so if already selected skip or ) # highlight those cells # aks about those cells # keep them on screen as the highest ones? #