jchoo commited on
Commit
3b79d2a
·
verified ·
1 Parent(s): 3f51e80

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +724 -724
app.py CHANGED
@@ -11,688 +11,688 @@ from matplotlib.colors import ListedColormap
11
  import panel as pn
12
  import altair as alt
13
 
14
- # def choices_to_df(choices, hue):
15
- # df = pd.DataFrame(choices, columns=['choices'])
16
- # df['hue'] = hue
17
- # df['hue'] = df['hue'].astype(str)
18
- # return df
19
-
20
- # binrange = (0, 100)
21
- # moves = []
22
- # with open('dictator.csv', 'r') as f:
23
- # reader = csv.reader(f)
24
- # header = next(reader)
25
- # col2idx = {col: idx for idx, col in enumerate(header)}
26
- # for row in reader:
27
- # record = {col: row[idx] for col, idx in col2idx.items()}
28
-
29
- # if record['Role'] != 'first': continue
30
- # if int(record['Round']) > 1: continue
31
- # if int(record['Total']) != 100: continue
32
- # if record['move'] == 'None': continue
33
- # if record['gameType'] != 'dictator': continue
34
-
35
- # move = float(record['move'])
36
- # if move < binrange[0] or \
37
- # move > binrange[1]: continue
38
 
39
- # moves.append(move)
40
-
41
- # df_dictator_human = choices_to_df(moves, 'Human')
42
-
43
- # choices = [50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0]
44
- # df_dictator_gpt4 = choices_to_df(choices, hue=str('ChatGPT-4'))
45
-
46
- # choices = [25, 35, 70, 30, 20, 25, 40, 80, 30, 30, 40, 30, 30, 30, 30, 30, 40, 40, 30, 30, 40, 30, 60, 20, 40, 25, 30, 30, 30]
47
- # df_dictator_turbo = choices_to_df(choices, hue=str('ChatGPT-3'))
48
-
49
- # def extract_choices(recrods):
50
- # choices = [extract_amout(
51
- # messages[-1]['content'],
52
- # prefix='$',
53
- # print_except=True,
54
- # type=float) for messages in records['messages']
55
- # ]
56
- # choices = [x for x in choices if x is not None]
57
- # # print(choices)
58
- # return choices
59
-
60
- # def extract_amout(
61
- # message,
62
- # prefix='',
63
- # print_except=True,
64
- # type=float,
65
- # brackets='[]'
66
- # ):
67
- # try:
68
- # matches = extract_brackets(message, brackets=brackets)
69
- # matches = [s[len(prefix):] \
70
- # if s.startswith(prefix) \
71
- # else s for s in matches]
72
- # invalid = False
73
- # if len(matches) == 0:
74
- # invalid = True
75
- # for i in range(len(matches)):
76
- # if matches[i] != matches[0]:
77
- # invalid = True
78
- # if invalid:
79
- # raise ValueError('Invalid answer: %s' % message)
80
- # return type(matches[0])
81
- # except Exception as e:
82
- # if print_except: print(e)
83
- # return None
84
-
85
- # records = json.load(open('dictator_wo_ex_2023_03_13-11_24_07_PM.json', 'r'))
86
- # choices = extract_choices(records)
87
-
88
- # # Plot 1 - Dictator (altruism)
89
- # def plot_facet(
90
- # df_list,
91
- # x='choices',
92
- # hue='hue',
93
- # palette=None,
94
- # binrange=None,
95
- # bins=10,
96
- # # binwidth=10,
97
- # stat='count',
98
- # x_label='',
99
- # sharex=True,
100
- # sharey=False,
101
- # subplot=sns.histplot,
102
- # xticks_locs=None,
103
- # # kde=False,
104
- # **kwargs
105
- # ):
106
- # data = pd.concat(df_list)
107
- # if binrange is None:
108
- # binrange = (data[x].min(), data[x].max())
109
- # g = sns.FacetGrid(
110
- # data, row=hue, hue=hue,
111
- # palette=palette,
112
- # aspect=2, height=2,
113
- # sharex=sharex, sharey=sharey,
114
- # despine=True,
115
- # )
116
- # g.map_dataframe(
117
- # subplot,
118
- # x=x,
119
- # # kde=kde,
120
- # binrange=binrange,
121
- # bins=bins,
122
- # stat=stat,
123
- # **kwargs
124
- # )
125
- # # g.add_legend(title='hue')
126
- # g.set_axis_labels(x_label, stat.title())
127
- # g.set_titles(row_template="{row_name}")
128
- # for ax in g.axes.flat:
129
- # ax.yaxis.set_major_formatter(
130
- # FuncFormatter(lambda y, pos: '{:.2f}'.format(y))
131
- # )
132
 
133
- # binwidth = (binrange[1] - binrange[0]) / bins
134
- # if xticks_locs is None:
135
- # locs = np.linspace(binrange[0], binrange[1], bins//2+1)
136
- # locs = [loc + binwidth for loc in locs]
137
- # else:
138
- # locs = xticks_locs
139
- # labels = [str(int(loc)) for loc in locs]
140
- # locs = [loc + 0.5*binwidth for loc in locs]
141
- # plt.xticks(locs, labels)
142
 
143
- # g.set(xlim=binrange)
144
- # return g
145
-
146
- # df = df_dictator_human
147
- # bin_ranges = [0, 10, 30, 50, 70]
148
-
149
- # # Calculate density as a percentage
150
- # density_percentage = df['choices'].value_counts(normalize=True)
151
-
152
- # # Create a DataFrame with the density percentages
153
- # density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
154
-
155
- # # Create the bar chart using Altair
156
- # chart1 = alt.Chart(density_df).mark_bar().encode(
157
- # x=alt.X('choices:O', bin=alt.Bin(extent=[0, 70], step=10), axis=None),
158
- # y='density:Q',
159
- # color=alt.value('steelblue'),
160
- # tooltip=['density']
161
- # ).properties(
162
- # width=500,
163
- # title='Density of Choices'
164
- # ).interactive()
165
 
166
- # df = df_dictator_gpt4
167
- # bin_ranges = [0, 10, 30, 50, 70]
168
 
169
- # # Calculate density as a percentage
170
- # density_percentage = df['choices'].value_counts(normalize=True)
171
 
172
- # # Create a DataFrame with the density percentages
173
- # density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
174
 
175
- # # Create the bar chart using Altair
176
- # chart2 = alt.Chart(density_df).mark_bar().encode(
177
- # x=alt.X('choices:O', bin=alt.Bin(extent=[0, 70], step=10), axis=None),
178
- # y='density:Q',
179
- # color=alt.value('orange'),
180
- # tooltip=['density']
181
- # ).properties(
182
- # width=500,
183
- # title='Density of Choices'
184
- # ).interactive()
185
 
186
- # df = df_dictator_turbo
187
-
188
- # bin_ranges = [0, 10, 30, 50, 70]
189
 
190
- # # Calculate density as a percentage
191
- # density_percentage = df['choices'].value_counts(normalize=True)
192
 
