Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Create an execution plan to publish the data received to an output stream. For more information on creating execution plans, see the WSO2 Data Analytics Server (WSO2 DAS) documentation.

Follow the steps given below:

...

Follow the steps given below to create a script that summarizes and presents the average battery level of the device every hour. For more information on creating scripts, see the WSO2 Data Analytics Server (WSO2 DAS) documentation.

  1. On the Main tab click Scripts that is under Batch Analytics.
  2. Click Add New Analytics Scripts.
  3. Give the script a name, such as battery_data_analytics.
  4. Copy the script given below to the Spark SQL Queries text box.

    Code Block
     CREATE TEMPORARY TABLE BatteryData USING CarbonAnalytics OPTIONS(tableName "ORG_WSO2_IOT_BATTERYSTREAM", incrementalParams "ORG_WSO2_IOT_BATTERYSTREAM, HOUR");
        
     CREATE TEMPORARY TABLE Battery_Level_Per_Hour USING CarbonAnalytics
     OPTIONS (tableName "Battery_Level_Per_Hour",
     schema "deviceId STRING, type STRING, level DOUBLE -i, year INT -i, month INT -i, day INT -i, hour INT -i,
     timestamp LONG", primaryKeys "year, month, day, hour, deviceId, type", mergeSchema "false");
    
     INSERT INTO TABLE Battery_Level_Per_Hour
     SELECT meta_deviceId as deviceId, meta_deviceType as type, avg(level) as level, year, month, day, hour, getHourStartingTime(year, month, day, hour) as   timestamp
     FROM BatteryData
     GROUP BY meta_deviceId, meta_deviceType, year, month, day, hour; 
         
    
    
     INCREMENTAL_TABLE_COMMIT ORG_WSO2_IOT_BATTERYSTREAM;
    Note

    Make sure to add a space when starting each new line in the script. If you copy the script given above, it has the spaces set by default.

    Image Added

  5. Enter 0 0 0/1 1/1 * ? * as the value for the Cron Expression.
    This field is used to determine how often the analytics script needs to be executed. In this sample, we have configured the script to run every minute.
  6. Click Add.

...