Академический Документы
Профессиональный Документы
Культура Документы
for
WSO2 Data Analytics Server 3.1.0
Developer Fundamentals
Email: training@wso2.com
Lab:Creating Dashboards
Note: The participants are expected to be connected to the internet throughout in order to
successfully complete the lab exercises.
Business Scenario
Smarthome Info is a large scale supplier of electricity with customers spread in 10 states of
USA. Customers consist of houses and households.
This company needs to carry out detailed analysis for large volumes of data relating to the
electricity usage of all its customers in order to optimize its production and distribution of energy
based on the demand.
Detailed Instructions
Download and Install WSO2 DAS
To download WSO2 DAS:
1. Visit the WSO2 DAS home page and click DOWNLOAD. This downloads WSO2 DAS as
a zip file.
2. Unzip the zip file in a preferred location in your machine. As a result, a directory named
WSO2DAS-<VERION_NO> is created. This directory is referred to as the <DAS_HOME>
throughout this lab kit.
https://<DAS_HOST>:<DAS_PORT>
The DAS host is the local host. You can use localhost or the number of the local host in the URL.
The default DAS port is 9443. If required, it can be changed by using the following property with the
command to start the server.
-DportOffset n
When trying this lab kit, you can use admin as both the username and the password to log into the
DAS Management Console.
Business Scenario
Info Smart Homes company is a power supplier. It needs to collect data relating to the power usage
over time of the houses that are its customers. A unit of data that is collected over time should have
the following information.
● ID
● Value
● Property
● Plug ID
● Household ID
● House ID
Here we assume a hierarchical structure with a house, identified by a unique house ID being the
topmost entity. Every house contains one or more household identified by a unique household
ID (within a house). Every household contains one or more smart plugs, each identified by a
unique plug ID (within a household). Every smart plug contains two sensors:
1. A load sensor that measures the current load with Watt as a unit.
2. A work sensor measuring the total accumulated work since the start (or reset) of the
sensor with kWh as a unit.
Detailed Instructions
In order to capture units of data with the information given above, we need to create an event
stream. The event stream should have a unique attribute for each item of information mentioned
above. All the units of data that have values to match all the attributes in the stream are selected into
the event flow of WSO2 DAS.
Follow the steps below to create an event stream to capture data as required.
id string
value float
property bool
plug_id int
household_id int
house_id int
Follow steps 1-5 given above to define another stream to be used as the output stream.The
parameter and attribute values should be as follows.
Parameter Value
house_id int
maxVal float
minVal float
avgVal double
timestamp long
Business Scenario
Info Smart Home receives data in the wso2event format.
Detailed Instructions
An event receiver is required to receive events in the wso2event format and then direct them to the
SMARTHOME_DATA. event stream. Follow the steps below to create an event receiver of the
wso2event type.
1. Log in to the DAS Management Console, if you are not already logged in.
ain, and then click Receivers.
2. Click M
3. Click A dd Event Receiver, and enter the details as shown below.
Parameter Value
Expected Outcome
The DATA_RECEIVER receiver is saved and is displayed in the Available Event Receivers as
follows.
Business Scenario
Info Smart Home needs to print the list of processed events in a CLI log.
Detailed Instructions
In order to print the processed events in a CLI log, an event publisher of the logger type should be
defined. The processed events should be published from the SMARTHOME_DATA event stream
because the processed events are directed to that stream.
1. Log in to the DAS Management Console, if you are not already logged in.
ain, and then click Publishers to open the Available Event Publishers page.
2. Click M
3. Click A dd Event Publisher to open the Create a New Event Publisher page and enter
information as follows.
Training Objective
Write Siddhi queries to analyze data real time.
Business Scenario
Average, minimum and maximum usage needs to be calculated for the events in the
SMARTHOME_DATA event stream, and the processed events with these values should be inserted
into the usageStream.
Detailed Instructions
Follow the steps below to add an execution plan.
1. Log into the DAS Management Console if you are not already logged in.
2. In the Main tab, click Execution Plans to open the Available Execution Plans page.
dd Execution Plan to open the Create a New Execution Plan page.
3. Click A
@Import('SMARTHOME_DATA:1.0.0')
define stream inputStream (id string, value float, property bool,
plug_id int, household_id int, house_id int);
5. In the Export Stream field, select usageStream:1.0.0. Then enter outputStream in the
Value Of field and click Export. This adds the following query that adds the usageStream
stream as the output stream to which values processed are exported.
@Export('usageStream:1.0.0')
7. Click Validate Query Expressions to verify whether the queries entered are valid.
8. Click A dd Execution Plan to save the queries.
Expected Outcome
Once the execution plan is created and saved, it is displayed in the Available Execution Plans
page as follows.
Detailed Instructions
Follow the steps below to view the event flow.
1. Log into the DAS Management Console if you are not already logged in.
2. In the Main tab, click Flow to open the CEP Event Flow page.
Expected Outcome
The event flow is displayed as follows.
Business Scenario
Info Smart Home needs to publish a single event in the wso2event format.
Detailed Instructions
1. Log into the WSO2 DAS Management Console if you are not already logged in.
2. In the Tools tab, click Event Simulator to open the Event Stream Simulator page.
3. Select the SMART_HOME_DATA:1.0.0 stream in the Event Stream Name field.
4. Enter values for the available attributes as follows.
Attribute Value
id 3655509222
property FALSE
plug_id 5
household_id 2
house_id 10
Expected Outcome
A message appears to confirm that the event is successfully sent.
Business Scenario
Info Smart Home needs to publish the data to be analyzed in WSO2 DAS
Detailed Instructions
Follow the steps below to upload a file with events in the wso2event format to be analyzed using
WSO2 DAS.
1. Log into the WSO2 DAS Management Console if you are not already logged in.
2. In the Tools tab, click Event Simulator to open the Event Stream Simulator page.
3. Select the SMART_HOME_DATA:1.0.0 stream in the Event Stream Name field.
4. Download the sample.csv file in a location in your machine.
5. Click Choose File in the Event Stream Simulator page and browse for the sample.csv
file. Then click Upload. Click OK in the message that appears to confirm that the file was
successfully uploaded. Refresh the page. The uploaded file is displayed as follows.
Expected Outcome
A message appears to confirm that the event publishing has started.
The events sent are logged in the CLI as shown in the extract below, by the logger publisher
you previously created.
Business Scenario
The data captured by Info Smart Homes needs to be stored in the database in order to carry out
batch analytics as well as to carry out searches.
Detailed Instructions
In order to store the data captured by an event stream in databases, the event stream should be
persisted. Follow the steps below to persist the SMARTHOME_DATA and usageStream event
streams.
1. Log into the WSO2 Management Console if you are not already logged in.
2. In the Main tab, click Streams to open the Available Event Streams page.
dit for the SMART_HOME_DATA:1.0.0 stream to open the Edit Event Stream page.
3. Click E
Then click Next [Persist Event].
4. Select the Persist Event Stream check box to store information in the
SMART_HOME_DATA:1.0.0 stream to databases.
5. Select the Persist Attribute check box for each attribute in the stream. This ensures that all
the attribute values specified in events are stored in the database.
6. Select the Primary Key check box for the id, household_id and the house_id attributes.
This allows you to search for single events by a specific combination of values for these
three attributes.
Expected Outcome
A message appears to confirm whether you want to update the event stream. Click Yes in the
message.
Business Scenario
The usage (i.e., the difference between the maximum usage and the minimum usage) should be
calculated for each event, and this information needs to be saved in a temporary table. Then the
events where the usage is greater than 30 should be filtered and saved in another table.
Prerequisite
Before you create the Spark Scripts given below and execute them, generate events to be
persisted in the system for Batch analytics by repeating Lab: Publishing Multiple Events.
Detailed Instructions
Follow the steps below to add Apache Spark queries to process events as described in the above
business scenario.
1. Log into the Management Console if you are not already logged in.
2. In the Main tab, click Scripts to open the Available Analytics Scripts page.
3. Click Add New Analytics Script to open the Add New Analytics Script page.
4. Enter Batch_Analytics in the Script Name field.
5. Enter the following Spark queries in the Spark SQL Queries field, and click Add.
Expected Outcome
Once the queries are successfully executed, the results are displayed as follows.
Training Objective
Learn how to use the Spark Console to execute Spark queries for faster results.
Business Scenario
Info Smarthomes need to execute a quick query to filter events where the plug usage is greater
than 100.
Detailed Instructions
1. Log into the DAS Management Console if you are not already logged in.
2. In the Main tab, click Console to open the Interactive Analytics Console.
3. Enter the following command in the console and click Enter.
Expected Outcome
The output is displayed as follows.
Business Scenario
Info Smarthomes need to to search for the following events.
● The single event that with the following properties.
○ House ID - 39
○ Household ID - 11
○ ID - 3655508728
● All the records relating to house number 8.
Detailed Instructions
1. Log into the DAS Management Console if you are not already logged in.
2. In the Main tab, click Data Explorer to open the Data Explorer page.
3. In the Table Name field, select the SMARTHOME_DATA table and click Search. This fetches
all the records that are currently stored in this table as shown below.
4. Select the By Primary Key option. As a result, the house_id and the id fields are displayed
as shown below.
5. Enter values for each field as follows and click Search.
Attribute Value
house_id 39
household_id 11
id
3655508728
This fetches a single record with the primary key combination given above as follows.
Each event should have a unique primary key combination. Therefore, a search by
primary key should always fetch just one event.
6. Select the By Query option. As a result, a field for search queries is displayed as follows.
For more detailed information of all the possible searches that can be carried out in WSO2 DAS,
see WSO2 Data Analytics Server Documentation - Searching for Data.
Expected Outcome
The first query by the unique primary key combination fetches a single event as follows.
Business Scenario
The Data Analyst at Smarthome Info needs the following information.
● A list of all the available analytics tables in the WSO2 DAS system containing
information relating to the business.
● The details saved in these tables.
● All the records relating to house number 8, sorted by the ID.
● The count of records relating to house number 8.
● The schema of the SMARTHOME_DATA table.
Detailed Instructions
Follow the steps below to obtain the information mentioned above.
Note: Before you follow this exercise, follow the instructions on adding a basic auth header.
Expected Outcome
The table below shows the expected return for each cURL command.
Note: The return might vary depending on the amount of data you have simulated.
Fetch information in all the tables This fetches all the data is all the existing
tables. The following example is an
curl -H "Content-Type:
extract.
application/json" -H
[{"id":"45896194-1372-4b2c-13
"Authorization: Basic
YWRtaW46YWRtaW4=" 1d-740da92e9dc3","tableName":
[{"id":"f075cb02-8ef0-97bb-3b
Fetch all records for house 8
86-973bebd7a212","tableName":
curl -X POST -H "Content-Type: "SMARTHOME_DATA","timestamp":
application/json" -H 1484116852062,"values":{"hous
"Authorization: Basic e_id":8,"household_id":0,"pro
YWRtaW46YWRtaW4=" perty":false,"plug_id":5,"id"
https://localhost:9443/analytics/s
:"3655509020","_version":"1.0
earch -d
'{"tableName":"SMARTHOME_DATA",
.0","value":0.0}},{"id":"ecbd
"query":"house_id:8", "start":0, 55d9-a534-a4ac-38d6-39ee01134
"count":3, "sortBy" : [{"field" : 742","tableName":"SMARTHOME_D
"id", "sortType" : "ASC"}]}' -k ATA","timestamp":148411686107
2,"values":{"house_id":8,"hou
sehold_id":1,"property":false
,"plug_id":4,"id":"3655509029
","_version":"1.0.0","value":
0.517}},{"id":"7e30c466-2677-
4fbe-e2f8-78c23f9dbbb8","tabl
eName":"SMARTHOME_DATA","time
stamp":1484116864077,"values"
:{"house_id":8,"household_id"
:1,"property":false,"plug_id"
:5,"id":"3655509032","_versio
n":"1.0.0","value":41.675}}]
The count of records relating to house 8 This returns a number that equals the
number of records relating to house 8.
curl -X POST -H "Content-Type:
application/json" -H
"Authorization: Basic
YWRtaW46YWRtaW4="
https://localhost:9443/analytics/s
Business Scenario
NOTE: A different dataset is used in this lab exercise. The Smart Home Info example will be
continued to be used after this lab exercise.
High-level Steps
1. Create a dataset
2. Create a project
3. Create an analysis
4. Predict using the model
Detailed Instructions
Create a Dataset
Follow the steps below to upload the dataset based on which the training model is created.
1. Access the WSO2 Machine Learner wizard embedded within DAS via the
https://<DAS_HOME>:<DAS_PORT/ml/site/home/login.jag URL, and login with
Version 1.0.0
Create a Project
Follow the procedure below to create a project for the dataset uploaded.
1. Log into the Machine Learner wizard of WSO2 DAS if you are not already logged in. You can
access it with the https://<DAS_HOME>:<DAS_PORT/ml/site/home/login.jag URL,
and login with your credentials.
2. Click Add Project.
Dataset Breast_Cancer_Dataset
Create an Analysis
Follow the procedure below to analyse the Breast_Cancer_Dataset dataset, and then create a
training model based on that analysis.
1. Log into the Machine Learner wizard if you are not already logged in. You can access it with
the https://<DAS_HOME>:<DAS_PORT/ml/site/home/login.jag URL, and login
with your credentials.
2. Click the You have X projects link as shown below.
The Explore view opens. Note that Parallel Sets and Trellis Chart visualizations are
enabled, and Scatter Plot and Cluster Diagram visualizations are disabled. This is
determined by the feature types of the dataset.
8. Click Next. The Model view appears. Select Breast_Cancer_Dataset-1.0.0 as the dataset
version.
SampleCodeNumber 1018561
UniformityOfCellSize 1
UniformityOfCell Shape 1
MarginalAdhesion 1
SingleEpithelialCellSize 2
BareNuclei 1
BlandChromati 1
NormalNucleoli 1
Mitoses 5
Business Scenario
Smarthome Info needs a visual representation of the change in the maximum usage, minimum
usage and the average usage over time.
Detailed Instructions
1. Access the WSO2 DAS analytics Dashboard using the
https://<DAS_HOST>:<DAS_PORT>/portal URL, and log in with your credentials.
2. Click the menu icon (shown below) and then click Gadgets to open the Gadgets page.
Field Value
This is the event table from which data is fetched to update the gadget. Click the Test
Connection to test whether the gadget is successfully connected to that table. If the
5. Click Show Data to preview the data that is already available in the event table. A table with
a sample of the data already available in the USAGESTREAM event table is displayed as
Parameter Value
X Axis timestamp
X Type time
Y Axis maxVal
Y Type number
Max Length 30
Two more gadgets are required for this scenario. In order to create them, repeat steps 1-5 above,
and enter information in the Configure Chart page as follows.
Parameter Value
X Axis timestamp
X Type time
Y Axis avgVal
Y Type number
Max Length 30
Parameter Value
X Axis timestamp
X Type time
Y Axis minVal
Y Type number
Max Length 30
Click Add to Store to save the gadget configurations.
Business Scenario
A dashboard is required to place the three gadgets you created in the previous exercise.
Detailed Instructions
1. Access the WSO2 DAS analytics Dashboard using the
https://<DAS_HOST>:<DAS_PORT>/portal URL, and log in with your credentials.
2. Click CREATE DASHBOARD to open the Create a Dashboard Wizard.
3. Enter basic information for the dashboard as follows, and click Next.
Field Value
5. Click the icon for gadgets. Then drag and drop the MaxPowerUsagePerHouse,
AvgPowerUsagePerHouse, and MinPowerUsagePerHouse gadgets to the columns in the
dashboard as demonstrated in the example below.
When you click View, the gadgets you added to it are displayed as follows.
Business Scenario
Smarthome Info needs a template for an event stream, an event publisher and an execution
plan because it needs to create all three artifacts multiple times with similar configurations.
Detailed Instructions
Create Basic Template
In this exercise, a basic template is created and saved as a file. The required event stream and
execution plan configurations are added in the later exercises.
Create an XML file with the following configuration and save it in the
<DAS_HOME>/repository/conf/template-manager/domain template directory as
PowerConsumptionAlerts.xml.
<?xml version="1.0"?>
<!--
~ Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights
Reserved.
~
~ WSO2 Inc. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
<domain name="PowerConsumptionAlerts">
<description>Domain for power consumption alerts</description>
<scenarios>
<scenario type="PowerConsumptionAlerts">
<description>Configure a scenario to notify power
consumption alerts.
</description>
<templates>
<!--Note: These will be deployed in the order they appear here-->
<template type="eventstream">
<!--A Stream Definition Template here-->
</template>
<template type="realtime">
<!--An Execution Plan Template here-->
</template>
<template type="eventreceiver">
<!--An Event Receiver Template here-->
</template>
<template type="eventpublisher">
<!--An Event Publisher Template here-->
</template>
<template type="gadget">
<!--A Gadget Template here-->
</template>
<template type="dashboard">
<!--A Dashboard Template here-->
</template>
</templates>
<streamMappings>
<!--Define stream mappings here-->
</streamMappings>
<parameters>
<!--Define parameters here-->
</parameters>
</scenario>
</scenarios>
<domain name="PowerConsumptionAlerts">
<description>Domain for Power Consumption Alerts</description>
<scenarios>
<scenario type="PowerConsumptionAlerts">
<description>Configure a scenario to notify power consumption
alerts.
</description>
<templates>
<!--Note: These will be deployed in the order they appear
here-->
<template type="eventstream">
<!--A Stream Definition Template here-->
</template>
<template type="realtime">
<!--An Execution Plan Template here-->
</template>
<template type="eventreceiver">
<!--An Event Receiver Template here-->
</template>
<template type="eventpublisher">
<!--An Event Publisher Template here-->
</template>
<template type="gadget">
<!--A Gadget Template here-->
</template>
<template type="dashboard">
<!--A Dashboard Template here-->
</template>
</templates>
<streamMappings>
{
"streamId":"House$houseIdAlertStream:1.0.0",
"name":"House$houseIdAlertStream",
"version":"1.0.0",
"nickName":"",
"description":"",
"metaData":[
],
"correlationData":[
],
"payloadData":[
{
"name":"house_id",
"type":"INT"
},
{
"name":"type",
"type":"STRING"
},
{
"streamId":"House$houseIdAlertStream:1.0.0",
"name":"House$houseIdAlertStream",
"version":"1.0.0",
"nickName":"",
"description":"",
"metaData":[
],
"correlationData":[
],
"payloadData":[
"name":"house_id",
"type":"INT"
},
"name":"type",
"type":"STRING"
},
"type":"STRING"
<template type="realtime">
<![CDATA[@Plan:name('House$houseIdPowerConsumptionAlerts')
@Import('SMARTHOME_DATA:1.0.0')
define stream dataIn (id string, value float, property bool,
plug_id int, household_id int, house_id int);
@Export('House$houseIdAlertStream:1.0.0')
define stream alertStream (house_id int, type string, message
string);
</template>
</template>
<parameters>
<parameter name="houseId" type="int">
<displayName>House ID</displayName>
<description>ID of the House</description>
<defaultValue>39</defaultValue>
</parameter>
<parameter name="maxValue" type="long">
<displayName>Maximum threshold</displayName>
<description>Maximum threshold value</description>
<defaultValue>100</defaultValue>
</parameter>
<parameter name="minValue" type="long">
<displayName>Minimum threshold</displayName>
<description>Minimum threshold value</description>
<defaultValue>10</defaultValue>
</parameter>
</parameters>
Business Scenario
Smarthome Info needs:
● A new execution plan that uses the existing Smarthome_Data stream as the input
stream.
● A new event stream that serves as the output stream to the new execution plan.
Detailed Instructions
Follo2
1. Log into the WSO2 DAS Management Console. (If the DAS server was already running
at the time you created the template, you need to restart it.
2. In the Main tab, click Template Manager to open the Domains page. The
PowerConsumptionAlerts template is displayed as shown below.
4. Click Create New Scenario to open the Edit Scenario page, and enter information as
follows.
Field Value
House ID 39
Minimum Threshold 10
Expected Outcome
The scenario is added to the list of deployed scenarios as shown below.
● To view details of the execution plan, open the Main => Execution Plans => Available
Execution Plans page and click
PowerConsumptionAlerts-PowerConsumptionAlerts-UsageHouse39-realtime1.
● ain => Event Streams => Available Event
To view details of the event stream, open the M
Streams page and click House39AlertStream:1.0.0.
For more information, see WSO2 Clustering Guide - Minimum High Availability Deployment -
DAS 3.1.0.
Business Scenario
Smarthome Info needs to ensure high system availability to ensure that it suffers no loss as a
result of system failure.
Detailed Instructions
For detailed instructions, see WSO2 Clustering Guide - Minimum High Availability Deployment -
DAS 3.1.0.