Skip to content

Interpretation

Jane edited this page Feb 23, 2016 · 20 revisions

Overview

Data interpretation is the process that turns raw data collected from the Wearable Devices into insights about the user's current situation, context, activity, mood and more.

After you've successfully connected to the device and managed to get the necessary data, the next step would usually be interpreting that data. Data Interpretation requires the utilization of an interpretation algorithm. You can either use one of the readily available algorithms (Fall Detection or Excessive Temperature Detection) or utilize the SDK to build your own custom interpretation code.

Interpreting raw data using an existing algorithm

To interpret the data you should register interpretation classes using the MobileEdgeController class. This normally requires three steps:

  1. Create an instance of your interpretation class.
  2. Register a listener to the newly created instance to receive notifications when interpretation occurs.
  3. Register the newly created interpretation class in the system using the MobileEdgeController.

The registration of the interpretation class can be achieved using a single call to the registerInterpretation method of the MobileEdgeController.

Example: Registering a FallDetection interpretation

//create new instance of the 'FallDetection' class 
let fallDetection = FallDetection()

//register an instance of 'FallDetection' with listener function 'fallDetected'
controller.registerInterpretation(fallDetection, withListener: fallDetected)
     
//this function will be called when a fall of the device is detected
func fallDetected(additonalInfo: AnyObject!) {
     print("A fall of the device was detected!")     
}

Defining a custom interpretation algorithm

You can define your own interpretation classes and register them using the MobileEdgeController class.

To create a new interpretation class, follow these steps:

  1. Create a class that extends the BaseInterpretation class.
  2. Initialize your class with a name relevant to the type of interpretation (for example "High Temperature Detection").
  3. Register listeners for the sensors required by your interpretation.
  4. Implement the logic of the interpretation.

Example: Identifying excessive temperature

In this example, we will create a simple algorithm that identifies a situation of excessive temperature (for simplicity, let's say it occurs when the temperature measured by the sensor exceeds 80°F).

We will now create a new interpretation called HighTemperatureDetection.

Example: Defining the HighTemperatureDetection class

//Step 1: create class that extends BaseInterpretation
class HighTemperatureDetection : BaseInterpretation {
      
      init(){
          //Step 2: initialize the class using a custom interpretation name
          super.init(interpretationName: "High Temperature Detection")
      }
     
      //Step 3: register the interpretation to use the temperature sensor
      override func registerForEvents(sensors: Sensors) {
          //here you define that the interpretation will use only the temperature sensor
          sensors.temperature.registerListener(temperatureDataChanged)
      }
     
      //Step 4: implement the logic of the interpretation
      func temperatureDataChanged(data:TemperatureData){
          
          //this method will be called every time the temperature is changed.
          //here you decide how to act once the temperature data is changed
          if (data.temperature > 80){
              notifyResult()  //calls the interpretation listener
          }
      }
}

Once you have created your custom interpretation, you can register it as described in the previous section.

Example: Using the custom HighTemperatureDetection interpretation class

//create a new instance of the 'HighTemperatureDetection' class 
//and register it with the listener function 'highTemperatureDetected'   
controller.registerInterpretation(HighTemperatureDetection(), withListener: highTemperatureDetected)
  
//this function will be called once the temperature of the device exceeds 80°F
func highTemperatureDetected(additonalInfo: AnyObject!) {
     print("The temperature of the device exceeds 80°F")
}

Clone this wiki locally