2. Fetch view data
Do your development for this section in the coding cell under Lab 4 – Visualize data in Python notebook > Step 2a – Fetch view data. Do not copy and paste your application from previous steps into this cell; this will be a separate code segment.
- Import the following items:
from collections import deque
from IPython.lib import backgroundjobs as bg
- Create a double-ended queue (deque) that can hold up to 2000 tuples. Call it
plotQueue = deque(, 2000)
- Start your data fetch and call it
view = avgHrView.start_data_fetch()
- Create a data_collector function that iterates through the view and appends each value to the list.
for d in iter(view.get, None):
- Create an instance of the BackgroundJobManager class. Name it
jobs = bg.BackgroundJobManager()
- Start a new background job and pass in both
- Run the cell.You won’t observe any output because it is merely saving your streams data in the background.
- Run the third cell under Lab 4 – Visualize data in Python notebook> Step 2b – Visualize view data using Matplotlib.This cell contains everything you need to create a plot for your data view.A data plot should appear under this last cell and update in real time with the average heart rate data from your streaming application. With data visualization tools like this, you don’t even need to go into the Streams Console to see the outputs of your program.
You have now learned not only to create a life-like Streams application in the Python language, but also to generate visuals for your data.