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.

  1. Import the following items:from collections import dequefrom IPython.lib import backgroundjobs as bg
  2. Create a double-ended queue (deque) that can hold up to 2000 tuples. Call it plotQueue.plotQueue = deque([], 2000)
  3. Start your data fetch and call it view.view = avgHrView.start_data_fetch()
  4. Create a data_collector­ function that iterates through the view and appends each value to the list.
    def data_collecter(view):
    for d in iter(view.get, None):
  5. Create an instance of the BackgroundJobManager class. Name it jobs.jobs = bg.BackgroundJobManager()
  6. Start a new background job and pass in both data_collecter and view.jobs.new(data_collecter, view)
  7. Run the cell.You won’t observe any output because it is merely saving your streams data in the background.
  8. 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.