<commit_before>/*
 * JobServiceID:
 * urn:moat:${APPID}:plant-monitoring:upload-sensing-data:1.0
 * 
 * Description: Notify captured image to the Web UI application.
 */
var moat = require('moat');
var context = moat.init();
var session = context.session;
var clientRequest = context.clientRequest;
var logTag = 'upload-sensing-data'

var WEBAPI_SENSING_DATA = 'https://plant-monitoring-test.herokuapp.com/contents/notify_sensing_data/';
//var WEBAPI_SENSING_DATA = 'http://localhost:3000/contents/notify_sensing_data/';

session.log(logTag, '--- Data arrived ---');

var objects = clientRequest.objects;
if (objects.length != 1) {
  throw '*** ERROR!! *** invalid object length:' + objects.length;
}

var array = rawDataToNotifyData(objects[0].array);
notifyData(clientRequest.device.deviceId, array);

function rawDataToNotifyData(rawArray) {
  var array = [];
  for (var i = 0; i < rawArray.length; i++) {
    var e = rawArray[i];
    var entity = {
      uid : e.uid,
      serialNumber : e.serialNumber,
      temperature : e.temperature,
      humidity : e.humidity,
      moisture : e.moisture,
      timestamp : e.timestamp
    };
    array.push(entity);
  }
  return array;
}
function notifyData(deviceId, rawData) {
  session.fetchUrlSync(
    WEBAPI_SENSING_DATA,
    {
      method : 'POST',
      contentType : 'application/json',
      payload : {
        deviceId : deviceId,
        array: array
      }
    },
    function(response) {
      if (parseInt(response.responseCode / 100) == 2) {
        session.log(logTag, 'Notified');
      } else {
        session.log(logTag, '*** ERROR!! *** resp code: ' + response.responseCode);<commit_msg>string to float<commit_after>/*
 * JobServiceID:
 * urn:moat:${APPID}:plant-monitoring:upload-sensing-data:1.0
 * 
 * Description: Notify captured image to the Web UI application.
 */
var moat = require('moat');
var context = moat.init();
var session = context.session;
var clientRequest = context.clientRequest;
var logTag = 'upload-sensing-data'

var WEBAPI_SENSING_DATA = 'https://plant-monitoring-test.herokuapp.com/contents/notify_sensing_data/';
//var WEBAPI_SENSING_DATA = 'http://localhost:3000/contents/notify_sensing_data/';

session.log(logTag, '--- Data arrived ---');

var objects = clientRequest.objects;
if (objects.length != 1) {
  throw '*** ERROR!! *** invalid object length:' + objects.length;
}

var array = rawDataToNotifyData(objects[0].array);
notifyData(clientRequest.device.deviceId, array);

function rawDataToNotifyData(rawArray) {
  var array = [];
  for (var i = 0; i < rawArray.length; i++) {
    var e = rawArray[i];
    var entity = {
      uid : e.uid,
      serialNumber : e.serialNumber,
      temperature : parseFloat(e.temperature),
      humidity : parseFloat(e.humidity),
      moisture : e.moisture,
      timestamp : e.timestamp
    };
    array.push(entity);
  }
  return array;
}
function notifyData(deviceId, rawData) {
  session.fetchUrlSync(
    WEBAPI_SENSING_DATA,
    {
      method : 'POST',
      contentType : 'application/json',
      payload : {
        deviceId : deviceId,
        array: array
      }
    },
    function(response) {
      if (parseInt(response.responseCode / 100) == 2) {
        session.log(logTag, 'Notified');
      } else {
        session.log(logTag, '*** ERROR!! *** resp code: ' + response.responseCode);
{'fraction_non_alphanumeric': 0.14354066985645933, 'fraction_numerical': 0.00777511961722488, 'mean_word_length': 3.3385214007782102, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7383087', 'n_tokens_mistral': 1099, 'n_tokens_neox': 1082, 'n_words': 223}