Send the Scan to the Cloud for analysis
July 23, 2015

The ScioCloud analyse function has the following parameters:

  • ScioReading: The sample data retrieved after a successful scan.
  • ModelId / List<ModelId>: ID of the model or a list of model id’s to compare the sample data to. You retrieve the model ID from the ScioModel object returned by the cloud.
  • ScioCloudAnalyzeCallback/ScioCloudAnalyzeManyCallback function: The callback object for the analyze function. This callback is called when the cloud sends back the analyzed scanned sample data with the results. The sample is analyzed, and in turn the ScioModel or List<ScioModel> objects are constructed and sent back to the mobile device.

The ScioCloudAnalyzeCallback/ScioCloudAnalyzeManyCallback  has two callback methods: onSuccess() and onError().

The onSuccess() method returns the data from the scanned sample including:

  • ScioModel/List<ScioModel>: ScioModel objects contains the model for the scanned sample including its specific attributes.

The onError function returns a String with an error message.

The following code sample sends a ScioReading to the cloud for analysis, retrieves the ScioModel and displays the information on the screen.

(Analyzing multiple models at once is not shown here but is done in the same way).

public void analyze(final ScioReading reading, final String modelId) {

   scioCloud.analyze(reading, modelId, new ScioCloudAnalyzeCallback() {
       @Override
       public void onSuccess(final ScioModel model) {

           List<ScioAttribute> modelAttributes = model.getAttributes();

           // model attribute for example
           ScioAttribute attribute = modelAttributes.get(0);

           String attributeType = attribute.getAttributeType().toString();
           String attributeUnit = attribute.getUnits();
           String attributeValue;

           switch (attribute.getAttributeType()) { 
               case STRING: 
                   attributeValue = ((ScioStringAttribute) attribute).getValue(); 
                    break; 
               case NUMERIC: 
                   attributeValue = String.valueOf(((ScioNumericAttribute) (attribute)).getValue()); 
                   break; 
              case DATE_TIME: 
                  attributeValue = ((ScioDatetimeAttribute) (attribute)).getValue().toString(); 
                  break;
               default: 
                   attributeValue = "N/A";
          } Log.i("DemoApp analyze", "Result model attribute type: " + attributeType); Log.i("DemoApp analyze", "Result model Get Units: " + attributeUnit); Log.i("DemoApp analyze", "Result model Value: " + attributeValue); 
      } 
      @Override 
      public void onError(int errorCode, String message) {
          Log.e("DemoApp analyze","on error: " + message); 
      } 
  }); 
}

 

Leave a Reply