Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 84cad92

Browse files
committed
fixed geo-streaming example
1 parent da36063 commit 84cad92

File tree

2 files changed

+35
-79
lines changed

2 files changed

+35
-79
lines changed

_posts/user_guide_python/2015-06-30-geo-streaming.html

Lines changed: 19 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ <h2 id="Streaming-to-a-Map-and-Geo-Streaming">Streaming to a Map and Geo-Streami
5353
</div>
5454
<div class="cell border-box-sizing code_cell rendered">
5555
<div class="input">
56-
<div class="prompt input_prompt">In&nbsp;[42]:</div>
56+
<div class="prompt input_prompt">In&nbsp;[18]:</div>
5757
<div class="inner_cell">
5858
<div class="input_area">
5959
<div class=" highlight hl-ipython2"><pre><span class="c"># (*) Import plotly package</span>
@@ -71,11 +71,11 @@ <h2 id="Streaming-to-a-Map-and-Geo-Streaming">Streaming to a Map and Geo-Streami
7171
<div class="output">
7272

7373

74-
<div class="output_area"><div class="prompt output_prompt">Out[42]:</div>
74+
<div class="output_area"><div class="prompt output_prompt">Out[18]:</div>
7575

7676

7777
<div class="output_text output_subarea output_execute_result">
78-
<pre>&apos;1.9.9&apos;</pre>
78+
<pre>&apos;1.9.10&apos;</pre>
7979
</div>
8080

8181
</div>
@@ -96,7 +96,7 @@ <h2 id="Streaming-to-a-Map-and-Geo-Streaming">Streaming to a Map and Geo-Streami
9696
</div>
9797
<div class="cell border-box-sizing code_cell rendered">
9898
<div class="input">
99-
<div class="prompt input_prompt">In&nbsp;[6]:</div>
99+
<div class="prompt input_prompt">In&nbsp;[19]:</div>
100100
<div class="inner_cell">
101101
<div class="input_area">
102102
<div class=" highlight hl-ipython2"><pre><span class="c"># (*) To communicate with Plotly&#39;s server</span>
@@ -148,7 +148,7 @@ <h4 id="Getting-Set-Up">Getting Set Up<a class="anchor-link" href="#Getting-Set-
148148
</div>
149149
<div class="cell border-box-sizing code_cell rendered">
150150
<div class="input">
151-
<div class="prompt input_prompt">In&nbsp;[7]:</div>
151+
<div class="prompt input_prompt">In&nbsp;[20]:</div>
152152
<div class="inner_cell">
153153
<div class="input_area">
154154
<div class=" highlight hl-ipython2"><pre><span class="kn">import</span> <span class="nn">pandas</span> <span class="kn">as</span> <span class="nn">pd</span>
@@ -172,7 +172,7 @@ <h4 id="Getting-Set-Up">Getting Set Up<a class="anchor-link" href="#Getting-Set-
172172
</div>
173173
<div class="cell border-box-sizing code_cell rendered">
174174
<div class="input">
175-
<div class="prompt input_prompt">In&nbsp;[48]:</div>
175+
<div class="prompt input_prompt">In&nbsp;[21]:</div>
176176
<div class="inner_cell">
177177
<div class="input_area">
178178
<div class=" highlight hl-ipython2"><pre><span class="n">stream_tokens</span> <span class="o">=</span> <span class="n">tls</span><span class="o">.</span><span class="n">get_credentials_file</span><span class="p">()[</span><span class="s">&#39;stream_ids&#39;</span><span class="p">]</span>
@@ -211,7 +211,7 @@ <h4 id="Getting-Set-Up">Getting Set Up<a class="anchor-link" href="#Getting-Set-
211211
</div>
212212
<div class="cell border-box-sizing code_cell rendered">
213213
<div class="input">
214-
<div class="prompt input_prompt">In&nbsp;[50]:</div>
214+
<div class="prompt input_prompt">In&nbsp;[22]:</div>
215215
<div class="inner_cell">
216216
<div class="input_area">
217217
<div class=" highlight hl-ipython2"><pre><span class="n">stream_id</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">token</span><span class="o">=</span><span class="n">token</span><span class="p">,</span> <span class="n">maxpoints</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
@@ -226,7 +226,7 @@ <h4 id="Getting-Set-Up">Getting Set Up<a class="anchor-link" href="#Getting-Set-
226226
<div class="output">
227227

228228

229-
<div class="output_area"><div class="prompt output_prompt">Out[50]:</div>
229+
<div class="output_area"><div class="prompt output_prompt">Out[22]:</div>
230230

231231

232232
<div class="output_text output_subarea output_execute_result">
@@ -260,7 +260,7 @@ <h4 id="Getting-Set-Up">Getting Set Up<a class="anchor-link" href="#Getting-Set-
260260
</div>
261261
<div class="cell border-box-sizing code_cell rendered">
262262
<div class="input">
263-
<div class="prompt input_prompt">In&nbsp;[54]:</div>
263+
<div class="prompt input_prompt">In&nbsp;[23]:</div>
264264
<div class="inner_cell">
265265
<div class="input_area">
266266
<div class=" highlight hl-ipython2"><pre><span class="n">data</span> <span class="o">=</span> <span class="p">[</span><span class="nb">dict</span><span class="p">(</span>
@@ -277,8 +277,9 @@ <h4 id="Getting-Set-Up">Getting Set Up<a class="anchor-link" href="#Getting-Set-
277277
<span class="n">width</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
278278
<span class="n">color</span><span class="o">=</span><span class="s">&#39;rgba(102, 102, 102)&#39;</span>
279279
<span class="p">),</span>
280-
<span class="n">stream</span><span class="o">=</span><span class="n">stream_id</span>
281-
<span class="p">))]</span>
280+
<span class="p">),</span>
281+
<span class="n">stream</span><span class="o">=</span><span class="n">stream_id</span><span class="p">,</span>
282+
<span class="n">name</span><span class="o">=</span><span class="s">&quot;Plane&quot;</span><span class="p">)]</span>
282283