193
- # # Create a DataFrame with the density percentages
194
- # density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
195
-
196
- # # Create the bar chart using Altair
197
- # chart3 = alt.Chart(density_df).mark_bar().encode(
198
- # x=alt.X('choices:O', bin=alt.Bin(extent=[0, 70], step=10)),
199
- # y='density:Q',
200
- # color=alt.value('green'),
201
- # tooltip=['density']
202
- # ).properties(
203
- # width=500,
204
- # title='Density of Choices'
205
- # ).interactive()
206
-
207
- # final = alt.vconcat(chart1, chart2, chart3).resolve_scale(x='shared')
208
-
209
- # #Plot 2 - - Ultimatum (Fairness)
210
- # df = pd.read_csv('ultimatum_strategy.csv')
211
- # df = df[df['gameType'] == 'ultimatum_strategy']
212
- # df = df[df['Role'] == 'player']
213
- # df = df[df['Round'] == 1]
214
- # df = df[df['Total'] == 100]
215
- # df = df[df['move'] != 'None']
216
- # df['propose'] = df['move'].apply(lambda x: eval(x)[0])
217
- # df['accept'] = df['move'].apply(lambda x: eval(x)[1])
218
- # df = df[(df['propose'] >= 0) & (df['propose'] <= 100)]
219
- # df = df[(df['accept'] >= 0) & (df['accept'] <= 100)]
220
-
221
- # df_ultimatum_1_human = choices_to_df(list(df['propose']), 'Human')
222
- # df_ultimatum_2_human = choices_to_df(list(df['accept']), 'Human')
223
-
224
- # choices = [50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0]
225
- # df_ultimatum_1_gpt4 = choices_to_df(choices, hue=str('ChatGPT-4'))
226
-
227
- # choices = [40, 40, 40, 30, 70, 70, 50, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 30, 30, 35, 50, 40, 70, 40, 60, 60, 70, 40, 50]
228
- # df_ultimatum_1_turbo = choices_to_df(choices, hue=str('ChatGPT-3'))
229
-
230
- # choices = [50.0, 50.0, 50.0, 1.0, 1.0, 1.0, 50.0, 25.0, 50.0, 1.0, 1.0, 20.0, 50.0, 50.0, 50.0, 20.0, 50.0, 1.0, 1.0, 1.0, 50.0, 50.0, 50.0, 1.0, 1.0, 1.0, 20.0, 1.0] + [0, 1]
231
- # df_ultimatum_2_gpt4 = choices_to_df(choices, hue=str('ChatGPT-4'))
232
-
233
- # choices = [None, 50, 50, 50, 50, 30, None, None, 30, 33.33, 40, None, 50, 40, None, 1, 30, None, 10, 50, 30, 10, 30, None, 30, None, 10, 30, 30, 30]
234
- # df_ultimatum_2_turbo = choices_to_df(choices, hue=str('ChatGPT-3'))
235
-
236
- # choices = [50.0, 50.0, 10.0, 40.0, 20.0, 50.0, 1.0, 1.0, 50.0, 1.0, 50.0, 50.0, 20.0, 10.0, 50.0, 20.0, 1.0, 1.0, 50.0, 1.0, 20.0, 1.0, 50.0, 50.0, 20.0, 20.0, 50.0, 20.0, 1.0, 50.0]
237
- # df_ultimatum_2_gpt4_female = choices_to_df(choices, hue='ChatGPT-4 Female')
238
-
239
- # choices = [1.0, 1.0, 1.0, 20.0, 1.0, 1.0, 50.0, 1.0, 1.0, 50.0, 50.0, 50.0, 20.0, 20.0, 1.0, 50.0, 1.0, 1.0, 1.0, 50.0, 20.0, 1.0, 50.0, 20.0, 20.0, 10.0, 50.0, 1.0, 1.0, 1.0]
240
- # df_ultimatum_2_gpt4_male = choices_to_df(choices, hue='ChatGPT-4 Male')
241
-
242
- # choices = [40.0, 1.0, 1.0, 20.0, 1.0, 20.0, 50.0, 50.0, 1.0, 1.0, 1.0, 50.0, 1.0, 20.0, 50.0, 10.0, 50.0, 1.0, 1.0, 20.0, 1.0, 50.0, 20.0, 20.0, 20.0, 1.0, 1.0, 1.0, 1.0, 40.0]
243
- # df_ultimatum_2_gpt4_US = choices_to_df(choices, hue='ChatGPT-4 US')
244
-
245
- # choices = [1.0, 1.0, 20.0, 50.0, 1.0, 1.0, 1.0, 1.0, 20.0, 20.0, 50.0, 20.0, 20.0, 50.0, 20.0, 1.0, 40.0, 50.0, 1.0, 1.0, 1.0, 20.0, 1.0, 1.0, 50.0, 50.0, 1.0, 1.0, 1.0, 1.0]
246
- # df_ultimatum_2_gpt4_Poland = choices_to_df(choices, hue='ChatGPT-4 Poland')
247
-
248
- # choices = [50.0, 1.0, 20.0, 50.0, 50.0, 50.0, 50.0, 1.0, 1.0, 50.0, 1.0, 50.0, 1.0, 50.0, 1.0, 20.0, 1.0, 1.0, 20.0, 50.0, 0.0, 20.0, 1.0, 1.0, 1.0, 1.0, 20.0, 20.0, 50.0, 20.0]
249
- # df_ultimatum_2_gpt4_China = choices_to_df(choices, hue='ChatGPT-4 China')
250
-
251
- # choices = [1.0, 1.0, 1.0, 50.0, 1.0, 1.0, 50.0, 40.0, 1.0, 1.0, 1.0, 1.0, 20.0, 1.0, 1.0, 50.0, 1.0, 50.0, 1.0, 20.0, 1.0, 20.0, 1.0, 50.0, 1.0, 50.0, 20.0, 1.0, 1.0, 50.0]
252
- # df_ultimatum_2_gpt4_UK = choices_to_df(choices, hue='ChatGPT-4 UK')
253
-
254
- # choices = [50.0, 1.0, 20.0, 50.0, 50.0, 50.0, 50.0, 10.0, 1.0, 40.0, 50.0, 20.0, 1.0, 1.0, 1.0, 50.0, 50.0, 20.0, 20.0, 1.0, 1.0, 50.0, 20.0, 50.0, 50.0, 20.0, 1.0, 20.0, 50.0, 1]
255
- # df_ultimatum_2_gpt4_Columbia = choices_to_df(choices, hue='ChatGPT-4 Columbia')
256
-
257
- # choices = [50.0, 1.0, 50.0, 20.0, 20.0, 20.0, 50.0, 20.0, 20.0, 1.0, 1.0, 1.0, 1.0, 20.0, 1.0, 50.0, 1.0, 20.0, 20.0, 50.0, 1.0, 50.0, 1.0, 40.0, 1.0, 20.0, 1.0, 20.0, 1.0, 1.0]
258
- # df_ultimatum_2_gpt4_under = choices_to_df(choices, hue='ChatGPT-4 Undergrad')
259
-
260
- # choices = [1.0, 20.0, 1.0, 40.0, 50.0, 1.0, 1.0, 1.0, 25.0, 20.0, 50.0, 20.0, 50.0, 50.0, 1.0, 50.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 50.0, 20.0, 1.0, 1.0, 1.0, 50.0, 20.0, 20.0]
261
- # df_ultimatum_2_gpt4_grad = choices_to_df(choices, hue='ChatGPT-4 Graduate')
262
-
263
- # df = df_ultimatum_1_human
264
- # bin_ranges = [0, 10, 30, 50, 70]
265
-
266
- # # Calculate density as a percentage
267
- # density_percentage = df['choices'].value_counts(normalize=True)
268
-
269
- # # Create a DataFrame with the density percentages
270
- # density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
271
-
272
- # # Create the bar chart using Altair
273
- # chart1 = alt.Chart(density_df).mark_bar().encode(
274
- # x=alt.X('choices:O', bin=alt.Bin(extent=[0, 70], step=10), axis=None),
275
- # y='density:Q',
276
- # color=alt.value('steelblue'),
277
- # tooltip=['density']
278
- # ).properties(
279
- # width=500,
280
- # title='Density of Choices'
281
- # ).interactive()
282
-
283
- # df = df_ultimatum_1_gpt4
284
- # bin_ranges = [0, 10, 30, 50, 70]
285
-
286
- # # Calculate density as a percentage
287
- # density_percentage = df['choices'].value_counts(normalize=True)
288
-
289
- # # Create a DataFrame with the density percentages
290
- # density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
291
-
292
- # # Create the bar chart using Altair
293
- # chart2 = alt.Chart(density_df).mark_bar().encode(
294
- # x=alt.X('choices:O', bin=alt.Bin(extent=[0, 70], step=10), axis=None),
295
- # y='density:Q',
296
- # color=alt.value('orange'),
297
- # tooltip=['density']
298
- # ).properties(
299
- # width=500,
300
- # title='Density of Choices'
301
- # ).interactive()
302
-
303
- # df = df_ultimatum_1_turbo
304
- # bin_ranges = [0, 10, 30, 50, 70]
305
-
306
- # # Calculate density as a percentage
307
- # density_percentage = df['choices'].value_counts(normalize=True)
308
-
309
- # # Create a DataFrame with the density percentages
310
- # density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
311
-
312
- # # Create the bar chart using Altair
313
- # chart3 = alt.Chart(density_df).mark_bar().encode(
314
- # x=alt.X('choices:O', bin=alt.Bin(extent=[0, 70], step=10)),
315
- # y='density:Q',
316
- # color=alt.value('green'),
317
- # tooltip=['density']
318
- # ).properties(
319
- # width=500,
320
- # title='Density of Choices'
321
- # ).interactive()
322
-
323
- # final2 = alt.vconcat(chart1, chart2, chart3).resolve_scale(x='shared')
324
-
325
- # #Plot 3 - - Ultimatum (Responder) (spite)
326
- # df = df_ultimatum_2_human
327
- # bin_ranges = [0, 10, 30, 50, 70]
328
-
329
- # # Calculate density as a percentage
330
- # density_percentage = df['choices'].value_counts(normalize=True)
331
-
332
- # # Create a DataFrame with the density percentages
333
- # density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
334
-
335
- # # Create the bar chart using Altair
336
- # chart1 = alt.Chart(density_df).mark_bar().encode(
337
- # x=alt.X('choices:O', bin=alt.Bin(extent=[0, 70], step=10), axis=None),
338
- # y='density:Q',
339
- # color=alt.value('steelblue'),
340
- # tooltip=['density']
341
- # ).properties(
342
- # width=500,
343
- # title='Density of Choices'
344
- # ).interactive()
345
-
346
- # df = df_ultimatum_2_gpt4
347
- # bin_ranges = [0, 10, 30, 50, 70]
348
-
349
- # # Calculate density as a percentage
350
- # density_percentage = df['choices'].value_counts(normalize=True)
351
-
352
- # # Create a DataFrame with the density percentages
353
- # density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
354
-
355
- # # Create the bar chart using Altair
356
- # chart2 = alt.Chart(density_df).mark_bar().encode(
357
- # x=alt.X('choices:O', bin=alt.Bin(extent=[0, 70], step=10), axis=None),
358
- # y='density:Q',
359
- # color=alt.value('orange'),
360
- # tooltip=['density']
361
- # ).properties(
362
- # width=500,
363
- # title='Density of Choices'
364
- # ).interactive()
365
-
366
- # df = df_ultimatum_2_turbo
367
- # bin_ranges = [0, 10, 30, 50, 70]
368
-
369
- # # Calculate density as a percentage
370
- # density_percentage = df['choices'].value_counts(normalize=True)
371
-
372
- # # Create a DataFrame with the density percentages
373
- # density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
374
-
375
- # # Create the bar chart using Altair
376
- # chart3 = alt.Chart(density_df).mark_bar().encode(
377
- # x=alt.X('choices:O', bin=alt.Bin(extent=[0, 70], step=10), axis=None),
378
- # y='density:Q',
379
- # color=alt.value('green'),
380
- # tooltip=['density']
381
- # ).properties(
382
- # width=500,
383
- # title='Density of Choices'
384
- # ).interactive()
385
-
386
- # final3 = alt.vconcat(chart1, chart2, chart3).resolve_scale(x='shared')
387
-
388
- # #Plot 4 - - Trust (as Investor) (trust)
389
- # binrange = (0, 100)
390
- # moves_1 = []
391
- # moves_2 = defaultdict(list)
392
- # with open('trust_investment.csv', 'r') as f:
393
- # reader = csv.reader(f)
394
- # header = next(reader)
395
- # col2idx = {col: idx for idx, col in enumerate(header)}
396
- # for row in reader:
397
- # record = {col: row[idx] for col, idx in col2idx.items()}
398
-
399
- # # if record['Role'] != 'first': continue
400
- # if int(record['Round']) > 1: continue
401
- # # if int(record['Total']) != 100: continue
402
- # if record['move'] == 'None': continue
403
- # if record['gameType'] != 'trust_investment': continue
404
-
405
- # if record['Role'] == 'first':
406
- # move = float(record['move'])
407
- # if move < binrange[0] or \
408
- # move > binrange[1]: continue
409
- # moves_1.append(move)
410
- # elif record['Role'] == 'second':
411
- # inv, ret = eval(record['roundResult'])
412
- # if ret < 0 or \
413
- # ret > inv * 3: continue
414
- # moves_2[inv].append(ret)
415
- # else: continue
416
-
417
- # df_trust_1_human = choices_to_df(moves_1, 'Human')
418
- # df_trust_2_human = choices_to_df(moves_2[10], 'Human')
419
- # df_trust_3_human = choices_to_df(moves_2[50], 'Human')
420
- # df_trust_4_human = choices_to_df(moves_2[100], 'Human')
421
-
422
- # choices = [50.0, 50.0, 40.0, 30.0, 50.0, 50.0, 40.0, 50.0, 50.0, 50.0, 50.0, 50.0, 30.0, 30.0, 50.0, 50.0, 50.0, 40.0, 40.0, 50.0, 50.0, 50.0, 50.0, 40.0, 50.0, 50.0, 50.0, 50.0]
423
- # df_trust_1_gpt4 = choices_to_df(choices, hue=str('ChatGPT-4'))
424
-
425
- # choices = [50.0, 50.0, 30.0, 30.0, 30.0, 60.0, 50.0, 40.0, 20.0, 20.0, 50.0, 40.0, 30.0, 20.0, 30.0, 20.0, 30.0, 60.0, 50.0, 30.0, 50.0, 20.0, 20.0, 30.0, 50.0, 30.0, 30.0, 50.0, 40.0] + [30]
426
- # df_trust_1_turbo = choices_to_df(choices, hue=str('ChatGPT-3'))
427
-
428
- # choices = [20.0, 20.0, 20.0, 20.0, 15.0, 15.0, 15.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 15.0, 20.0, 20.0, 20.0, 20.0, 20.0, 15.0, 15.0, 20.0, 15.0, 15.0, 15.0, 15.0, 15.0, 20.0, 20.0, 15.0]
429
- # df_trust_2_gpt4 = choices_to_df(choices, hue=str('ChatGPT-4'))
430
-
431
- # choices = [20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 15.0, 25.0, 30.0, 30.0, 20.0, 25.0, 30.0, 20.0, 20.0, 18.0] + [20, 20, 20, 25, 25, 25, 30]
432
- # df_trust_2_turbo = choices_to_df(choices, hue=str('ChatGPT-3'))
433
-
434
- # choices = [100.0, 75.0, 75.0, 75.0, 75.0, 75.0, 100.0, 75.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 75.0, 100.0, 75.0, 75.0, 75.0, 100.0, 100.0, 100.0, 75.0, 100.0, 100.0, 100.0, 100.0, 75.0, 100.0, 75.0]
435
- # df_trust_3_gpt4 = choices_to_df(choices, hue=str('ChatGPT-4'))
436
-
437
- # choices = [150.0, 100.0, 150.0, 150.0, 50.0, 150.0, 100.0, 150.0, 100.0, 100.0, 100.0, 150.0] + [100, 100, 100, 100, 100, 100, 100, 100]
438
- # df_trust_3_turbo = choices_to_df(choices, hue=str('ChatGPT-3'))
439
-
440
- # choices = [200.0, 200.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 200.0, 200.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0]
441
- # df_trust_4_gpt4 = choices_to_df(choices, hue=str('ChatGPT-4'))
442
-
443
- # choices = [225.0, 225.0, 300.0, 300.0, 220.0, 300.0, 250.0] + [200, 200, 250, 200, 200]
444
- # df_trust_4_turbo = choices_to_df(choices, hue=str('ChatGPT-3'))
445
-
446
- # df = df_trust_1_human
447
-
448
- # bin_ranges = [0, 10, 30, 50, 70]
449
-
450
- # # Calculate density as a percentage
451
- # density_percentage = df['choices'].value_counts(normalize=True)
452
-
453
- # # Create a DataFrame with the density percentages
454
- # density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
455
-
456
- # # Create the bar chart using Altair
457
- # chart1 = alt.Chart(density_df).mark_bar().encode(
458
- # x=alt.X('choices:O', bin=alt.Bin(extent=[0, 70], step=10), axis=None),
459
- # y='density:Q',
460
- # color=alt.value('steelblue'),
461
- # tooltip=['density']
462
- # ).properties(
463
- # width=500,
464
- # title='Density of Choices'
465
- # ).interactive()
466
-
467
-
468
-
469
- # df = df_trust_1_gpt4
470
-
471
- # bin_ranges = [0, 10, 30, 50, 70]
472
-
473
- # # Calculate density as a percentage
474
- # density_percentage = df['choices'].value_counts(normalize=True)
475
-
476
- # # Create a DataFrame with the density percentages
477
- # density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
478
-
479
- # # Create the bar chart using Altair
480
- # chart2 = alt.Chart(density_df).mark_bar().encode(
481
- # x=alt.X('choices:O', bin=alt.Bin(extent=[0, 70], step=10), axis=None),
482
- # y='density:Q',
483
- # color=alt.value('orange'),
484
- # tooltip=['density']
485
- # ).properties(
486
- # width=500,
487
- # title='Density of Choices'
488
- # ).interactive()
489
-
490
-
491
- # df = df_trust_1_turbo
492
 
