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 c1af157b..9f3fa5fb 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/api/stats-api.jag +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/api/stats-api.jag @@ -31,118 +31,111 @@ var statsClient = new Packages.org.wso2.carbon.device.mgt.iot.common.analytics.s if (uriMatcher.match("/{context}/api/stats")) { - deviceId = request.getParameter("deviceId"); - deviceType = request.getParameter("deviceType"); - from = request.getParameter("from"); - to = request.getParameter("to"); - - user = session.get(constants.USER_SESSION_KEY); - if (!user) { - response.sendRedirect(dcProps.appContext + "login?#login-required"); - exit(); - } - - log.info("deviceId : " + deviceId + " from : " + from + " to : " + to); - - switch (deviceType){ - case "firealarm": - result = getFireAlarmData(user.username, deviceId, from, to); - break; - case "sensebot": - result = getSensebotData(user.username, deviceId, from, to); - break; - case "arduino": - result = getArduinoData(user.username, deviceId, from, to); - break; - case "digital_display": - result = getDigitalDisplayData(user.username, deviceId, from, to); - break; - case "android_sense": - result = getAndroidSenseData(user.username, deviceId, from, to); - break; - case "raspberrypi": - result = getDigitalDisplayData(user.username, deviceId, from, to); - break; - default: - result = new Object(); - } + deviceId = request.getParameter("deviceId"); + deviceType = request.getParameter("deviceType"); + from = request.getParameter("from"); + to = request.getParameter("to"); + + user = session.get(constants.USER_SESSION_KEY); + if (!user) { + response.sendRedirect(dcProps.appContext + "login?#login-required"); + exit(); + } + + log.info("deviceId : " + deviceId + " from : " + from + " to : " + to); + + switch (deviceType) { + case "firealarm": + result = getFireAlarmData(user.username, deviceId, from, to); + break; + case "sensebot": + result = getSensebotData(user.username, deviceId, from, to); + break; + case "arduino": + result = getArduinoData(user.username, deviceId, from, to); + break; + case "digital_display": + result = getDigitalDisplayData(user.username, deviceId, from, to); + break; + case "android_sense": + result = getAndroidSenseData(user.username, deviceId, from, to); + break; + case "raspberrypi": + result = getDigitalDisplayData(user.username, deviceId, from, to); + break; + default: + result = new Object(); + } } // returning the result. if (result) { - print(result); + print(result); } -function getFireAlarmData(user, deviceId, from, to){ - result = new Object(); - result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY","TEMPERATURE",user, deviceId, from, to); - result['fanData'] = getSensorData("DEVICE_FAN_USAGE_SUMMARY","status",user, deviceId, from, to); - result['bulbData'] = getSensorData("DEVICE_BULB_USAGE_SUMMARY","status",user, deviceId, from, to); - return result; +function getFireAlarmData(user, deviceId, from, to) { + result = new Object(); + result['cpuTemperatureData'] = getSensorData("DEVICE_CPU_TEMPERATURE_SUMMARY", "TEMPERATURE", user, deviceId, from, to); + result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY", "TEMPERATURE", user, deviceId, from, to); + result['fanData'] = getSensorData("DEVICE_FAN_USAGE_SUMMARY", "status", user, deviceId, from, to); + result['bulbData'] = getSensorData("DEVICE_BULB_USAGE_SUMMARY", "status", user, deviceId, from, to); + return result; } -function getSensebotData(user, deviceId, from, to){ - result = new Object(); - result['sonarData'] = getSensorData("SONAR_SENSOR_SUMMARY","sonar",user, deviceId, from, to); - result['motionData'] = getSensorData("PIR_MOTION_SENSOR_SUMMARY","motion",user, deviceId, from, to); - result['lightData'] = getSensorData("LDR_LIGHT_SENSOR_SUMMARY","light",user, deviceId, from, to); - result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY","TEMPERATURE",user, deviceId, from, to); - return result; +function getSensebotData(user, deviceId, from, to) { + result = new Object(); + result['sonarData'] = getSensorData("SONAR_SENSOR_SUMMARY", "sonar", user, deviceId, from, to); + result['motionData'] = getSensorData("PIR_MOTION_SENSOR_SUMMARY", "motion", user, deviceId, from, to); + result['lightData'] = getSensorData("LDR_LIGHT_SENSOR_SUMMARY", "light", user, deviceId, from, to); + result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY", "TEMPERATURE", user, deviceId, from, to); + return result; } -function getArduinoData(user, deviceId, from, to){ - result = new Object(); - result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY","TEMPERATURE",user, deviceId, from, to); - return result; +function getArduinoData(user, deviceId, from, to) { + result = new Object(); + result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY", "TEMPERATURE", user, deviceId, from, to); + return result; } -function getDigitalDisplayData(user, deviceId, from, to){ - result = new Object(); - result['ramData'] = getSensorData("RAM_USAGE_SUMMARY","motion",user, deviceId, from, to); - result['cpuData'] = getSensorData("CPU_LOAD_SUMMARY","light",user, deviceId, from, to); - result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY","TEMPERATURE",user, deviceId, from, to); - return result; +function getAndroidSenseData(user, deviceId, from, to) { + result = new Object(); + result['ramData'] = getSensorData("RAM_USAGE_SUMMARY", "motion", user, deviceId, from, to); + result['cpuData'] = getSensorData("CPU_LOAD_SUMMARY", "light", user, deviceId, from, to); + result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY", "TEMPERATURE", user, deviceId, from, to); + result['motionData'] = getSensorData("PIR_MOTION_SENSOR_SUMMARY", "motion", user, deviceId, from, to); + return result; } -function getAndroidSenseData(user, deviceId, from, to){ - result = new Object(); - result['ramData'] = getSensorData("RAM_USAGE_SUMMARY","motion",user, deviceId, from, to); - result['cpuData'] = getSensorData("CPU_LOAD_SUMMARY","light",user, deviceId, from, to); - result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY","TEMPERATURE",user, deviceId, from, to); - result['motionData'] = getSensorData("PIR_MOTION_SENSOR_SUMMARY","motion",user, deviceId, from, to); - return result; -} - -function getDigitalDisplayData(user, deviceId, from, to){ - result = new Object(); - result['ramData'] = getSensorData("RAM_USAGE_SUMMARY","motion",user, deviceId, from, to); - result['cpuData'] = getSensorData("CPU_LOAD_SUMMARY","light",user, deviceId, from, to); - result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY","TEMPERATURE",user, deviceId, from, to); - return result; +function getDigitalDisplayData(user, deviceId, from, to) { + result = new Object(); + result['ramData'] = getSensorData("RAM_USAGE_SUMMARY", "motion", user, deviceId, from, to); + result['cpuData'] = getSensorData("CPU_LOAD_SUMMARY", "light", user, deviceId, from, to); + result['cpuTemperatureData'] = getSensorData("DEVICE_CPU_TEMPERATURE_SUMMARY", "TEMPERATURE", user, deviceId, from, to); + return result; } function getSensorData(table, column, user, deviceId, from, to) { - var fetchedData = null; + var fetchedData = null; - try { - fetchedData = statsClient.getDeviceStats(table, column, user, deviceId, from, to); - }catch(error){ - log.error(error); - } + try { + fetchedData = statsClient.getDeviceStats(table, column, user, deviceId, from, to); + } catch (error) { + log.error(error); + } - var sensorData = []; + var sensorData = []; - if(fetchedData==null) return []; + if (fetchedData == null) return []; - for (var i = 0; i < fetchedData.size(); i++) { - sensorData.push({ - time: fetchedData.get(i).getTime(), - value: fetchedData.get(i).getValue() - }); - } + for (var i = 0; i < fetchedData.size(); i++) { + sensorData.push({ + time: fetchedData.get(i).getTime(), + value: fetchedData.get(i).getValue() + }); + } - return sensorData; + return sensorData; } %> \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/analytics/analytics.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/analytics/analytics.hbs index 9575d03e..27abf139 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/analytics/analytics.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/analytics/analytics.hbs @@ -48,6 +48,8 @@