283284
<span class="n">layout</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span>
284285
<span class="n">title</span> <span class="o">=</span> <span class="s">&#39;Busy Airplane Streaming&#39;</span><span class="p">,</span>
@@ -307,7 +308,7 @@ <h4 id="Getting-Set-Up">Getting Set Up<a class="anchor-link" href="#Getting-Set-
307308
<div class="output">
308309

309310

310-
<div class="output_area"><div class="prompt output_prompt">Out[54]:</div>
311+
<div class="output_area"><div class="prompt output_prompt">Out[23]:</div>
311312

312313
<div class="output_html rendered_html output_subarea output_execute_result">
313314
<iframe id="igraph" scrolling="no" style="border:none;" seamless="seamless" src="https://plot.ly/~demo_account/21.embed" height="525px" width="100%"></iframe>
@@ -331,7 +332,7 @@ <h4 id="Getting-Set-Up">Getting Set Up<a class="anchor-link" href="#Getting-Set-
331332
</div>
332333
<div class="cell border-box-sizing code_cell rendered">
333334
<div class="input">
334-
<div class="prompt input_prompt">In&nbsp;[57]:</div>
335+
<div class="prompt input_prompt">In&nbsp;[24]:</div>
335336
<div class="inner_cell">
336337
<div class="input_area">
337338
<div class=" highlight hl-ipython2"><pre><span class="n">s</span> <span class="o">=</span> <span class="n">py</span><span class="o">.</span><span class="n">Stream</span><span class="p">(</span><span class="n">stream_id</span><span class="o">=</span><span class="n">token</span><span class="p">)</span>
@@ -357,7 +358,7 @@ <h4 id="Start-Streaming">Start Streaming<a class="anchor-link" href="#Start-Stre
357358
<div class="inner_cell">
358359
<div class="text_cell_render border-box-sizing rendered_html">
359360
<p>Below we'll wrap the relevant code to generate the data stream into a function we call <code>lets_stream()</code>.
360-
We will also follow up with a while loop that will keep our stream up persistently.</p>
361+
We will also follow up with a while loop that will keep our stream up persistently. Notice that the small green dot is the departing airport, the red dot is the arrival airport, and the blue dot is the plane!</p>
361362

362363
</div>
363364
</div>
@@ -367,7 +368,10 @@ <h4 id="Start-Streaming">Start Streaming<a class="anchor-link" href="#Start-Stre
367368
<div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div>
368369
<div class="inner_cell">
369370
<div class="input_area">
370-
<div class=" highlight hl-ipython2"><pre><span class="k">def</span> <span class="nf">lets_stream</span><span class="p">():</span>
371+
<div class=" highlight hl-ipython2"><pre><span class="kn">import</span> <span class="nn">datetime</span>
372+
<span class="kn">import</span> <span class="nn">time</span>
373+
374+
<span class="k">def</span> <span class="nf">lets_stream</span><span class="p">():</span>
371375

372376
<span class="n">s</span><span class="o">.</span><span class="n">open</span><span class="p">()</span>
373377

@@ -419,40 +423,4 @@ <h4 id="Start-Streaming">Start Streaming<a class="anchor-link" href="#Start-Stre
419423
</div>
420424
</div>
421425

422-
<div class="output_wrapper">
423-
<div class="output">
424-
425-
426-
<div class="output_area"><div class="prompt"></div>
427-
<div class="output_subarea output_stream output_stdout output_text">
428-
<pre>Server responded with status code: 404
429-
and message: streamtoken not registered or valid.
430-
Server responded with status code: 404
431-
and message: streamtoken not registered or valid.
432-
Server responded with status code: 404
433-
and message: streamtoken not registered or valid.
434-
Server responded with status code: 404
435-
and message: streamtoken not registered or valid.
436-
Server responded with status code: 404
437-
and message: streamtoken not registered or valid.
438-
Server responded with status code: 404
439-
and message: streamtoken not registered or valid.
440-
Server responded with status code: 404
441-
and message: streamtoken not registered or valid.
442-
Server responded with status code: 404
443-
and message: streamtoken not registered or valid.
444-
Server responded with status code: 404
445-
and message: streamtoken not registered or valid.
446-
Server responded with status code: 404
447-
and message: streamtoken not registered or valid.
448-
Server responded with status code: 404
449-
and message: streamtoken not registered or valid.
450-
Server responded with status code: 404
451-
and message: streamtoken not registered or valid.</pre>
452-
</div>
453-
</div>
454-
455-
</div>
456-
</div>
457-
458426
</div>{% endraw %}