493
- # bin_ranges = [0, 10, 30, 50, 70]
494
 
495
- # # Calculate density as a percentage
496
- # density_percentage = df['choices'].value_counts(normalize=True)
497
 
498
- # # Create a DataFrame with the density percentages
499
- # density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
500
 
501
- # # Create the bar chart using Altair
502
- # chart3 = alt.Chart(density_df).mark_bar().encode(
503
- # x=alt.X('choices:O', bin=alt.Bin(extent=[0, 70], step=10), axis=None),
504
- # y='density:Q',
505
- # color=alt.value('green'),
506
- # tooltip=['density']
507
- # ).properties(
508
- # width=500,
509
- # title='Density of Choices'
510
- # ).interactive()
511
 
512
 
513
- # final4 = alt.vconcat(chart1, chart2, chart3).resolve_scale(x='shared')
514
-
515
- # #Plot 5 - Trust (as Banker) (fairness, altruism, reciprocity)
516
- # df = df_trust_3_human
517
-
518
- # bin_ranges = [0, 25, 50, 75, 100, 125, 150]
519
-
520
- # custom_ticks = [2, 6, 10, 14, 18]
521
-
522
- # # Calculate density as a percentage
523
- # density_percentage = df['choices'].value_counts(normalize=True)
524
-
525
- # # Create a DataFrame with the density percentages
526
- # density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
527
 
528
- # # Create the bar chart using Altair
529
- # chart1 = alt.Chart(density_df).mark_bar().encode(
530
- # x=alt.X('choices:O', bin=alt.Bin(step=10), axis=None),
531
- # y='density:Q',
532
- # color=alt.value('steelblue')
533
- # ).properties(
534
- # width=500,
535
- # title='Density of Choices'
536
- # ).interactive()
537
 
538
 
539
 
540
- # df = df_trust_3_gpt4
541
-
542
- # bin_ranges = [0, 25, 50, 75, 100, 125, 150]
543
-
544
- # # Calculate density as a percentage
545
- # density_percentage = df['choices'].value_counts(normalize=True)
546
 
547
- # # Create a DataFrame with the density percentages
548
- # density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
549
 
550
- # # Create the bar chart using Altair
551
- # chart2 = alt.Chart(density_df).mark_bar().encode(
552
- # x=alt.X('choices:O', bin=alt.Bin(step=10), axis=None),
553
- # y='density:Q',
554
- # color=alt.value('orange')
555
- # ).properties(
556
- # width=500,
557
- # title='Density of Choices'
558
- # ).interactive()
559
 
560
 
