Versions Compared

Key

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

In this tutorial, you get the average of a device's battery level, and create the Battery_Level_Per_Hour table by analyzing the data gathered from all the enrolled devices.

MobX creates new mobile applications or sends updates to corporate mobile applications. These applications need to be installed on the user's devices. To ensure that the applications are successfully installed or updated on all the enrolled devices successfully, all the devices need to have a battery level of 50% or above. Using the steps given below, MobX administrators are able to identify the devices that had less battery power when an application installation request was pushed and confirm with those users if the application was installed successfully.

...

  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 a new line in the script. If you copy the script given above, it has the spaces set by default.

  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.

...