1. Log in to the Azure portal at https://portal.azure.com➢ navigate to the Azure Stream Analytics job you created in Exercise 3.17➢ select Query from the Navigation menu ➢ select the Input Preview blade under the query window on the Query blade ➢ select the Upload Sample Input link ➢ upload the meditation.json file, which is located in the Chapter07/Ch07Ex02 directory on GitHub ➢ and then click OK. Figure 7.10 shows how the data should look after the upload.

FIGURE 7.10 Test sample data upload in Azure Stream Analytics

  1. Enter the following Azure Stream Analytics query into the query window; the query is in the StreamAnalyticsQuery.txt file on GitHub.
  1. Click the Test Query button. The result should resemble Figure 7.11.

FIGURE 7.11 The result of test data uploaded in Azure Stream Analytics

  1. Click the Save Query button.

In Exercise 7.2 you received a working query; however, it took some time to create the query to produce the desired output. This is a very useful approach for creating your streaming solution. The query selects the five frequency values from the input file, along with a timestamp. The timestamp is used with the GROUP BY clause along with the tumbling window with a 5‐second time interval. Placing the SELECT query, which calculates the median values of the brain wave input file over a 5‐second time frame, within the WITH clause creates the interface to access the results from another associated SELECT query. The results of the query are used to determine if the median brain wave value per frequency matches the ranges identified through the EDA in previous chapters. The EDA results are in Table 5.2. The logic to determine the brain wave scenario uses CASE WHEN T‐SQL statements, which are similar to if (), then {}, and else {} statements used in common programming languages like C#, Python, and Java. If any of the brain wave readings fall within the ranges identified as being from a meditation scenario, then “Meditation” is added as the value for the resulting Scenario column; otherwise, the value is “Unknown.”

Notice that the query code used here is T‐SQL and therefore abides by the declarative programming paradigm. Now that the input and output of the streamed data expected to flow through Azure Stream Analytics is clear, you will learn a bit more about Azure Event Hubs, implement the final solution in Azure Stream Analytics, and then configure Power BI to view the result of a meditation session in real time.

Katie Cox

Learn More

Leave a Reply

Your email address will not be published. Required fields are marked *