Skip to content

Commit 1c43061

Browse files
authored
Merge pull request #2 from Dallinger/stories/341-bot-data
Story 341: Script/Notebook to collect and replay bot-driven data
2 parents cf0d4b8 + cd8a045 commit 1c43061

11 files changed

+370
-2
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ RUN sed /etc/postgresql/10/main/pg_hba.conf -e 's/md5/trust/g' --in-place
3232
RUN apt-get -yq install redis-server
3333

3434
RUN sudo pip3 install matplotlib==2.1.0
35-
RUN sudo pip3 install -e git+https://github.com/Dallinger/Dallinger.git@stories/342-realtime-playback#egg=dallinger[data,jupyter]
35+
RUN sudo pip3 install -e git+https://github.com/Dallinger/Dallinger.git@stories/341-bot-data#egg=dallinger[data,jupyter]
3636
RUN sudo pip3 install -e git+https://github.com/Dallinger/Griduniverse.git@stories/342-realtime-playback#egg=dlgr-griduniverse
3737

3838
# My binder specifics as per:

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
# NGS2 Cycle 2 pilot data
22

3-
[![Binder](https://mybinder.org/badge.svg)](https://mybinder.org/v2/gh/Dallinger/ngs2-cycle2-pilot-data/stories%2F340-replay-widget-p3?filepath=analyses.ipynb)
3+
[![Binder](https://mybinder.org/badge.svg)](https://mybinder.org/v2/gh/Dallinger/ngs2-cycle2-pilot-data/stories%2F341-bot-data?filepath=analyses.ipynb)
4+
5+
# Bot Run Data
6+
7+
[![Binder](https://mybinder.org/badge.svg)](https://mybinder.org/v2/gh/Dallinger/ngs2-cycle2-pilot-data/stories%2F341-bot-data?filepath=bot_runs%2Fbot_collector.ipynb)

bot_runs/bot_collector.ipynb

Lines changed: 282 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,282 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 5,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import sys\n",
10+
"import csv\n",
11+
"import dallinger\n",
12+
"from dallinger.experiments import Griduniverse\n",
13+
"\n",
14+
"\n",
15+
"sys.path.append('..')\n",
16+
"import binder_helpers\n",
17+
"binder_helpers.start_services()\n",
18+
"\n",
19+
"ROWS = 49\n",
20+
"COLS = 49\n",
21+
"ORIG_CSV_LIMIT = csv.field_size_limit(ROWS*COLS*1024)\n",
22+
"\n",
23+
"BASE_ID = \"{}01daa{}-f7ed-43fa-ad6b-9928aa51f8e1\"\n",
24+
"PARTICIPANTS = 9\n",
25+
"NUM_AS_EXPERIMENTS = 3\n",
26+
"NUM_RANDOM_EXPERIMENTS = 3\n",
27+
"\n",
28+
"EXP_CONFIG = {\n",
29+
" \"recruiter\": \"bots\",\n",
30+
" \"max_participants\": PARTICIPANTS,\n",
31+
"}\n",
32+
"\n",
33+
"exp = Griduniverse()\n",
34+
"data = {}"
35+
]
36+
},
37+
{
38+
"cell_type": "code",
39+
"execution_count": 6,
40+
"metadata": {},
41+
"outputs": [
42+
{
43+
"name": "stdout",
44+
"output_type": "stream",
45+
"text": [
46+
"Collecting 3 experiments with 9 AdvantageSeekingBot players\n",
47+
">>>> Retrieve: Data found for experiment ab01daa0-f7ed-43fa-ad6b-9928aa51f8e1, retrieving.\n",
48+
">>>> Retrieve: Data found for experiment ab01daa1-f7ed-43fa-ad6b-9928aa51f8e1, retrieving.\n",
49+
">>>> Retrieve: Data found for experiment ab01daa2-f7ed-43fa-ad6b-9928aa51f8e1, retrieving.\n",
50+
"Data retrieval complete\n"
51+
]
52+
}
53+
],
54+
"source": [
55+
"print('Collecting {} experiments with {} AdvantageSeekingBot players'.format(\n",
56+
" NUM_AS_EXPERIMENTS, PARTICIPANTS\n",
57+
"))\n",
58+
"\n",
59+
"for count in range(NUM_AS_EXPERIMENTS):\n",
60+
" exp_id = BASE_ID.format('ab', count)\n",
61+
" config = EXP_CONFIG.copy()\n",
62+
" config['bot_policy'] = 'AdvantageSeekingBot'\n",
63+
" data[exp_id] = {\n",
64+
" 'title': '{} Experiment #{} ({})'.format(config['bot_policy'], count + 1, exp_id),\n",
65+
" 'data': exp.collect(exp_id, exp_config=config)\n",
66+
" }\n",
67+
" \n",
68+
"print('Data retrieval complete.')"
69+
]
70+
},
71+
{
72+
"cell_type": "code",
73+
"execution_count": 7,
74+
"metadata": {},
75+
"outputs": [
76+
{
77+
"name": "stdout",
78+
"output_type": "stream",
79+
"text": [
80+
"Collecting 3 experiments with 9 RandomBot players\n",
81+
">>>> Retrieve: Data found for experiment ad01daa0-f7ed-43fa-ad6b-9928aa51f8e1, retrieving.\n",
82+
">>>> Retrieve: Data found for experiment ad01daa1-f7ed-43fa-ad6b-9928aa51f8e1, retrieving.\n",
83+
">>>> Retrieve: Data found for experiment ad01daa2-f7ed-43fa-ad6b-9928aa51f8e1, retrieving.\n",
84+
"Data retrieval complete.\n"
85+
]
86+
}
87+
],
88+
"source": [
89+
"print('Collecting {} experiments with {} RandomBot players'.format(\n",
90+
" NUM_RANDOM_EXPERIMENTS, PARTICIPANTS\n",
91+
"))\n",
92+
"\n",
93+
"for count in range(NUM_RANDOM_EXPERIMENTS):\n",
94+
" exp_id = BASE_ID.format('ad', count)\n",
95+
" config = EXP_CONFIG.copy()\n",
96+
" config['bot_policy'] = 'RandomBot'\n",
97+
" data[exp_id] = {\n",
98+
" 'title': '{} Experiment #{} ({})'.format(config['bot_policy'], count + 1, exp_id),\n",
99+
" 'data': exp.collect(exp_id, exp_config=config)\n",
100+
" }\n",
101+
"\n",
102+
"print('Data retrieval complete.') "
103+
]
104+
},
105+
{
106+
"cell_type": "code",
107+
"execution_count": 4,
108+
"metadata": {
109+
"scrolled": false
110+
},
111+
"outputs": [
112+
{
113+
"name": "stdout",
114+
"output_type": "stream",
115+
"text": [
116+
"Successfully collected data from 6 bot experiments. Rendering replay widgets:\n",
117+
"Ingesting dataset from ab01daa0-f7ed-43fa-ad6b-9928aa51f8e1-data.zip...\n"
118+
]
119+
},
120+
{
121+
"data": {
122+
"application/vnd.jupyter.widget-view+json": {
123+
"model_id": "38f06c4e23f44271ac6f6875fdd9066a",
124+
"version_major": 2,
125+
"version_minor": 0
126+
},
127+
"text/plain": [
128+
"VBox(children=(ExperimentWidget(children=(HTML(value='\\n<h2>AdvantageSeekingBot Experiment #1 (ab01daa0-f7ed-4…"
129+
]
130+
},
131+
"metadata": {},
132+
"output_type": "display_data"
133+
},
134+
{
135+
"name": "stdout",
136+
"output_type": "stream",
137+
"text": [
138+
"Ingesting dataset from ab01daa1-f7ed-43fa-ad6b-9928aa51f8e1-data.zip...\n"
139+
]
140+
},
141+
{
142+
"data": {
143+
"application/vnd.jupyter.widget-view+json": {
144+
"model_id": "db5a419157a64f2fbc53fb6d8b3cb8da",
145+
"version_major": 2,
146+
"version_minor": 0
147+
},
148+
"text/plain": [
149+
"VBox(children=(ExperimentWidget(children=(HTML(value='\\n<h2>AdvantageSeekingBot Experiment #2 (ab01daa1-f7ed-4…"
150+
]
151+
},
152+
"metadata": {},
153+
"output_type": "display_data"
154+
},
155+
{
156+
"name": "stdout",
157+
"output_type": "stream",
158+
"text": [
159+
"Ingesting dataset from ab01daa2-f7ed-43fa-ad6b-9928aa51f8e1-data.zip...\n"
160+
]
161+
},
162+
{
163+
"data": {
164+
"application/vnd.jupyter.widget-view+json": {
165+
"model_id": "23c4951777ab4e37af3d8deffb690e29",
166+
"version_major": 2,
167+
"version_minor": 0
168+
},
169+
"text/plain": [
170+
"VBox(children=(ExperimentWidget(children=(HTML(value='\\n<h2>AdvantageSeekingBot Experiment #3 (ab01daa2-f7ed-4…"
171+
]
172+
},
173+
"metadata": {},
174+
"output_type": "display_data"
175+
},
176+
{
177+
"name": "stdout",
178+
"output_type": "stream",
179+
"text": [
180+
"Ingesting dataset from ad01daa0-f7ed-43fa-ad6b-9928aa51f8e1-data.zip...\n"
181+
]
182+
},
183+
{
184+
"data": {
185+
"application/vnd.jupyter.widget-view+json": {
186+
"model_id": "058a6f9ff1144200989455a030dca0a8",
187+
"version_major": 2,
188+
"version_minor": 0
189+
},
190+
"text/plain": [
191+
"VBox(children=(ExperimentWidget(children=(HTML(value='\\n<h2>RandomBot Experiment #1 (ad01daa0-f7ed-43fa-ad6b-9…"
192+
]
193+
},
194+
"metadata": {},
195+
"output_type": "display_data"
196+
},
197+
{
198+
"name": "stdout",
199+
"output_type": "stream",
200+
"text": [
201+
"Ingesting dataset from ad01daa1-f7ed-43fa-ad6b-9928aa51f8e1-data.zip...\n"
202+
]
203+
},
204+
{
205+
"data": {
206+
"application/vnd.jupyter.widget-view+json": {
207+
"model_id": "8f32522f6e264e3f8cea262aebdf14b5",
208+
"version_major": 2,
209+
"version_minor": 0
210+
},
211+
"text/plain": [
212+
"VBox(children=(ExperimentWidget(children=(HTML(value='\\n<h2>RandomBot Experiment #2 (ad01daa1-f7ed-43fa-ad6b-9…"
213+
]
214+
},
215+
"metadata": {},
216+
"output_type": "display_data"
217+
},
218+
{
219+
"name": "stdout",
220+
"output_type": "stream",
221+
"text": [
222+
"Ingesting dataset from ad01daa2-f7ed-43fa-ad6b-9928aa51f8e1-data.zip...\n"
223+
]
224+
},
225+
{
226+
"data": {
227+
"application/vnd.jupyter.widget-view+json": {
228+
"model_id": "0dc3e866a56a4200bd6028ec6a73d27b",
229+
"version_major": 2,
230+
"version_minor": 0
231+
},
232+
"text/plain": [
233+
"VBox(children=(ExperimentWidget(children=(HTML(value='\\n<h2>RandomBot Experiment #3 (ad01daa2-f7ed-43fa-ad6b-9…"
234+
]
235+
},
236+
"metadata": {},
237+
"output_type": "display_data"
238+
}
239+
],
240+
"source": [
241+
"print('Successfully collected data from {} bot experiments. Rendering replay widgets:'.format(len(data)))\n",
242+
"\n",
243+
"for exp_id in data:\n",
244+
" replay_exp = Griduniverse()\n",
245+
" replay_exp.task = data[exp_id]['title']\n",
246+
" replay_exp.jupyter_replay(\n",
247+
" app_id=exp_id,\n",
248+
" session=dallinger.db.init_db(drop_all=True),\n",
249+
" rows=ROWS, columns=COLS\n",
250+
" )"
251+
]
252+
},
253+
{
254+
"cell_type": "code",
255+
"execution_count": null,
256+
"metadata": {},
257+
"outputs": [],
258+
"source": []
259+
}
260+
],
261+
"metadata": {
262+
"kernelspec": {
263+
"display_name": "Python 2",
264+
"language": "python",
265+
"name": "python2"
266+
},
267+
"language_info": {
268+
"codemirror_mode": {
269+
"name": "ipython",
270+
"version": 3
271+
},
272+
"file_extension": ".py",
273+
"mimetype": "text/x-python",
274+
"name": "python",
275+
"nbconvert_exporter": "python",
276+
"pygments_lexer": "ipython3",
277+
"version": "3.6.5"
278+
}
279+
},
280+
"nbformat": 4,
281+
"nbformat_minor": 2
282+
}

bot_runs/bot_runs.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import csv
2+
from dallinger.experiments import Griduniverse
3+
4+
ROWS = 49
5+
COLS = 49
6+
ORIG_CSV_LIMIT = csv.field_size_limit(ROWS*COLS*1024)
7+
8+
BASE_ID = "{}01daa{}-f7ed-43fa-ad6b-9928aa51f8e1"
9+
PARTICIPANTS = 9
10+
NUM_AS_EXPERIMENTS = 3
11+
NUM_RANDOM_EXPERIMENTS = 3
12+
13+
EXP_CONFIG = {
14+
"recruiter": "bots",
15+
"max_participants": PARTICIPANTS,
16+
}
17+
18+
exp = Griduniverse()
19+
data = {}
20+
21+
print('Collecting {} experiments with {} AdvantageSeekingBot players'.format(
22+
NUM_AS_EXPERIMENTS, PARTICIPANTS
23+
))
24+
25+
for count in range(NUM_AS_EXPERIMENTS):
26+
exp_id = BASE_ID.format('ab', count)
27+
config = EXP_CONFIG.copy()
28+
config['bot_policy'] = 'AdvantageSeekingBot'
29+
data[exp_id] = {
30+
'title': '{} Experiment #{} ({})'.format(config['bot_policy'],
31+
count + 1, exp_id),
32+
'data': exp.collect(exp_id, exp_config=config)
33+
}
34+
35+
print('Collecting {} experiments with {} RandomBot players'.format(
36+
NUM_RANDOM_EXPERIMENTS, PARTICIPANTS
37+
))
38+
39+
for count in range(NUM_RANDOM_EXPERIMENTS):
40+
exp_id = BASE_ID.format('ad', count)
41+
config = EXP_CONFIG.copy()
42+
config['bot_policy'] = 'RandomBot'
43+
data[exp_id] = {
44+
'title': '{} Experiment #{} ({})'.format(config['bot_policy'],
45+
count + 1, exp_id),
46+
'data': exp.collect(exp_id, exp_config=config)
47+
}
48+
49+
print(
50+
'Successfully collected data from '
51+
'{} bot experiments. Rendering replay widgets:'.format(
52+
len(data))
53+
)
1.56 MB
Binary file not shown.
1.69 MB
Binary file not shown.
1.63 MB
Binary file not shown.
1.41 MB
Binary file not shown.
1.55 MB
Binary file not shown.
1.52 MB
Binary file not shown.

0 commit comments

Comments
 (0)