Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
update notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Nov 16, 2019
1 parent 35c3a69 commit b785161
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 49 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -546,3 +546,6 @@ _doc/notebooks/td2a_eco2/*pocket.json
_doc/sphinxdoc/source/plot_pypi.py
_unittests/ut_data/DEAL Flow automatisation 2019.xlsx
_unittests/ut_data/Jeu de données deal flow 2018.csv
_doc/notebooks/2a/twitter_for_network_100000.db.zip
_doc/notebooks/2a/twitter_for_network_100000.db
_doc/notebooks/2a/tw_users.json
135 changes: 86 additions & 49 deletions _doc/notebooks/2a/seance_5_intro_et_json.ipynb
Expand Up @@ -21,12 +21,12 @@
"<script>\n",
"function repeat_indent_string(n){\n",
" var a = \"\" ;\n",
" for ( ; n > 0 ; --n) {\n",
" for ( ; n > 0 ; --n)\n",
" a += \" \";\n",
" }\n",
" return a;\n",
"}\n",
"var update_menu_string = function(begin, lfirst, llast, sformat, send, keep_item) {\n",
"// look up into all sections and builds an automated menu //\n",
"var update_menu_string = function(begin, lfirst, llast, sformat, send, keep_item, begin_format, end_format) {\n",
" var anchors = document.getElementsByClassName(\"section\");\n",
" if (anchors.length == 0) {\n",
" anchors = document.getElementsByClassName(\"text_cell_render rendered_html\");\n",
Expand All @@ -39,9 +39,9 @@
" var href;\n",
" var tags = [];\n",
" var main_item = 0;\n",
" for (i = 0; i <= llast; i++) {\n",
" var format_open = 0;\n",
" for (i = 0; i <= llast; i++)\n",
" tags.push(\"h\" + i);\n",
" }\n",
"\n",
" for (i = 0; i < anchors.length; i++) {\n",
" text_memo += \"**\" + anchors[i].id + \"--\\n\";\n",
Expand All @@ -54,7 +54,7 @@
"break;\n",
" }\n",
" }\n",
" if (child == null){\n",
" if (child == null) {\n",
" text_memo += \"null\\n\";\n",
" continue;\n",
" }\n",
Expand Down Expand Up @@ -82,15 +82,16 @@
" continue ;\n",
" }\n",
" if (title.endsWith('\u00b6')) {\n",
" title = title.substring(0,title.length-1).replace(\"<\", \"&lt;\").replace(\">\", \"&gt;\").replace(\"&\", \"&amp;\")\n",
" title = title.substring(0,title.length-1).replace(\"<\", \"&lt;\")\n",
" .replace(\">\", \"&gt;\").replace(\"&\", \"&amp;\");\n",
" }\n",
"\n",
" if (title.length == 0) {\n",
" continue;\n",
" }\n",
"\n",
" while (level < memo_level) {\n",
" text_menu += \"</ul>\\n\";\n",
" text_menu += end_format + \"</ul>\\n\";\n",
" format_open -= 1;\n",
" memo_level -= 1;\n",
" }\n",
" if (level == lfirst) {\n",
Expand All @@ -104,22 +105,33 @@
" text_menu += \"<ul>\\n\";\n",
" memo_level += 1;\n",
" }\n",
" text_menu += repeat_indent_string(level-2) + sformat.replace(\"__HREF__\", href).replace(\"__TITLE__\", title);\n",
" text_menu += repeat_indent_string(level-2);\n",
" text_menu += begin_format + sformat.replace(\"__HREF__\", href).replace(\"__TITLE__\", title);\n",
" format_open += 1;\n",
" }\n",
" while (1 < memo_level) {\n",
" text_menu += \"</ul>\\n\";\n",
" text_menu += end_format + \"</ul>\\n\";\n",
" memo_level -= 1;\n",
" format_open -= 1;\n",
" }\n",
" text_menu += send;\n",
" //text_menu += \"\\n\" + text_memo;\n",
"\n",
" while (format_open > 0) {\n",
" text_menu += end_format;\n",
" format_open -= 1;\n",
" }\n",
" return text_menu;\n",
"};\n",
"var update_menu = function() {\n",
" var sbegin = \"\";\n",
" var sformat = '<li><a href=\"#__HREF__\">__TITLE__</a></li>';\n",
" var sformat = '<a href=\"#__HREF__\">__TITLE__</a>';\n",
" var send = \"\";\n",
" var begin_format = '<li>';\n",
" var end_format = '</li>';\n",
" var keep_item = -1;\n",
" var text_menu = update_menu_string(sbegin, 2, 4, sformat, send, keep_item);\n",
" var text_menu = update_menu_string(sbegin, 2, 4, sformat, send, keep_item,\n",
" begin_format, end_format);\n",
" var menu = document.getElementById(\"my_id_menu_nb\");\n",
" menu.innerHTML=text_menu;\n",
"};\n",
Expand Down Expand Up @@ -160,7 +172,7 @@
{
"data": {
"text/plain": [
"['twitter_for_network_100000.db']"
"['.\\\\twitter_for_network_100000.db']"
]
},
"execution_count": 3,
Expand All @@ -182,16 +194,44 @@
"name": "stdout",
"output_type": "stream",
"text": [
"User defined method or cross-method\n",
"10 loops, best of 3: 26.4 ms per loop\n",
"10 loops, best of 3: 20.9 ms per loop\n",
"100 loops, best of 3: 13 ms per loop\n",
"100 loops, best of 3: 10.8 ms per loop\n",
"User defined method or cross-method\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\python372_x64\\lib\\site-packages\\ipykernel_launcher.py:6: RuntimeWarning: overflow encountered in long_scalars\n",
" \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"21.3 ms \u00b1 548 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 10 loops each)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\python372_x64\\lib\\site-packages\\ipykernel_launcher.py:1: RuntimeWarning: overflow encountered in long_scalars\n",
" \"\"\"Entry point for launching an IPython kernel.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"17.1 ms \u00b1 611 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 100 loops each)\n",
"6.24 ms \u00b1 274 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 100 loops each)\n",
"4.95 ms \u00b1 658 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 100 loops each)\n",
"Builtin function\n",
"100 loops, best of 3: 3.81 ms per loop\n",
"1.54 ms \u00b1 80.8 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 1000 loops each)\n",
"Numpy function\n",
"10000 loops, best of 3: 84.4 \u00b5s per loop\n",
"10000 loops, best of 3: 82.2 \u00b5s per loop\n"
"49.6 \u00b5s \u00b1 366 ns per loop (mean \u00b1 std. dev. of 7 runs, 10000 loops each)\n",
"50.4 \u00b5s \u00b1 4.17 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 10000 loops each)\n"
]
}
],
Expand Down Expand Up @@ -275,7 +315,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Memory used : 108 MB\n"
"Memory used : 114 MB\n"
]
}
],
Expand All @@ -286,9 +326,7 @@
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"import cytoolz as ct # import groupby, valmap, compose\n",
Expand Down Expand Up @@ -340,7 +378,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Memory used : 112 MB\n"
"Memory used : 120 MB\n"
]
}
],
Expand Down Expand Up @@ -521,8 +559,7 @@
" 'user_mentions': [{'id': 551669623,\n",
" 'id_str': '551669623',\n",
" 'indices': [97, 112],\n",
" 'name': 'Fran\u00e7ois '\n",
" 'Fillon',\n",
" 'name': 'Fran\u00e7ois Fillon',\n",
" 'screen_name': 'FrancoisFillon'}]},\n",
" 'favorite_count': 4,\n",
" 'favorited': False,\n",
Expand All @@ -543,13 +580,12 @@
" 'source': '<a href=\"http://www.apple.com\" '\n",
" 'rel=\"nofollow\">iOS</a>',\n",
" 'text': '#Agriculture : \"Le plan du Gouvernement '\n",
" \"n'apporte aucune solution durable aux \"\n",
" 'fili\u00e8res en crise\" @FrancoisFillon '\n",
" \"n'apporte aucune solution durable aux fili\u00e8res \"\n",
" 'en crise\" @FrancoisFillon '\n",
" 'http://t.co/wZ3HkhHvuM',\n",
" 'truncated': False,\n",
" 'user': {'contributors_enabled': False,\n",
" 'created_at': 'Thu Apr 23 12:27:59 +0000 '\n",
" '2009',\n",
" 'created_at': 'Thu Apr 23 12:27:59 +0000 2009',\n",
" 'default_profile': False,\n",
" 'default_profile_image': False,\n",
" 'description': '#CM #ComPol #SocialMedia '\n",
Expand Down Expand Up @@ -726,17 +762,22 @@
"metadata": {},
"outputs": [],
"source": [
"import psycopg2\n",
"from psycopg2.extras import Json\n",
"\n",
"db_name = 'cours_ensae'\n",
"conn_string = \"host='localhost' dbname='{0}' user='python' password='kyojin'\".format( db_name )\n",
"try:\n",
" conn_psql = psycopg2.connect(conn_string)\n",
" cursor_psql = conn_psql.cursor()\n",
" import psycopg2\n",
" from psycopg2.extras import Json\n",
" postgre_ok = True\n",
"except psycopg2.OperationalError:\n",
" postgre_ok = False "
"except ImportError:\n",
" postgre_ok = False\n",
"\n",
"if postgre_ok:\n",
" db_name = 'cours_ensae'\n",
" conn_string = \"host='localhost' dbname='{0}' user='python' password='kyojin'\".format( db_name )\n",
" try:\n",
" conn_psql = psycopg2.connect(conn_string)\n",
" cursor_psql = conn_psql.cursor()\n",
" postgre_ok = True\n",
" except psycopg2.OperationalError:\n",
" postgre_ok = False "
]
},
{
Expand All @@ -752,9 +793,7 @@
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"if postgre_ok:\n",
Expand Down Expand Up @@ -962,9 +1001,7 @@
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": []
}
Expand All @@ -985,7 +1022,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
"version": "3.7.2"
},
"widgets": {
"state": {},
Expand Down

0 comments on commit b785161

Please sign in to comment.