561
- # df = df_trust_3_turbo
562
 
563
- # bin_ranges = [0, 25, 50, 75, 100, 125, 150]
564
 
565
- # # Calculate density as a percentage
566
- # density_percentage = df['choices'].value_counts(normalize=True)
567
 
568
- # # Create a DataFrame with the density percentages
569
- # density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
570
 
571
- # # Create the bar chart using Altair
572
- # chart3 = alt.Chart(density_df).mark_bar().encode(
573
- # x=alt.X('choices:O', bin=alt.Bin(step=10)),
574
- # y='density:Q',
575
- # color=alt.value('green')
576
- # ).properties(
577
- # width=500,
578
- # title='Density of Choices'
579
- # ).interactive()
580
 
581
- # # chart1
582
- # final5 = alt.vconcat(chart1, chart2, chart3).resolve_scale(x='shared')
583
 
584
- # #Plot 6 - Public Goods (Free-Riding, altruism, cooperation)
585
- # df = pd.read_csv('public_goods_linear_water.csv')
586
- # df = df[df['Role'] == 'contributor']
587
- # df = df[df['Round'] <= 3]
588
- # df = df[df['Total'] == 20]
589
- # df = df[df['groupSize'] == 4]
590
- # df = df[df['move'] != None]
591
- # df = df[(df['move'] >= 0) & (df['move'] <= 20)]
592
- # df = df[df['gameType'] == 'public_goods_linear_water']
593
 
594
- # round_1 = df[df['Round'] == 1]['move']
595
- # round_2 = df[df['Round'] == 2]['move']
596
- # round_3 = df[df['Round'] == 3]['move']
597
- # print(len(round_1), len(round_2), len(round_3))
598
- # df_PG_human = pd.DataFrame({
599
- # 'choices': list(round_1)
600
- # })
601
- # df_PG_human['hue'] = 'Human'
602
- # # df_PG_human
603
 
604
- # file_names = [
605
- # 'PG_basic_turbo_2023_05_09-02_49_09_AM.json',
606
- # 'PG_basic_turbo_loss_2023_05_09-03_59_49_AM.json',
607
- # 'PG_basic_gpt4_2023_05_09-11_15_42_PM.json',
608
- # 'PG_basic_gpt4_loss_2023_05_09-10_44_38_PM.json',
609
- # ]
610
 
611
- # choices = []
612
- # for file_name in file_names:
613
- # with open(file_name, 'r') as f:
614
- # choices += json.load(f)['choices']
615
- # choices_baseline = choices
616
 
617
- # choices = [tuple(x)[0] for x in choices]
618
- # df_PG_turbo = choices_to_df(choices, hue=str('ChatGPT-3'))
619
- # # df_PG_turbo.head()
620
- # df_PG_gpt4 = choices_to_df(choices, hue=str('ChatGPT-4'))
621
- # # df_PG_gpt4.head()
622
-
623
- # df = df_PG_human
624
-
625
- # bin_ranges = [0, 25, 50, 75, 100, 125, 150]
626
-
627
- # custom_ticks = [2, 6, 10, 14, 18]
628
-
629
- # # Calculate density as a percentage
630
- # density_percentage = df['choices'].value_counts(normalize=True)
631
-
632
- # # Create a DataFrame with the density percentages
633
- # density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
634
-
635
- # # Create the bar chart using Altair
636
- # chart1 = alt.Chart(density_df).mark_bar().encode(
637
- # x=alt.X('choices:O', bin=alt.Bin(step=2), axis=None),
638
- # y='density:Q',
639
- # color=alt.value('steelblue'),
640
- # tooltip=['density']
641
- # ).properties(
642
- # width=500,
643
- # title='Density of Choices'
644
- # ).interactive()
645
-
646
-
647
-
648
- # df = df_PG_gpt4
649
-
650
- # bin_ranges = [0, 25, 50, 75, 100, 125, 150]
651
-
652
- # # Calculate density as a percentage
653
- # density_percentage = df['choices'].value_counts(normalize=True)
654
-
655
- # # Create a DataFrame with the density percentages
656
- # density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
657
-
658
- # # Create the bar chart using Altair
659
- # chart2 = alt.Chart(density_df).mark_bar().encode(
660
- # x=alt.X('choices:O', bin=alt.Bin(step=2), axis=None),
661
- # y='density:Q',
662
- # color=alt.value('orange'),
663
- # tooltip=['density']
664
- # ).properties(
665
- # width=500,
666
- # title='Density of Choices'
667
- # ).interactive()
668
-
669
-
670
- # df = df_PG_turbo
671
-
672
- # bin_ranges = [0, 25, 50, 75, 100, 125, 150]
673
-
674
- # # Calculate density as a percentage
675
- # density_percentage = df['choices'].value_counts(normalize=True)
676
-
677
- # # Create a DataFrame with the density percentages
678
- # density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
679
-
680
- # # Create the bar chart using Altair
681
- # chart3 = alt.Chart(density_df).mark_bar().encode(
682
- # x=alt.X('choices:O', bin=alt.Bin(step=2)),
683
- # y='density:Q',
684
- # color=alt.value('green'),
685
- # tooltip=['density']
686
- # ).properties(
687
- # width=500,
688
- # title='Density of Choices'
689
- # ).interactive()
690
 
691
- # # chart1
692
- # final6 = alt.vconcat(chart1, chart2, chart3).resolve_scale(x='shared')
693
 
694
- # #Final_Final
695
- # final_final = (final | final2 | final3 ) & (final4 | final5 | final6)
696
 
697
 
698
  # # we want to use bootstrap/template, tell Panel to load up what we need
