# -*- coding: utf-8 -*- """ Created on Mon Dec 5 18:29:27 2022 @author: janmo """ import pandas as pd from random import shuffle import pickle import random Lotterries_A = pd.read_csv("lotteries_classA.csv") Lotterries_B = pd.read_csv("lotteries_classB_170.csv") print(Lotterries_B.iloc[:, 3]) def create_lottery(p1, v1, v2): parameter_list = [p1, v1, v2] expected_value = p1 * v1 + (1 - p1) * v2 if (v1 != 1) and (v2 != 1): lottery = f"With a probability of {p1 * 100}% you will receive {v1} points.
With a probability of {(1 - p1) * 100}% you will receive {v2} points." elif (v1 == 1) and (v2 != 1): lottery = f"With a probability of {p1 * 100}% you will receive {v1} points.
With a probability of {(1 - p1) * 100}% you will receive {v2} points." elif (v1 != 1) and (v2 == 1): lottery = f"With a probability of {p1 * 100}% you will receive {v1} points.
With a probability of {(1 - p1) * 100}% you will receive {v2} points." return lottery lottery_A_list = [] for i in range(len(Lotterries_A)): p = Lotterries_A.iloc[i, 1] value1 = int(Lotterries_A.iloc[i, 2])/10 value2 = int(Lotterries_A.iloc[i, 3])/10 exp_value = Lotterries_A.iloc[i, 4]/10 #var = Lotterries_A.iloc[i, 5] representative = Lotterries_A.iloc[i, 6] lottery_A_dict = dict(ID=i, prob = p, value1 = value1, value2 = value2, text = create_lottery(p, value1, value2), exp_value = exp_value, #var = var, representative = representative, risk_level = None, dominance_class = "A", #roman_index = None ) lottery_A_list.append(lottery_A_dict) lottery_A_list[0]['risk_level'] = 0 #lottery_A_list[0]['roman_index'] = "I" lottery_A_list[2]['risk_level'] = 1 #lottery_A_list[2]['roman_index'] = "II" lottery_A_list[4]['risk_level'] = 2 #lottery_A_list[4]['roman_index'] = "III" lottery_A_list[6]['risk_level'] = 3 #lottery_A_list[6]['roman_index'] = "IV" lottery_A_list[9]['risk_level'] = 4 #lottery_A_list[9]['roman_index'] = "V" lottery_A_list[11]['risk_level'] = 5 #lottery_A_list[11]['roman_index'] = "VI" lottery_A_list[15]['risk_level'] = 6 #lottery_A_list[15]['roman_index'] = "VII" lottery_A_list[18]['risk_level'] = 7 #lottery_A_list[18]['roman_index'] = "VIII" lottery_A_list[22]['risk_level'] = 8 #lottery_A_list[22]['roman_index'] = "IX" lottery_A_list[25]['risk_level'] = 9 #lottery_A_list[25]['roman_index'] = "X" lottery_A_list[27]['risk_level'] = 10 #lottery_A_list[27]['roman_index'] = "XI" # ... lottery_B_list = [] for i in range(len(Lotterries_B)): p = Lotterries_B.iloc[i, 1] value1 = int(Lotterries_B.iloc[i, 2])/10 value2 = int(Lotterries_B.iloc[i, 3])/10 exp_value = Lotterries_B.iloc[i, 4] #var = Lotterries_B.iloc[i, 5] lottery_B_dict = dict(ID=i, prob = p, value1 = value1, value2 = value2, text = create_lottery(p, value1, value2), exp_value = exp_value, #var = var, dominance_class = "B", risk_level = None, representative=None, #roman_index = None ) lottery_B_list.append(lottery_B_dict) lottery_AB_list = (lottery_A_list + lottery_B_list).copy() print(lottery_AB_list[:50]) #shuffle(lottery_AB_list) #for i in range(len(lottery_AB_list)): # lottery_AB_list[i]['ID_shuffled'] = i """ # Save the lotteries filenameA = 'C:/Users/janmo/OneDrive/Dokumente/Goethe Uni/Doktor/Projekte/Decentralized Feature Selection 1/Otree/lotteries_risk_game_en_within_subjects_v4/lotteries_A_smaller_values_en.sav' filenameB = 'C:/Users/janmo/OneDrive/Dokumente/Goethe Uni/Doktor/Projekte/Decentralized Feature Selection 1/Otree/lotteries_risk_game_en_within_subjects_v4/lotteries_B_smaller_values_en.sav' filenameAB = 'C:/Users/janmo/OneDrive/Dokumente/Goethe Uni/Doktor/Projekte/Decentralized Feature Selection 1/Otree/lotteries_risk_game_en_within_subjects_v4/lotteries_AB_smaller_values_en.sav' pickle.dump(lottery_A_list, open(filenameA, 'wb')) pickle.dump(lottery_B_list, open(filenameB, 'wb')) pickle.dump(lottery_AB_list, open(filenameAB, 'wb')) """ """ ### Lottery Personalization personalised_lotteries = [] for lottery in lottery_A_list: if lottery['risk_level'] == 7: ID_found = lottery['ID'] if ID_found == 0: ID_presented = [0,1,2,3,4] elif ID_found == 1: ID_presented = [0,1,2,3,4] else: ID_presented = [ID_found-2, ID_found-1, ID_found, ID_found+1, ID_found+2] for lottery in lottery_A_list: if lottery['ID'] in ID_presented: personalised_lotteries.append(lottery) """ ### ------- ### ### ------- ### ### ------- ### ### ------- ### def create_lottery_masked(p1, v1, v2): parameter_list = [p1, v1, v2] expected_value = p1 * v1 + (1 - p1) * v2 if (v1 != 1) and (v2 != 1): lottery = f"With a probability of {p1 * 100}% you will receive xxx points.
With a probability of {(1 - p1) * 100}% you will receive yyy points." elif (v1 == 1) and (v2 != 1): lottery = f"With a probability of {p1 * 100}% you will receive xxx points.
With a probability of {(1 - p1) * 100}% you will receive yyy points." elif (v1 != 1) and (v2 == 1): lottery = f"With a probability of {p1 * 100}% you will receive xxx points.
With a probability of {(1 - p1) * 100}% you will receive yyy points." return lottery lottery_A_list_masked = [] for i in range(len(Lotterries_A)): p = Lotterries_A.iloc[i, 1] lottery_A_dict = dict(ID=i, prob = p, text = create_lottery_masked(p, value1, value2), ) lottery_A_list_masked.append(lottery_A_dict) lottery_B_list_masked = [] for i in range(len(Lotterries_B)): p = Lotterries_B.iloc[i, 1] lottery_B_dict = dict(ID=i, prob = p, text = create_lottery_masked(p, value1, value2), ) lottery_B_list_masked.append(lottery_B_dict) lottery_AB_masked_list = (lottery_A_list_masked + lottery_B_list_masked).copy() #shuffle(lottery_AB_masked_list) #for i in range(len(lottery_AB_masked_list)): # lottery_AB_masked_list[i]['ID_shuffled'] = i #filenameAB_masked = 'C:/Users/janmo/OneDrive/Dokumente/Goethe Uni/Doktor/Projekte/Decentralized Feature Selection 1/Otree/lotteries_risk_game_en/lotteries_AB_masked_en.sav' #pickle.dump(lottery_AB_masked_list, open(filenameAB_masked, 'wb'))