From 995732bd5fcf8139ad8ce55099319a6f282acb82 Mon Sep 17 00:00:00 2001 From: charithag Date: Thu, 6 Aug 2015 18:48:20 +0530 Subject: [PATCH] Add commented stats emulation to test analytics --- .../jaggeryapps/iotserver/api/stats-api.jag | 42 ++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/api/stats-api.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/api/stats-api.jag index 28c260a3..f501793c 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/api/stats-api.jag +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/api/stats-api.jag @@ -49,7 +49,6 @@ if (uriMatcher.match("/{context}/api/stats")) { deviceId = request.getParameter("deviceId"); deviceType = request.getParameter("deviceType"); - log.info("deviceId : " + deviceId + " from : " + from + " to : " + to); getDeviceData(deviceType, deviceId); }else if (uriMatcher.match("/{context}/api/stats/group")){ @@ -58,7 +57,6 @@ if (uriMatcher.match("/{context}/api/stats")) { //URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/device/all var endPoint = deviceCloudService + "/group/id/" + groupId + "/device/all"; var data = {"username": user.username}; - log.info("ep: " + endPoint); var devices = get(endPoint, data, "json"); for (var device in devices.data){ @@ -132,6 +130,46 @@ function getSensebotData(user, device, from, to) { if (stats['temperatureData'] == null){ stats['temperatureData'] = []; } + + //Uncomment below section to emulate data + /* + var timeInterval = 30; + var i, rnd, chartData; + chartData = []; + var i = parseInt(from); + while (i < parseInt(to)) { + rnd = rnd = Math.random() * 50; + chartData.push({time: i, value: rnd}); + i += timeInterval; + } + stats['sonarData'].push({"device": device.name, "stats" : chartData}); + chartData = []; + var i = parseInt(from); + while (i < parseInt(to)) { + rnd = Math.round(Math.random()); + chartData.push({time: i, value: rnd}); + i += timeInterval; + } + stats['motionData'].push({"device": device.name, "stats" : chartData}); + chartData = []; + var i = parseInt(from); + while (i < parseInt(to)) { + rnd = Math.round(Math.random()); + chartData.push({time: i, value: rnd}); + i += timeInterval; + } + stats['lightData'].push({"device": device.name, "stats" : chartData}); + chartData = []; + var i = parseInt(from); + while (i < parseInt(to)) { + rnd = Math.random() * (27 - 24) + 24; + chartData.push({time: i, value: rnd}); + i += timeInterval; + } + stats['temperatureData'].push({"device": device.name, "stats" : chartData}); + */ + + //Comment below section to emulate data stats['sonarData'].push({"device": device.name, "stats" : getSensorData("SONAR_SENSOR_SUMMARY", "sonar", user, device.deviceIdentifier, from, to)}); stats['motionData'].push({"device": device.name, "stats" : getSensorData("PIR_MOTION_SENSOR_SUMMARY", "motion", user, device.deviceIdentifier, from, to)}); stats['lightData'].push({"device": device.name, "stats" : getSensorData("LDR_LIGHT_SENSOR_SUMMARY", "light", user, device.deviceIdentifier, from, to)});