_posts/user_guide_python/geo-streaming.ipynb

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
},
3333
{
3434
"cell_type": "code",
35-
"execution_count": 1,
35+
"execution_count": 18,
3636
"metadata": {
3737
"collapsed": false
3838
},
@@ -43,7 +43,7 @@
4343
"'1.9.10'"
4444
]
4545
},
46-
"execution_count": 1,
46+
"execution_count": 18,
4747
"metadata": {},
4848
"output_type": "execute_result"
4949
}
@@ -65,7 +65,7 @@
6565
},
6666
{
6767
"cell_type": "code",
68-
"execution_count": 2,
68+
"execution_count": 19,
6969
"metadata": {
7070
"collapsed": false
7171
},
@@ -109,7 +109,7 @@
109109
},
110110
{
111111
"cell_type": "code",
112-
"execution_count": 3,
112+
"execution_count": 20,
113113
"metadata": {
114114
"collapsed": false
115115
},
@@ -128,7 +128,7 @@
128128
},
129129
{
130130
"cell_type": "code",
131-
"execution_count": 4,
131+
"execution_count": 21,
132132
"metadata": {
133133
"collapsed": false
134134
},
@@ -156,7 +156,7 @@
156156
},
157157
{
158158
"cell_type": "code",
159-
"execution_count": 5,
159+
"execution_count": 22,
160160
"metadata": {
161161
"collapsed": false
162162
},
@@ -167,7 +167,7 @@
167167
"{'maxpoints': 3, 'token': u'4lm5a0gsr8'}"
168168
]
169169
},
170-
"execution_count": 5,
170+
"execution_count": 22,
171171
"metadata": {},
172172
"output_type": "execute_result"
173173
}
@@ -193,7 +193,7 @@
193193
},
194194
{
195195
"cell_type": "code",
196-
"execution_count": 6,
196+
"execution_count": 23,
197197
"metadata": {
198198
"collapsed": false
199199
},
@@ -207,7 +207,7 @@
207207
"<plotly.tools.PlotlyDisplay object>"
208208
]
209209
},
210-
"execution_count": 6,
210+
"execution_count": 23,
211211
"metadata": {},
212212
"output_type": "execute_result"
213213
}
@@ -227,8 +227,9 @@
227227
" width=1,\n",
228228
" color='rgba(102, 102, 102)'\n",
229229
" ),\n",
230-
" stream=stream_id\n",
231-
" ))]\n",
230+
" ),\n",
231+
" stream=stream_id,\n",
232+
" name=\"Plane\")]\n",
232233
"\n",
233234
"layout = dict(\n",
234235
" title = 'Busy Airplane Streaming',\n",
@@ -258,7 +259,7 @@
258259
},
259260
{
260261
"cell_type": "code",
261-
"execution_count": 7,
262+
"execution_count": 24,
262263
"metadata": {
263264
"collapsed": false
264265
},
@@ -279,29 +280,16 @@
279280
"metadata": {},
280281
"source": [
281282
"Below we'll wrap the relevant code to generate the data stream into a function we call `lets_stream()`.\n",
282-
"We will also follow up with a while loop that will keep our stream up persistently."
283+
"We will also follow up with a while loop that will keep our stream up persistently. Notice that the small green dot is the departing airport, the red dot is the arrival airport, and the blue dot is the plane!"
283284
]
284285
},
285286
{
286287
"cell_type": "code",
287-
"execution_count": 8,
288+
"execution_count": null,
288289
"metadata": {
289290
"collapsed": false
290291
},
291-
"outputs": [
292-
{
293-
"ename": "KeyboardInterrupt",
294-
"evalue": "",
295-
"output_type": "error",
296-
"traceback": [
297-
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
298-
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
299-
"\u001b[0;32m<ipython-input-8-79700bba9edc>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 42\u001b[0m \u001b[0;32mwhile\u001b[0m \u001b[0mTrue\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 43\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 44\u001b[0;31m \u001b[0mlets_stream\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 45\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 46\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'log.txt'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'a+'\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
300-
"\u001b[0;32m<ipython-input-8-79700bba9edc>\u001b[0m in \u001b[0;36mlets_stream\u001b[0;34m()\u001b[0m\n\u001b[1;32m 35\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msleep\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mabs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstall\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m0.01\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0;36m2.0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 36\u001b[0m \u001b[0ms\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mheartbeat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 37\u001b[0;31m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msleep\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mabs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstall\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m0.01\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0;36m2.0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 38\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 39\u001b[0m \u001b[0mdepart\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0marrive\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
301-
"\u001b[0;31mKeyboardInterrupt\u001b[0m: "
302-
]
303-
}
304-
],
292+
"outputs": [],
305293
"source": [
306294
"import datetime\n",
307295
"import time\n",

0 commit comments

Comments
 (0)