@@ -753,73 +753,62 @@ options = ['Altruism', 'Fairness', 'spite', 'trust', 'reciprocity', 'free-riding
753
  select_widget = pn.widgets.Select(options=options, name='Select a category')
754
 
755
 
756
- # # Define function to update chart
757
- # def update_chart(value):
758
- # if value:
759
- # index = int(value.split()[-1]) - 1
760
- # return charts[index]
761
- # else:
762
- # return None
763
-
764
- # # Combine dropdown and chart
765
- # @pn.depends(select1.param.value, select2.param.value)
766
- # def update_plots(value1, value2):
767
- # selected_chart1 = update_chart(value1)
768
- # selected_chart2 = update_chart(value2)
769
- # if selected_chart1 and selected_chart2:
770
- # return pn.Row(selected_chart1, selected_chart2)
771
- # elif selected_chart1:
772
- # return selected_chart1
773
- # elif selected_chart2:
774
- # return selected_chart2
775
- # else:
776
- # return None
777
 
778
- # # Define functions for each category
779
- # def update_plots_altruism():
780
- # return pn.Row(final, final5)
781
 
782
- # def update_plots_fairness():
783
- # return pn.Row(final2, final5)
784
 
785
- # def update_plots_spite():
786
- # return final
787
 
788
- # def update_plots_trust():
789
- # return final4
790
 
791
- # def update_plots_reciprocity():
792
- # return final5
793
 
794
- # def update_plots_freeriding():
795
- # return final6
796
 
797
- # def update_plots_cooperation():
798
- # return final6
799
 
800
- # # Define a dictionary to map categories to update functions
801
- # update_functions = {
802
- # 'Altruism': update_plots_altruism,
803
- # 'Fairness': update_plots_fairness,
804
- # 'spite': update_plots_spite,
805
- # 'trust': update_plots_trust,
806
- # 'reciprocity': update_plots_reciprocity,
807
- # 'freeriding': update_plots_freeriding,
808
- # 'cooperation': update_plots_cooperation
809
- # }
810
 
811
 
812
- # # # Define function to update chart based on selected category
813
- # # def update_plots_category(event):
814
- # # selected_category = event.new
815
- # # maincol.clear() # Clear existing content in main column
816
-
817
- # # if selected_category in update_functions:
818
- # # update_function = update_functions[selected_category]
819
- # # maincol.append(update_function())
820
- # # else:
821
- # # maincol.append(pn.pane.Markdown(f"No update function found for category: {selected_category}"))
822
-
823
  # # Define function to update chart based on selected category
824
  # def update_plots_category(event):
825
  # selected_category = event.new
@@ -830,35 +819,46 @@ select_widget = pn.widgets.Select(options=options, name='Select a category')
830
  # maincol.append(update_function())
831
  # else:
832
  # maincol.append(pn.pane.Markdown(f"No update function found for category: {selected_category}"))
 
 
 
 
 
 
 
 
 
 
 
833
 
834
- # # Append select_widget again to allow changing the category selection
835
- # maincol.append(select_widget)
836
 
837
 
838
- # # Callback function to handle select widget events
839
- # def select_callback(event):
840
- # selected_value = event.new
841
- # maincol.clear() # Clear existing content in main column
842
 
843
- # if selected_value == 'Choose Your Own':
844
- # maincol.append(select1)
845
- # maincol.append(select2)
846
- # maincol.append(update_plots)
847
-
848
- # elif selected_value == 'Based On Category':
849
- # maincol.append(select_widget)
850
- # select_widget.param.watch(update_plots_category, 'value')
851
 
852
- # # # Bind the update_plots_category function to the select widget's 'value' parameter
853
- # # select.param.watch
854
- # # maincol.append(update_plots_category())
855
 
856
- # # Bind the callback function to the select widget's 'value' parameter
857
- # select0.param.watch(select_callback, 'value')
858
 
859
- # maincol.append(select0)
860
 
861
- maincol.append(select1)
862
 
863
  template.main.append(maincol)
864
  template.servable(title='SI649 Project2')
 
11
  import panel as pn
12
  import altair as alt
13
 
14
+ def choices_to_df(choices, hue):
15
+ df = pd.DataFrame(choices, columns=['choices'])
16
+ df['hue'] = hue
17
+ df['hue'] = df['hue'].astype(str)
18
+ return df
19
+
20
+ binrange = (0, 100)
21
+ moves = []
22
+ with open('dictator.csv', 'r') as f:
23
+ reader = csv.reader(f)
24
+ header = next(reader)
25
+ col2idx = {col: idx for idx, col in enumerate(header)}
26
+ for row in reader:
27
+ record = {col: row[idx] for col, idx in col2idx.items()}
28
+
29
+ if record['Role'] != 'first': continue
30
+ if int(record['Round']) > 1: continue
31
+ if int(record['Total']) != 100: continue
32
+ if record['move'] == 'None': continue
33
+ if record['gameType'] != 'dictator': continue
34
+
35
+ move = float(record['move'])
36
+ if move < binrange[0] or \
37
+ move > binrange[1]: continue
38
 
39
+ moves.append(move)
40
+
41
+ df_dictator_human = choices_to_df(moves, 'Human')
42
+
43
+ choices = [50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0]
44
+ df_dictator_gpt4 = choices_to_df(choices, hue=str('ChatGPT-4'))
45
+
46
+ choices = [25, 35, 70, 30, 20, 25, 40, 80, 30, 30, 40, 30, 30, 30, 30, 30, 40, 40, 30, 30, 40, 30, 60, 20, 40, 25, 30, 30, 30]
47
+ df_dictator_turbo = choices_to_df(choices, hue=str('ChatGPT-3'))
48
+
49
+ def extract_choices(recrods):
50
+ choices = [extract_amout(
51
+ messages[-1]['content'],
52
+ prefix='$',
53
+ print_except=True,
54
+ type=float) for messages in records['messages']
55
+ ]
56
+ choices = [x for x in choices if x is not None]
57
+ # print(choices)
58
+ return choices
59
+
60
+ def extract_amout(
61
+ message,
62
+ prefix='',
63
+ print_except=True,
64
+ type=float,
65
+ brackets='[]'
66
+ ):
67
+ try:
68
+ matches = extract_brackets(message, brackets=brackets)
69
+ matches = [s[len(prefix):] \
70
+ if s.startswith(prefix) \
71
+ else s for s in matches]
72
+ invalid = False
73
+ if len(matches) == 0:
74
+ invalid = True
75
+ for i in range(len(matches)):
76
+ if matches[i] != matches[0]:
77
+ invalid = True
78
+ if invalid:
79
+ raise ValueError('Invalid answer: %s' % message)
80
+ return type(matches[0])
81
+ except Exception as e:
82
+ if print_except: print(e)
83
+ return None
84
+
85
+ records = json.load(open('dictator_wo_ex_2023_03_13-11_24_07_PM.json', 'r'))
86
+ choices = extract_choices(records)
87
+
88
+ # Plot 1 - Dictator (altruism)
89
+ def plot_facet(
90
+ df_list,
91
+ x='choices',
92
+ hue='hue',
93
+ palette=None,
94
+ binrange=None,
95
+ bins=10,
96
+ # binwidth=10,
97
+ stat='count',
98
+ x_label='',
99
+ sharex=True,
100
+ sharey=False,
101
+ subplot=sns.histplot,
102
+ xticks_locs=None,
103
+ # kde=False,
104
+ **kwargs
105
+ ):
106
+ data = pd.concat(df_list)
107
+ if binrange is None:
108
+ binrange = (data[x].min(), data[x].max())
109
+ g = sns.FacetGrid(
110
+ data, row=hue, hue=hue,
111
+ palette=palette,
112
+ aspect=2, height=2,
113
+ sharex=sharex, sharey=sharey,
114
+ despine=True,
115
+ )
116
+ g.map_dataframe(
117
+ subplot,
118
+ x=x,
119
+ # kde=kde,
120
+ binrange=binrange,
121
+ bins=bins,
122
+ stat=stat,
123
+ **kwargs
124
+ )
125
+ # g.add_legend(title='hue')
126
+ g.set_axis_labels(x_label, stat.title())
127
+ g.set_titles(row_template="{row_name}")
128
+ for ax in g.axes.flat:
129
+ ax.yaxis.set_major_formatter(
130
+ FuncFormatter(lambda y, pos: '{:.2f}'.format(y))
131
+ )
132
 
133
+ binwidth = (binrange[1] - binrange[0]) / bins
134
+ if xticks_locs is None:
135
+ locs = np.linspace(binrange[0], binrange[1], bins//2+1)
136
+ locs = [loc + binwidth for loc in locs]
137
+ else:
138
+ locs = xticks_locs
139
+ labels = [str(int(loc)) for loc in locs]
140
+ locs = [loc + 0.5*binwidth for loc in locs]
141
+ plt.xticks(locs, labels)
142
 
143
+ g.set(xlim=binrange)
144
+ return g
145
+
146
+ df = df_dictator_human
147
+ bin_ranges = [0, 10, 30, 50, 70]
148
+
149
+ # Calculate density as a percentage
150
+ density_percentage = df['choices'].value_counts(normalize=True)
151
+
152
+ # Create a DataFrame with the density percentages
153
+ density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
154
+
155
+ # Create the bar chart using Altair
156
+ chart1 = alt.Chart(density_df).mark_bar().encode(
157
+ x=alt.X('choices:O', bin=alt.Bin(extent=[0, 70], step=10), axis=None),
158
+ y='density:Q',
159
+ color=alt.value('steelblue'),
160
+ tooltip=['density']
161
+ ).properties(
162
+ width=500,
163
+ title='Density of Choices'
164
+ ).interactive()
165
 
166
+ df = df_dictator_gpt4
167
+ bin_ranges = [0, 10, 30, 50, 70]
168
 
169
+ # Calculate density as a percentage
170
+ density_percentage = df['choices'].value_counts(normalize=True)
171
 
172
+ # Create a DataFrame with the density percentages
173
+ density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
174
 
175
+ # Create the bar chart using Altair
176
+ chart2 = alt.Chart(density_df).mark_bar().encode(
177
+ x=alt.X('choices:O', bin=alt.Bin(extent=[0, 70], step=10), axis=None),
178
+ y='density:Q',
179
+ color=alt.value('orange'),
180
+ tooltip=['density']
181
+ ).properties(
182
+ width=500,
183
+ title='Density of Choices'
184
+ ).interactive()
185
 
186
+ df = df_dictator_turbo
187
+
188
+ bin_ranges = [0, 10, 30, 50, 70]
189
 
190
+ # Calculate density as a percentage
191
+ density_percentage = df['choices'].value_counts(normalize=True)
192
 
193
+ # Create a DataFrame with the density percentages
194
+ density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
195
+
196
+ # Create the bar chart using Altair
197
+ chart3 = alt.Chart(density_df).mark_bar().encode(
198
+ x=alt.X('choices:O', bin=alt.Bin(extent=[0, 70], step=10)),
199
+ y='density:Q',
200
+ color=alt.value('green'),
201
+ tooltip=['density']
202
+ ).properties(
203
+ width=500,
204
+ title='Density of Choices'
205
+ ).interactive()
206
+
207
+ final = alt.vconcat(chart1, chart2, chart3).resolve_scale(x='shared')
208
+
209
+ #Plot 2 - - Ultimatum (Fairness)
210
+ df = pd.read_csv('ultimatum_strategy.csv')
211
+ df = df[df['gameType'] == 'ultimatum_strategy']
212
+ df = df[df['Role'] == 'player']
213
+ df = df[df['Round'] == 1]
214
+ df = df[df['Total'] == 100]
215
+ df = df[df['move'] != 'None']
216
+ df['propose'] = df['move'].apply(lambda x: eval(x)[0])
217
+ df['accept'] = df['move'].apply(lambda x: eval(x)[1])
218
+ df = df[(df['propose'] >= 0) & (df['propose'] <= 100)]
219
+ df = df[(df['accept'] >= 0) & (df['accept'] <= 100)]
220
+
221
+ df_ultimatum_1_human = choices_to_df(list(df['propose']), 'Human')
222
+ df_ultimatum_2_human = choices_to_df(list(df['accept']), 'Human')
223
+
224
+ choices = [50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0]
225
+ df_ultimatum_1_gpt4 = choices_to_df(choices, hue=str('ChatGPT-4'))
226
+
227
+ choices = [40, 40, 40, 30, 70, 70, 50, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 30, 30, 35, 50, 40, 70, 40, 60, 60, 70, 40, 50]
228
+ df_ultimatum_1_turbo = choices_to_df(choices, hue=str('ChatGPT-3'))
229
+
230
+ choices = [50.0, 50.0, 50.0, 1.0, 1.0, 1.0, 50.0, 25.0, 50.0, 1.0, 1.0, 20.0, 50.0, 50.0, 50.0, 20.0, 50.0, 1.0, 1.0, 1.0, 50.0, 50.0, 50.0, 1.0, 1.0, 1.0, 20.0, 1.0] + [0, 1]
231
+ df_ultimatum_2_gpt4 = choices_to_df(choices, hue=str('ChatGPT-4'))
232
+
233
+ choices = [None, 50, 50, 50, 50, 30, None, None, 30, 33.33, 40, None, 50, 40, None, 1, 30, None, 10, 50, 30, 10, 30, None, 30, None, 10, 30, 30, 30]
234
+ df_ultimatum_2_turbo = choices_to_df(choices, hue=str('ChatGPT-3'))
235
+
236
+ choices = [50.0, 50.0, 10.0, 40.0, 20.0, 50.0, 1.0, 1.0, 50.0, 1.0, 50.0, 50.0, 20.0, 10.0, 50.0, 20.0, 1.0, 1.0, 50.0, 1.0, 20.0, 1.0, 50.0, 50.0, 20.0, 20.0, 50.0, 20.0, 1.0, 50.0]
237
+ df_ultimatum_2_gpt4_female = choices_to_df(choices, hue='ChatGPT-4 Female')
238
+
239
+ choices = [1.0, 1.0, 1.0, 20.0, 1.0, 1.0, 50.0, 1.0, 1.0, 50.0, 50.0, 50.0, 20.0, 20.0, 1.0, 50.0, 1.0, 1.0, 1.0, 50.0, 20.0, 1.0, 50.0, 20.0, 20.0, 10.0, 50.0, 1.0, 1.0, 1.0]
240
+ df_ultimatum_2_gpt4_male = choices_to_df(choices, hue='ChatGPT-4 Male')
241
+
242
+ choices = [40.0, 1.0, 1.0, 20.0, 1.0, 20.0, 50.0, 50.0, 1.0, 1.0, 1.0, 50.0, 1.0, 20.0, 50.0, 10.0, 50.0, 1.0, 1.0, 20.0, 1.0, 50.0, 20.0, 20.0, 20.0, 1.0, 1.0, 1.0, 1.0, 40.0]
243
+ df_ultimatum_2_gpt4_US = choices_to_df(choices, hue='ChatGPT-4 US')
244
+
245
+ choices = [1.0, 1.0, 20.0, 50.0, 1.0, 1.0, 1.0, 1.0, 20.0, 20.0, 50.0, 20.0, 20.0, 50.0, 20.0, 1.0, 40.0, 50.0, 1.0, 1.0, 1.0, 20.0, 1.0, 1.0, 50.0, 50.0, 1.0, 1.0, 1.0, 1.0]
246
+ df_ultimatum_2_gpt4_Poland = choices_to_df(choices, hue='ChatGPT-4 Poland')
247
+
248
+ choices = [50.0, 1.0, 20.0, 50.0, 50.0, 50.0, 50.0, 1.0, 1.0, 50.0, 1.0, 50.0, 1.0, 50.0, 1.0, 20.0, 1.0, 1.0, 20.0, 50.0, 0.0, 20.0, 1.0, 1.0, 1.0, 1.0, 20.0, 20.0, 50.0, 20.0]
249
+ df_ultimatum_2_gpt4_China = choices_to_df(choices, hue='ChatGPT-4 China')
250
+
251
+ choices = [1.0, 1.0, 1.0, 50.0, 1.0, 1.0, 50.0, 40.0, 1.0, 1.0, 1.0, 1.0, 20.0, 1.0, 1.0, 50.0, 1.0, 50.0, 1.0, 20.0, 1.0, 20.0, 1.0, 50.0, 1.0, 50.0, 20.0, 1.0, 1.0, 50.0]
252
+ df_ultimatum_2_gpt4_UK = choices_to_df(choices, hue='ChatGPT-4 UK')
253
+
254
+ choices = [50.0, 1.0, 20.0, 50.0, 50.0, 50.0, 50.0, 10.0, 1.0, 40.0, 50.0, 20.0, 1.0, 1.0, 1.0, 50.0, 50.0, 20.0, 20.0, 1.0, 1.0, 50.0, 20.0, 50.0, 50.0, 20.0, 1.0, 20.0, 50.0, 1]
255
+ df_ultimatum_2_gpt4_Columbia = choices_to_df(choices, hue='ChatGPT-4 Columbia')
256
+
257
+ choices = [50.0, 1.0, 50.0, 20.0, 20.0, 20.0, 50.0, 20.0, 20.0, 1.0, 1.0, 1.0, 1.0, 20.0, 1.0, 50.0, 1.0, 20.0, 20.0, 50.0, 1.0, 50.0, 1.0, 40.0, 1.0, 20.0, 1.0, 20.0, 1.0, 1.0]
258
+ df_ultimatum_2_gpt4_under = choices_to_df(choices, hue='ChatGPT-4 Undergrad')
259
+
260
+ choices = [1.0, 20.0, 1.0, 40.0, 50.0, 1.0, 1.0, 1.0, 25.0, 20.0, 50.0, 20.0, 50.0, 50.0, 1.0, 50.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 50.0, 20.0, 1.0, 1.0, 1.0, 50.0, 20.0, 20.0]
261
+ df_ultimatum_2_gpt4_grad = choices_to_df(choices, hue='ChatGPT-4 Graduate')
262
+
263
+ df = df_ultimatum_1_human
264
+ bin_ranges = [0, 10, 30, 50, 70]
265
+
266
+ # Calculate density as a percentage
267
+ density_percentage = df['choices'].value_counts(normalize=True)
268
+
269
+ # Create a DataFrame with the density percentages
270
+ density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
271
+
272
+ # Create the bar chart using Altair
273
+ chart1 = alt.Chart(density_df).mark_bar().encode(
274
+ x=alt.X('choices:O', bin=alt.Bin(extent=[0, 70], step=10), axis=None),
275
+ y='density:Q',
276
+ color=alt.value('steelblue'),
277
+ tooltip=['density']
278
+ ).properties(
279
+ width=500,
280
+ title='Density of Choices'
281
+ ).interactive()
282
+
283
+ df = df_ultimatum_1_gpt4
284
+ bin_ranges = [0, 10, 30, 50, 70]
285
+
286
+ # Calculate density as a percentage
287
+ density_percentage = df['choices'].value_counts(normalize=True)
288
+
289
+ # Create a DataFrame with the density percentages
290
+ density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
291
+
292
+ # Create the bar chart using Altair
293
+ chart2 = alt.Chart(density_df).mark_bar().encode(
294
+ x=alt.X('choices:O', bin=alt.Bin(extent=[0, 70], step=10), axis=None),
295
+ y='density:Q',
296
+ color=alt.value('orange'),
297
+ tooltip=['density']
298
+ ).properties(
299
+ width=500,
300
+ title='Density of Choices'
301
+ ).interactive()
302
+
303
+ df = df_ultimatum_1_turbo
304
+ bin_ranges = [0, 10, 30, 50, 70]
305
+
306
+ # Calculate density as a percentage
307
+ density_percentage = df['choices'].value_counts(normalize=True)
308
+
309
+ # Create a DataFrame with the density percentages
310
+ density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
311
+
312
+ # Create the bar chart using Altair
313
+ chart3 = alt.Chart(density_df).mark_bar().encode(
314
+ x=alt.X('choices:O', bin=alt.Bin(extent=[0, 70], step=10)),
315
+ y='density:Q',
316
+ color=alt.value('green'),
317
+ tooltip=['density']
318
+ ).properties(
319
+ width=500,
320
+ title='Density of Choices'
321
+ ).interactive()
322
+
323
+ final2 = alt.vconcat(chart1, chart2, chart3).resolve_scale(x='shared')
324
+
325
+ #Plot 3 - - Ultimatum (Responder) (spite)
326
+ df = df_ultimatum_2_human
327
+ bin_ranges = [0, 10, 30, 50, 70]
328
+
329
+ # Calculate density as a percentage
330
+ density_percentage = df['choices'].value_counts(normalize=True)
331
+
332
+ # Create a DataFrame with the density percentages
333
+ density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
334
+
335
+ # Create the bar chart using Altair
336
+ chart1 = alt.Chart(density_df).mark_bar().encode(
337
+ x=alt.X('choices:O', bin=alt.Bin(extent=[0, 70], step=10), axis=None),
338
+ y='density:Q',
339
+ color=alt.value('steelblue'),
340
+ tooltip=['density']
341
+ ).properties(
342
+ width=500,
343
+ title='Density of Choices'
344
+ ).interactive()
345
+
346
+ df = df_ultimatum_2_gpt4
347
+ bin_ranges = [0, 10, 30, 50, 70]
348
+
349
+ # Calculate density as a percentage
350
+ density_percentage = df['choices'].value_counts(normalize=True)
351
+
352
+ # Create a DataFrame with the density percentages
353
+ density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
354
+
355
+ # Create the bar chart using Altair
356
+ chart2 = alt.Chart(density_df).mark_bar().encode(
357
+ x=alt.X('choices:O', bin=alt.Bin(extent=[0, 70], step=10), axis=None),
358
+ y='density:Q',
359
+ color=alt.value('orange'),
360
+ tooltip=['density']
361
+ ).properties(
362
+ width=500,
363
+ title='Density of Choices'
364
+ ).interactive()
365
+
366
+ df = df_ultimatum_2_turbo
367
+ bin_ranges = [0, 10, 30, 50, 70]
368
+
369
+ # Calculate density as a percentage
370
+ density_percentage = df['choices'].value_counts(normalize=True)
371
+
372
+ # Create a DataFrame with the density percentages
373
+ density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
374
+
375
+ # Create the bar chart using Altair
376
+ chart3 = alt.Chart(density_df).mark_bar().encode(
377
+ x=alt.X('choices:O', bin=alt.Bin(extent=[0, 70], step=10), axis=None),
378
+ y='density:Q',
379
+ color=alt.value('green'),
380
+ tooltip=['density']
381
+ ).properties(
382
+ width=500,
383
+ title='Density of Choices'
384
+ ).interactive()
385
+
386
+ final3 = alt.vconcat(chart1, chart2, chart3).resolve_scale(x='shared')
387
+
388
+ #Plot 4 - - Trust (as Investor) (trust)
389
+ binrange = (0, 100)
390
+ moves_1 = []
391
+ moves_2 = defaultdict(list)
392
+ with open('trust_investment.csv', 'r') as f:
393
+ reader = csv.reader(f)
394
+ header = next(reader)
395
+ col2idx = {col: idx for idx, col in enumerate(header)}
396
+ for row in reader:
397
+ record = {col: row[idx] for col, idx in col2idx.items()}
398
+
399
+ # if record['Role'] != 'first': continue
400
+ if int(record['Round']) > 1: continue
401
+ # if int(record['Total']) != 100: continue
402
+ if record['move'] == 'None': continue
403
+ if record['gameType'] != 'trust_investment': continue
404
+
405
+ if record['Role'] == 'first':
406
+ move = float(record['move'])
407
+ if move < binrange[0] or \
408
+ move > binrange[1]: continue
409
+ moves_1.append(move)
410
+ elif record['Role'] == 'second':
411
+ inv, ret = eval(record['roundResult'])
412
+ if ret < 0 or \
413
+ ret > inv * 3: continue
414
+ moves_2[inv].append(ret)
415
+ else: continue
416
+
417
+ df_trust_1_human = choices_to_df(moves_1, 'Human')
418
+ df_trust_2_human = choices_to_df(moves_2[10], 'Human')
419
+ df_trust_3_human = choices_to_df(moves_2[50], 'Human')
420
+ df_trust_4_human = choices_to_df(moves_2[100], 'Human')
421
+
422
+ choices = [50.0, 50.0, 40.0, 30.0, 50.0, 50.0, 40.0, 50.0, 50.0, 50.0, 50.0, 50.0, 30.0, 30.0, 50.0, 50.0, 50.0, 40.0, 40.0, 50.0, 50.0, 50.0, 50.0, 40.0, 50.0, 50.0, 50.0, 50.0]
423
+ df_trust_1_gpt4 = choices_to_df(choices, hue=str('ChatGPT-4'))
424
+
425
+ choices = [50.0, 50.0, 30.0, 30.0, 30.0, 60.0, 50.0, 40.0, 20.0, 20.0, 50.0, 40.0, 30.0, 20.0, 30.0, 20.0, 30.0, 60.0, 50.0, 30.0, 50.0, 20.0, 20.0, 30.0, 50.0, 30.0, 30.0, 50.0, 40.0] + [30]
426
+ df_trust_1_turbo = choices_to_df(choices, hue=str('ChatGPT-3'))
427
+
428
+ choices = [20.0, 20.0, 20.0, 20.0, 15.0, 15.0, 15.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 15.0, 20.0, 20.0, 20.0, 20.0, 20.0, 15.0, 15.0, 20.0, 15.0, 15.0, 15.0, 15.0, 15.0, 20.0, 20.0, 15.0]
429
+ df_trust_2_gpt4 = choices_to_df(choices, hue=str('ChatGPT-4'))
430
+
431
+ choices = [20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 15.0, 25.0, 30.0, 30.0, 20.0, 25.0, 30.0, 20.0, 20.0, 18.0] + [20, 20, 20, 25, 25, 25, 30]
432
+ df_trust_2_turbo = choices_to_df(choices, hue=str('ChatGPT-3'))
433
+
434
+ choices = [100.0, 75.0, 75.0, 75.0, 75.0, 75.0, 100.0, 75.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 75.0, 100.0, 75.0, 75.0, 75.0, 100.0, 100.0, 100.0, 75.0, 100.0, 100.0, 100.0, 100.0, 75.0, 100.0, 75.0]
435
+ df_trust_3_gpt4 = choices_to_df(choices, hue=str('ChatGPT-4'))
436
+
437
+ choices = [150.0, 100.0, 150.0, 150.0, 50.0, 150.0, 100.0, 150.0, 100.0, 100.0, 100.0, 150.0] + [100, 100, 100, 100, 100, 100, 100, 100]
438
+ df_trust_3_turbo = choices_to_df(choices, hue=str('ChatGPT-3'))
439
+
440
+ choices = [200.0, 200.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 200.0, 200.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 150.0]
441
+ df_trust_4_gpt4 = choices_to_df(choices, hue=str('ChatGPT-4'))
442
+
443
+ choices = [225.0, 225.0, 300.0, 300.0, 220.0, 300.0, 250.0] + [200, 200, 250, 200, 200]
444
+ df_trust_4_turbo = choices_to_df(choices, hue=str('ChatGPT-3'))
445
+
446
+ df = df_trust_1_human
447
+
448
+ bin_ranges = [0, 10, 30, 50, 70]
449
+
450
+ # Calculate density as a percentage
451
+ density_percentage = df['choices'].value_counts(normalize=True)
452
+
453
+ # Create a DataFrame with the density percentages
454
+ density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
455
+
456
+ # Create the bar chart using Altair
457
+ chart1 = alt.Chart(density_df).mark_bar().encode(
458
+ x=alt.X('choices:O', bin=alt.Bin(extent=[0, 70], step=10), axis=None),
459
+ y='density:Q',
460
+ color=alt.value('steelblue'),
461
+ tooltip=['density']
462
+ ).properties(
463
+ width=500,
464
+ title='Density of Choices'
465
+ ).interactive()
466
+
467
+
468
+
469
+ df = df_trust_1_gpt4
470
+
471
+ bin_ranges = [0, 10, 30, 50, 70]
472
+
473
+ # Calculate density as a percentage
474
+ density_percentage = df['choices'].value_counts(normalize=True)
475
+
476
+ # Create a DataFrame with the density percentages
477
+ density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
478
+
479
+ # Create the bar chart using Altair
480
+ chart2 = alt.Chart(density_df).mark_bar().encode(
481
+ x=alt.X('choices:O', bin=alt.Bin(extent=[0, 70], step=10), axis=None),
482
+ y='density:Q',
483
+ color=alt.value('orange'),
484
+ tooltip=['density']
485
+ ).properties(
486
+ width=500,
487
+ title='Density of Choices'
488
+ ).interactive()
489
+
490
+
491
+ df = df_trust_1_turbo
492
 
493
+ bin_ranges = [0, 10, 30, 50, 70]
494
 
495
+ # Calculate density as a percentage
496
+ density_percentage = df['choices'].value_counts(normalize=True)
497
 
498
+ # Create a DataFrame with the density percentages
499
+ density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
500
 
501
+ # Create the bar chart using Altair
502
+ chart3 = alt.Chart(density_df).mark_bar().encode(
503
+ x=alt.X('choices:O', bin=alt.Bin(extent=[0, 70], step=10), axis=None),
504
+ y='density:Q',
505
+ color=alt.value('green'),
506
+ tooltip=['density']
507
+ ).properties(
508
+ width=500,
509
+ title='Density of Choices'
510
+ ).interactive()
511
 
512
 
513
+ final4 = alt.vconcat(chart1, chart2, chart3).resolve_scale(x='shared')
514
+
515
+ #Plot 5 - Trust (as Banker) (fairness, altruism, reciprocity)
516
+ df = df_trust_3_human
517
+
518
+ bin_ranges = [0, 25, 50, 75, 100, 125, 150]
519
+
520
+ custom_ticks = [2, 6, 10, 14, 18]
521
+
522
+ # Calculate density as a percentage
523
+ density_percentage = df['choices'].value_counts(normalize=True)
524
+
525
+ # Create a DataFrame with the density percentages
526
+ density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
527
 
528
+ # Create the bar chart using Altair
529
+ chart1 = alt.Chart(density_df).mark_bar().encode(
530
+ x=alt.X('choices:O', bin=alt.Bin(step=10), axis=None),
531
+ y='density:Q',
532
+ color=alt.value('steelblue')
533
+ ).properties(
534
+ width=500,
535
+ title='Density of Choices'
536
+ ).interactive()
537
 
538
 
539
 
540
+ df = df_trust_3_gpt4
541
+
542
+ bin_ranges = [0, 25, 50, 75, 100, 125, 150]
543
+
544
+ # Calculate density as a percentage
545
+ density_percentage = df['choices'].value_counts(normalize=True)
546
 
547
+ # Create a DataFrame with the density percentages
548
+ density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
549
 
550
+ # Create the bar chart using Altair
551
+ chart2 = alt.Chart(density_df).mark_bar().encode(
552
+ x=alt.X('choices:O', bin=alt.Bin(step=10), axis=None),
553
+ y='density:Q',
554
+ color=alt.value('orange')
555
+ ).properties(
556
+ width=500,
557
+ title='Density of Choices'
558
+ ).interactive()
559
 
560
 
561
+ df = df_trust_3_turbo
562
 
563
+ bin_ranges = [0, 25, 50, 75, 100, 125, 150]
564
 
565
+ # Calculate density as a percentage
566
+ density_percentage = df['choices'].value_counts(normalize=True)
567
 
568
+ # Create a DataFrame with the density percentages
569
+ density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
570
 
571
+ # Create the bar chart using Altair
572
+ chart3 = alt.Chart(density_df).mark_bar().encode(
573
+ x=alt.X('choices:O', bin=alt.Bin(step=10)),
574
+ y='density:Q',
575
+ color=alt.value('green')
576
+ ).properties(
577
+ width=500,
578
+ title='Density of Choices'
579
+ ).interactive()
580
 
581
+ # chart1
582
+ final5 = alt.vconcat(chart1, chart2, chart3).resolve_scale(x='shared')
583
 
584
+ #Plot 6 - Public Goods (Free-Riding, altruism, cooperation)
585
+ df = pd.read_csv('public_goods_linear_water.csv')
586
+ df = df[df['Role'] == 'contributor']
587
+ df = df[df['Round'] <= 3]
588
+ df = df[df['Total'] == 20]
589
+ df = df[df['groupSize'] == 4]
590
+ df = df[df['move'] != None]
591
+ df = df[(df['move'] >= 0) & (df['move'] <= 20)]
592
+ df = df[df['gameType'] == 'public_goods_linear_water']
593
 
594
+ round_1 = df[df['Round'] == 1]['move']
595
+ round_2 = df[df['Round'] == 2]['move']
596
+ round_3 = df[df['Round'] == 3]['move']
597
+ print(len(round_1), len(round_2), len(round_3))
598
+ df_PG_human = pd.DataFrame({
599
+ 'choices': list(round_1)
600
+ })
601
+ df_PG_human['hue'] = 'Human'
602
+ # df_PG_human
603
 
604
+ file_names = [
605
+ 'PG_basic_turbo_2023_05_09-02_49_09_AM.json',
606
+ 'PG_basic_turbo_loss_2023_05_09-03_59_49_AM.json',
607
+ 'PG_basic_gpt4_2023_05_09-11_15_42_PM.json',
608
+ 'PG_basic_gpt4_loss_2023_05_09-10_44_38_PM.json',
609
+ ]
610
 
611
+ choices = []
612
+ for file_name in file_names:
613
+ with open(file_name, 'r') as f:
614
+ choices += json.load(f)['choices']
615
+ choices_baseline = choices
616
 
617
+ choices = [tuple(x)[0] for x in choices]
618
+ df_PG_turbo = choices_to_df(choices, hue=str('ChatGPT-3'))
619
+ # df_PG_turbo.head()
620
+ df_PG_gpt4 = choices_to_df(choices, hue=str('ChatGPT-4'))
621
+ # df_PG_gpt4.head()
622
+
623
+ df = df_PG_human
624
+
625
+ bin_ranges = [0, 25, 50, 75, 100, 125, 150]
626
+
627
+ custom_ticks = [2, 6, 10, 14, 18]
628
+
629
+ # Calculate density as a percentage
630
+ density_percentage = df['choices'].value_counts(normalize=True)
631
+
632
+ # Create a DataFrame with the density percentages
633
+ density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
634
+
635
+ # Create the bar chart using Altair
636
+ chart1 = alt.Chart(density_df).mark_bar().encode(
637
+ x=alt.X('choices:O', bin=alt.Bin(step=2), axis=None),
638
+ y='density:Q',
639
+ color=alt.value('steelblue'),
640
+ tooltip=['density']
641
+ ).properties(
642
+ width=500,
643
+ title='Density of Choices'
644
+ ).interactive()
645
+
646
+
647
+
648
+ df = df_PG_gpt4
649
+
650
+ bin_ranges = [0, 25, 50, 75, 100, 125, 150]
651
+
652
+ # Calculate density as a percentage
653
+ density_percentage = df['choices'].value_counts(normalize=True)
654
+
655
+ # Create a DataFrame with the density percentages
656
+ density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
657
+
658
+ # Create the bar chart using Altair
659
+ chart2 = alt.Chart(density_df).mark_bar().encode(
660
+ x=alt.X('choices:O', bin=alt.Bin(step=2), axis=None),
661
+ y='density:Q',
662
+ color=alt.value('orange'),
663
+ tooltip=['density']
664
+ ).properties(
665
+ width=500,
666
+ title='Density of Choices'
667
+ ).interactive()
668
+
669
+
670
+ df = df_PG_turbo
671
+
672
+ bin_ranges = [0, 25, 50, 75, 100, 125, 150]
673
+
674
+ # Calculate density as a percentage
675
+ density_percentage = df['choices'].value_counts(normalize=True)
676
+
677
+ # Create a DataFrame with the density percentages
678
+ density_df = pd.DataFrame({'choices': density_percentage.index, 'density': density_percentage.values})
679
+
680
+ # Create the bar chart using Altair
681
+ chart3 = alt.Chart(density_df).mark_bar().encode(
682
+ x=alt.X('choices:O', bin=alt.Bin(step=2)),
683
+ y='density:Q',
684
+ color=alt.value('green'),
685
+ tooltip=['density']
686
+ ).properties(
687
+ width=500,
688
+ title='Density of Choices'
689
+ ).interactive()
690
 
691
+ # chart1
692
+ final6 = alt.vconcat(chart1, chart2, chart3).resolve_scale(x='shared')
693
 
694
+ #Final_Final
695
+ final_final = (final | final2 | final3 ) & (final4 | final5 | final6)
696
 
697
 
698
  # # we want to use bootstrap/template, tell Panel to load up what we need
 
753
  select_widget = pn.widgets.Select(options=options, name='Select a category')
754
 
755
 
756
+ # Define function to update chart
757
+ def update_chart(value):
758
+ if value:
759
+ index = int(value.split()[-1]) - 1
760
+ return charts[index]
761
+ else:
762
+ return None
763
+
764
+ # Combine dropdown and chart
765
+ @pn.depends(select1.param.value, select2.param.value)
766
+ def update_plots(value1, value2):
767
+ selected_chart1 = update_chart(value1)
768
+ selected_chart2 = update_chart(value2)
769
+ if selected_chart1 and selected_chart2:
770
+ return pn.Row(selected_chart1, selected_chart2)
771
+ elif selected_chart1:
772
+ return selected_chart1
773
+ elif selected_chart2:
774
+ return selected_chart2
775
+ else:
776
+ return None
777
 
778
+ # Define functions for each category
779
+ def update_plots_altruism():
780
+ return pn.Row(final, final5)
781
 
782
+ def update_plots_fairness():
783
+ return pn.Row(final2, final5)
784
 
785
+ def update_plots_spite():
786
+ return final
787
 
788
+ def update_plots_trust():
789
+ return final4
790
 
791
+ def update_plots_reciprocity():
792
+ return final5
793
 
794
+ def update_plots_freeriding():
795
+ return final6
796
 
797
+ def update_plots_cooperation():
798
+ return final6
799
 
800
+ # Define a dictionary to map categories to update functions
801
+ update_functions = {
802
+ 'Altruism': update_plots_altruism,
803
+ 'Fairness': update_plots_fairness,
804
+ 'spite': update_plots_spite,
805
+ 'trust': update_plots_trust,
806
+ 'reciprocity': update_plots_reciprocity,
807
+ 'freeriding': update_plots_freeriding,
808
+ 'cooperation': update_plots_cooperation
809
+ }
810
 
811
 
 
 
 
 
 
 
 
 
 
 
 
812
  # # Define function to update chart based on selected category
813
  # def update_plots_category(event):
814
  # selected_category = event.new
 
819
  # maincol.append(update_function())
820
  # else:
821
  # maincol.append(pn.pane.Markdown(f"No update function found for category: {selected_category}"))
822
+
823
+ # Define function to update chart based on selected category
824
+ def update_plots_category(event):
825
+ selected_category = event.new
826
+ maincol.clear() # Clear existing content in main column
827
+
828
+ if selected_category in update_functions:
829
+ update_function = update_functions[selected_category]
830
+ maincol.append(update_function())
831
+ else:
832
+ maincol.append(pn.pane.Markdown(f"No update function found for category: {selected_category}"))
833
 
834
+ # Append select_widget again to allow changing the category selection
835
+ maincol.append(select_widget)
836
 
837
 
838
+ # Callback function to handle select widget events
839
+ def select_callback(event):
840
+ selected_value = event.new
841
+ maincol.clear() # Clear existing content in main column
842
 
843
+ if selected_value == 'Choose Your Own':
844
+ maincol.append(select1)
845
+ maincol.append(select2)
846
+ maincol.append(update_plots)
847
+
848
+ elif selected_value == 'Based On Category':
849
+ maincol.append(select_widget)
850
+ select_widget.param.watch(update_plots_category, 'value')
851
 
852
+ # # Bind the update_plots_category function to the select widget's 'value' parameter
853
+ # select.param.watch
854
+ # maincol.append(update_plots_category())
855
 
856
+ # Bind the callback function to the select widget's 'value' parameter
857
+ select0.param.watch(select_callback, 'value')
858
 
859
+ maincol.append(select0)
860
 
861
+ # maincol.append(select1)
862
 
863
  template.main.append(maincol)
864
  template.servable(title='SI649 Project2')