Skip to content

Commit 3f39719

Browse files
committed
Converted all functions from Mongo to CouchDB
1 parent 21d9faa commit 3f39719

File tree

3 files changed

+313
-176
lines changed

3 files changed

+313
-176
lines changed

.ipynb_checkpoints/Untitled-checkpoint.ipynb

Lines changed: 138 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
},
6565
{
6666
"cell_type": "code",
67-
"execution_count": 33,
67+
"execution_count": 2,
6868
"metadata": {},
6969
"outputs": [],
7070
"source": [
@@ -87,24 +87,14 @@
8787
},
8888
{
8989
"cell_type": "code",
90-
"execution_count": 34,
90+
"execution_count": null,
9191
"metadata": {},
92-
"outputs": [
93-
{
94-
"name": "stdout",
95-
"output_type": "stream",
96-
"text": [
97-
"a2bd5c89-e9cb-490e-a8d0-c6c1f40153a6-bluemix 20e2923d8817e8c5bb111c39e477d6275e278a792a40339e3fe5c9ca8127055c https://a2bd5c89-e9cb-490e-a8d0-c6c1f40153a6-bluemix.cloudantnosqldb.appdomain.cloud/\n"
98-
]
99-
}
100-
],
101-
"source": [
102-
"print (username, password, url)"
103-
]
92+
"outputs": [],
93+
"source": []
10494
},
10595
{
10696
"cell_type": "code",
107-
"execution_count": 35,
97+
"execution_count": 4,
10898
"metadata": {},
10999
"outputs": [],
110100
"source": [
@@ -115,7 +105,7 @@
115105
},
116106
{
117107
"cell_type": "code",
118-
"execution_count": 40,
108+
"execution_count": 5,
119109
"metadata": {},
120110
"outputs": [
121111
{
@@ -135,7 +125,7 @@
135125
},
136126
{
137127
"cell_type": "code",
138-
"execution_count": 86,
128+
"execution_count": 6,
139129
"metadata": {},
140130
"outputs": [],
141131
"source": [
@@ -152,7 +142,7 @@
152142
},
153143
{
154144
"cell_type": "code",
155-
"execution_count": 89,
145+
"execution_count": 8,
156146
"metadata": {},
157147
"outputs": [
158148
{
@@ -161,28 +151,28 @@
161151
"text": [
162152
"User ID not found, creating new document\n",
163153
"{\n",
164-
" \"session_id\": \"793de5df-a016-45dc-80fa-9b9cddd33103\"\n",
154+
" \"session_id\": \"1ae29197-9939-42aa-ac5b-aa7c334e2dee\"\n",
165155
"}\n"
166156
]
167157
},
168158
{
169159
"data": {
170160
"text/plain": [
171-
"'793de5df-a016-45dc-80fa-9b9cddd33103'"
161+
"'1ae29197-9939-42aa-ac5b-aa7c334e2dee'"
172162
]
173163
},
174-
"execution_count": 89,
164+
"execution_count": 8,
175165
"metadata": {},
176166
"output_type": "execute_result"
177167
}
178168
],
179169
"source": [
180-
"getSessionID('test6')"
170+
"getSessionID('test')"
181171
]
182172
},
183173
{
184174
"cell_type": "code",
185-
"execution_count": 73,
175+
"execution_count": 9,
186176
"metadata": {},
187177
"outputs": [],
188178
"source": [
@@ -197,27 +187,27 @@
197187
},
198188
{
199189
"cell_type": "code",
200-
"execution_count": 80,
190+
"execution_count": 14,
201191
"metadata": {},
202192
"outputs": [
203193
{
204194
"data": {
205195
"text/plain": [
206-
"'ibm_assistant'"
196+
"'test'"
207197
]
208198
},
209-
"execution_count": 80,
199+
"execution_count": 14,
210200
"metadata": {},
211201
"output_type": "execute_result"
212202
}
213203
],
214204
"source": [
215-
"getReceiver('test2')"
205+
"getReceiver('test')"
216206
]
217207
},
218208
{
219209
"cell_type": "code",
220-
"execution_count": 77,
210+
"execution_count": 12,
221211
"metadata": {},
222212
"outputs": [],
223213
"source": [
@@ -232,7 +222,47 @@
232222
},
233223
{
234224
"cell_type": "code",
235-
"execution_count": 78,
225+
"execution_count": 26,
226+
"metadata": {},
227+
"outputs": [
228+
{
229+
"data": {
230+
"text/plain": [
231+
"True"
232+
]
233+
},
234+
"execution_count": 26,
235+
"metadata": {},
236+
"output_type": "execute_result"
237+
}
238+
],
239+
"source": [
240+
"updateUserType('test2','doctor')"
241+
]
242+
},
243+
{
244+
"cell_type": "code",
245+
"execution_count": 18,
246+
"metadata": {},
247+
"outputs": [],
248+
"source": [
249+
"def setupConnection(user1, user2): \n",
250+
" if user1 not in usersDB or user2 not in usersDB:\n",
251+
" return False\n",
252+
" \n",
253+
" userDoc1 = usersDB[user1]\n",
254+
" userDoc1['receiver'] = user2\n",
255+
" userDoc1.save()\n",
256+
" userDoc2 = usersDB[user2]\n",
257+
" userDoc2['receiver'] = user1\n",
258+
" userDoc2.save()\n",
259+
" \n",
260+
" return True"
261+
]
262+
},
263+
{
264+
"cell_type": "code",
265+
"execution_count": 20,
236266
"metadata": {},
237267
"outputs": [
238268
{
@@ -241,21 +271,97 @@
241271
"True"
242272
]
243273
},
244-
"execution_count": 78,
274+
"execution_count": 20,
245275
"metadata": {},
246276
"output_type": "execute_result"
247277
}
248278
],
249279
"source": [
250-
"updateUserType('test','Community')"
280+
"setupConnection('test','test2')"
281+
]
282+
},
283+
{
284+
"cell_type": "code",
285+
"execution_count": 21,
286+
"metadata": {},
287+
"outputs": [],
288+
"source": [
289+
"def breakConnection(user1, user2):\n",
290+
" if user1 not in usersDB or user2 not in usersDB:\n",
291+
" return False\n",
292+
" \n",
293+
" userDoc1 = usersDB[user1]\n",
294+
" userDoc1['receiver'] = IBM_RECEIVER\n",
295+
" userDoc1.save()\n",
296+
" userDoc2 = usersDB[user2]\n",
297+
" userDoc2['receiver'] = IBM_RECEIVER\n",
298+
" userDoc2.save()\n",
299+
" \n",
300+
" return True"
301+
]
302+
},
303+
{
304+
"cell_type": "code",
305+
"execution_count": 22,
306+
"metadata": {},
307+
"outputs": [
308+
{
309+
"data": {
310+
"text/plain": [
311+
"True"
312+
]
313+
},
314+
"execution_count": 22,
315+
"metadata": {},
316+
"output_type": "execute_result"
317+
}
318+
],
319+
"source": [
320+
"breakConnection('test','test2')"
321+
]
322+
},
323+
{
324+
"cell_type": "code",
325+
"execution_count": 29,
326+
"metadata": {},
327+
"outputs": [],
328+
"source": [
329+
"def findDoctor():\n",
330+
" for user in usersDB:\n",
331+
" if user['type'] == TYPE_DOCTOR and user['receiver'] == IBM_RECEIVER:\n",
332+
" return user['_id']\n",
333+
" return None"
334+
]
335+
},
336+
{
337+
"cell_type": "code",
338+
"execution_count": 30,
339+
"metadata": {},
340+
"outputs": [
341+
{
342+
"name": "stdout",
343+
"output_type": "stream",
344+
"text": [
345+
"test2\n"
346+
]
347+
}
348+
],
349+
"source": [
350+
"print (findDoctor())"
251351
]
252352
},
253353
{
254354
"cell_type": "code",
255355
"execution_count": null,
256356
"metadata": {},
257357
"outputs": [],
258-
"source": []
358+
"source": [
359+
"def findCommunity():\n",
360+
" for user in usersDB:\n",
361+
" if user['type'] == TYPE_COMMUNITY and user['receiver'] == IBM_RECEIVER:\n",
362+
" return user['_id']\n",
363+
" return None"
364+
]
259365
},
260366
{
261367
"cell_type": "code",

0 commit comments

Comments
 (0)