Merge pull request #143 from ayyoob/das-ext

resolving coffeecup issues
merge-requests/1/head
Milan Perera 9 years ago
commit 77a22bcd5c

@ -38,10 +38,10 @@
log4j.rootLogger=ERROR, CARBON_CONSOLE, CARBON_LOGFILE, CARBON_MEMORY, CARBON_SYS_LOG, ERROR_LOGFILE log4j.rootLogger=ERROR, CARBON_CONSOLE, CARBON_LOGFILE, CARBON_MEMORY, CARBON_SYS_LOG, ERROR_LOGFILE
log4j.logger.AUDIT_LOG=INFO, AUDIT_LOGFILE log4j.logger.AUDIT_LOG=INFO, AUDIT_LOGFILE
log4j.category.org.apache.synapse=INFO log4j.category.org.apache.synapse=WARN
log4j.category.org.apache.synapse.transport=INFO log4j.category.org.apache.synapse.transport=WARN
log4j.category.org.apache.axis2=INFO log4j.category.org.apache.axis2=WARN
log4j.category.org.apache.axis2.transport=INFO log4j.category.org.apache.axis2.transport=WARN
log4j.logger.com.atomikos=INFO,ATOMIKOS log4j.logger.com.atomikos=INFO,ATOMIKOS
log4j.logger.org.quartz=WARN log4j.logger.org.quartz=WARN
log4j.logger.org.wso2=INFO log4j.logger.org.wso2=INFO
@ -240,3 +240,4 @@ log4j.logger.org.wso2.carbon.event.receiver.core.EventReceiverDeployer=WARN
log4j.logger.org.wso2.carbon.analytics.spark.core.SparkScriptCAppDeployer=WARN log4j.logger.org.wso2.carbon.analytics.spark.core.SparkScriptCAppDeployer=WARN
log4j.logger.org.wso2.carbon.analytics.eventsink.AnalyticsEventStoreDeployer=WARN log4j.logger.org.wso2.carbon.analytics.eventsink.AnalyticsEventStoreDeployer=WARN
log4j.logger.org.wso2.carbon.event.processor.core.EventProcessorDeployer=WARN log4j.logger.org.wso2.carbon.event.processor.core.EventProcessorDeployer=WARN
log4j.logger.org.wso2.carbon.core.services.util.CarbonAuthenticationUtil=WARN

@ -1,9 +1,10 @@
<span id="connectedcup-details" data-devices="{{devices}}" data-devicename="{{device.name}}" <span id="connectedcup-details" data-devices="{{devices}}" data-devicename="{{device.name}}"
data-deviceid="{{device.deviceIdentifier}}" data-deviceid="{{device.deviceIdentifier}}"
data-appcontext="{{@app.context}}"></span> data-appcontext="{{@app.context}}"></span>
<div id="connectedcup-device-chart" data-backend-api-url = {{backendApiUri}}> <div id="connectedcup-div-chart" data-backend-api-url= {{backendApiUri}}>
<div class="chartWrapper" id="chartWrapper-temperature"> <div class="chartWrapper" id="chartWrapper-temperature">
<span id="span-title">Temperature</span> <span id="span-title">Temperature</span>
<div id="y_axis-temperature" class="custom_y_axis"></div> <div id="y_axis-temperature" class="custom_y_axis"></div>
<div class="legend_container"> <div class="legend_container">
<div id="smoother-temperature" title="Smoothing"></div> <div id="smoother-temperature" title="Smoothing"></div>
@ -16,6 +17,7 @@
<div class="chartWrapper" id="chartWrapper-coffeelevel"> <div class="chartWrapper" id="chartWrapper-coffeelevel">
<span id="span-title">Coffee Level</span> <span id="span-title">Coffee Level</span>
<div id="y_axis-coffeelevel" class="custom_y_axis"></div> <div id="y_axis-coffeelevel" class="custom_y_axis"></div>
<div class="legend_container"> <div class="legend_container">
<div id="smoother-coffeelevel" title="Smoothing"></div> <div id="smoother-coffeelevel" title="Smoothing"></div>

@ -17,6 +17,8 @@
*/ */
function onRequest(context) { function onRequest(context) {
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
var devices = context.unit.params.devices; var devices = context.unit.params.devices;
var deviceType = context.uriParams.deviceType; var deviceType = context.uriParams.deviceType;
var deviceId = request.getParameter("deviceId"); var deviceId = request.getParameter("deviceId");
@ -24,7 +26,7 @@ function onRequest(context) {
if (devices) { if (devices) {
return { return {
"devices": stringify(devices), "devices": stringify(devices),
"backendApiUri": devicemgtProps["httpsURL"] + "/android_sense/stats/" "backendApiUri": devicemgtProps["httpsURL"] + "/connectedcup/stats/"
}; };
} else if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) { } else if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) {
var deviceModule = require("/app/modules/device.js").deviceModule; var deviceModule = require("/app/modules/device.js").deviceModule;
@ -32,7 +34,7 @@ function onRequest(context) {
if (device && device.status != "error") { if (device && device.status != "error") {
return { return {
"device": device, "device": device,
"backendApiUrl": devicemgtProps["httpsURL"] + "/connectedcup/stats/" + deviceId + "/sensors/" "backendApiUri": devicemgtProps["httpsURL"] + "/connectedcup/stats/" + deviceId
}; };
} else { } else {
response.sendError(404, "Device Id " + deviceId + " of type " + deviceType + " cannot be found!"); response.sendError(404, "Device Id " + deviceId + " of type " + deviceType + " cannot be found!");

@ -17,43 +17,43 @@
*/ */
var palette = new Rickshaw.Color.Palette({scheme: "classic9"}); var palette = new Rickshaw.Color.Palette({scheme: "classic9"});
var graphMap = {};
function drawGraph_connectedcup(from, to) { function drawGraph_connectedcup(from, to) {
var devices = $("#connectedcup-details").data("devices"); $("#y_axis-temperature").html("");
var tzOffset = new Date().getTimezoneOffset() * 60; $("#smoother-temperature").html("");
$("#legend-temperature").html("");
var streamIndex = 0; $("#chart-temperature").html("");
var streams = ["temperature", "coffeelevel"]; $("#x_axis-temperature").html("");
$("#slider-temperature").html("");
populateGraph();
function populateGraph() {
if (streamIndex < 2) {
retrieveDataAndDrawLineGraph(streams[streamIndex], from, to);
}
streamIndex++;
}
function clearContent(type) { $("#y_axis-coffeelevel").html("");
$("#y_axis-" + type).html(""); $("#smoother-coffeelevel").html("");
$("#smoother-" + type).html(""); $("#legend-coffeelevel").html("");
$("#legend-" + type).html(""); $("#chart-coffeelevel").html("");
$("#chart-" + type).html(""); $("#x_axis-coffeelevel").html("");
$("#x_axis-" + type).html(""); $("#slider-coffeelevel").html("");
$("#slider-" + type).html("");
}
function initGraph(type, isMultilined) { var devices = $("#connectedcup-details").data("devices");
if (graphMap[type]) { var tzOffset = new Date().getTimezoneOffset() * 60;
return graphMap[type];
}
var chartWrapperElmId = "#connectedcup-div-chart"; var chartWrapperElmId = "#connectedcup-div-chart";
var graphWidth = $(chartWrapperElmId).width() - 50; var graphWidth = $(chartWrapperElmId).width() - 50;
var temperatureGraphConfig = {
element: document.getElementById("chart-temperature"),
width: graphWidth,
height: 400,
strokeWidth: 2,
renderer: 'line',
interpolation: "linear",
unstack: true,
stack: false,
xScale: d3.time.scale(),
padding: {top: 0.2, left: 0.02, right: 0.02, bottom: 0.2},
series: []
};
var graphConfig = { var coffeelevelGraphConfig = {
element: document.getElementById("chart-" + type), element: document.getElementById("chart-coffeelevel"),
width: graphWidth, width: graphWidth,
height: 400, height: 400,
strokeWidth: 2, strokeWidth: 2,
@ -68,7 +68,7 @@ function drawGraph_connectedcup(from, to) {
if (devices) { if (devices) {
for (var i = 0; i < devices.length; i++) { for (var i = 0; i < devices.length; i++) {
graphConfig['series'].push( temperatureGraphConfig['series'].push(
{ {
'color': palette.color(), 'color': palette.color(),
'data': [{ 'data': [{
@ -77,37 +77,28 @@ function drawGraph_connectedcup(from, to) {
}], }],
'name': devices[i].name 'name': devices[i].name
}); });
}
} else { coffeelevelGraphConfig['series'].push(
if (isMultilined) {
graphConfig['series'].push(
{
'color': palette.color(),
'data': [{
x: parseInt(new Date().getTime() / 1000),
y: 0
}],
'name': "x"
},
{ {
'color': palette.color(), 'color': palette.color(),
'data': [{ 'data': [{
x: parseInt(new Date().getTime() / 1000), x: parseInt(new Date().getTime() / 1000),
y: 0 y: 0
}], }],
'name': "y" 'name': devices[i].name
}, });
}
} else {
temperatureGraphConfig['series'].push(
{ {
'color': palette.color(), 'color': palette.color(),
'data': [{ 'data': [{
x: parseInt(new Date().getTime() / 1000), x: parseInt(new Date().getTime() / 1000),
y: 0 y: 0
}], }],
'name': "z" 'name': $("#connectedcup-details").data("devicename")
} });
); coffeelevelGraphConfig['series'].push(
} else {
graphConfig['series'].push(
{ {
'color': palette.color(), 'color': palette.color(),
'data': [{ 'data': [{
@ -117,37 +108,78 @@ function drawGraph_connectedcup(from, to) {
'name': $("#connectedcup-details").data("devicename") 'name': $("#connectedcup-details").data("devicename")
}); });
} }
}
var graph = new Rickshaw.Graph(graphConfig); var temperatureGraph = new Rickshaw.Graph(temperatureGraphConfig);
graph.render(); var coffeelevelGraph = new Rickshaw.Graph(coffeelevelGraphConfig);
temperatureGraph.render();
coffeelevelGraph.render
var xAxis = new Rickshaw.Graph.Axis.Time({ var xAxisTemepature = new Rickshaw.Graph.Axis.Time({
graph: graph graph: temperatureGraph
}); });
xAxis.render();
var yAxis = new Rickshaw.Graph.Axis.Y({ xAxisTemepature.render();
graph: graph,
var xAxisCoffeelevel = new Rickshaw.Graph.Axis.Time({
graph: coffeelevelGraph
});
xAxisCoffeelevel.render();
var yAxisTemperature = new Rickshaw.Graph.Axis.Y({
graph: temperatureGraph,
orientation: 'left', orientation: 'left',
element: document.getElementById("y_axis-" + type), element: document.getElementById("y_axis-temperature"),
width: 40, width: 40,
height: 410 height: 410
}); });
yAxis.render();
yAxisTemperature.render();
var yAxisCoffeelevel = new Rickshaw.Graph.Axis.Y({
graph: coffeelevelGraph,
orientation: 'left',
element: document.getElementById("y_axis-coffeelevel"),
width: 40,
height: 410
});
yAxisCoffeelevel.render();
var slider = new Rickshaw.Graph.RangeSlider.Preview({ var slider = new Rickshaw.Graph.RangeSlider.Preview({
graph: graph, graph: temperatureGraph,
element: document.getElementById("slider-" + type) element: document.getElementById("slider-temperature")
}); });
var legend = new Rickshaw.Graph.Legend({ var legend = new Rickshaw.Graph.Legend({
graph: graph, graph: temperatureGraph,
element: document.getElementById("legend-" + type) element: document.getElementById('legend-temperature')
});
var sliderCoffee = new Rickshaw.Graph.RangeSlider.Preview({
graph: coffeelevelGraph,
element: document.getElementById("slider-coffeelevel")
});
var legendCoffee = new Rickshaw.Graph.Legend({
graph: coffeelevelGraph,
element: document.getElementById('legend-coffeelevel')
}); });
var hoverDetail = new Rickshaw.Graph.HoverDetail({ var hoverDetail = new Rickshaw.Graph.HoverDetail({
graph: graph, graph: temperatureGraph,
formatter: function (series, x, y) {
var date = '<span class="date">' +
moment((x + tzOffset) * 1000).format('Do MMM YYYY h:mm:ss a') + '</span>';
var swatch = '<span class="detail_swatch" style="background-color: ' +
series.color + '"></span>';
return swatch + series.name + ": " + parseInt(y) + '<br>' + date;
}
});
var hoverDetailCoffeelevel = new Rickshaw.Graph.HoverDetail({
graph: coffeelevelGraph,
formatter: function (series, x, y) { formatter: function (series, x, y) {
var date = '<span class="date">' + var date = '<span class="date">' +
moment((x + tzOffset) * 1000).format('Do MMM YYYY h:mm:ss a') + '</span>'; moment((x + tzOffset) * 1000).format('Do MMM YYYY h:mm:ss a') + '</span>';
@ -158,48 +190,59 @@ function drawGraph_connectedcup(from, to) {
}); });
var shelving = new Rickshaw.Graph.Behavior.Series.Toggle({ var shelving = new Rickshaw.Graph.Behavior.Series.Toggle({
graph: graph, graph: temperatureGraph,
legend: legend legend: legend
}); });
var order = new Rickshaw.Graph.Behavior.Series.Order({ var order = new Rickshaw.Graph.Behavior.Series.Order({
graph: graph, graph: temperatureGraph,
legend: legend legend: legend
}); });
var highlighter = new Rickshaw.Graph.Behavior.Series.Highlight({ var highlighter = new Rickshaw.Graph.Behavior.Series.Highlight({
graph: graph, graph: temperatureGraph,
legend: legend legend: legend
}); });
graphMap[type] = {}; var shelvingCoffee = new Rickshaw.Graph.Behavior.Series.Toggle({
graphMap[type].graph = graph; graph: coffeelevelGraph,
graphMap[type].config = graphConfig; legend: legendCoffee
return graphMap[type]; });
}
function retrieveDataAndDrawLineGraph(type, from, to) { var orderCoffee = new Rickshaw.Graph.Behavior.Series.Order({
clearContent(type); graph: coffeelevelGraph,
legend: legendCoffee
});
var graphObj = initGraph(type, false); var highlighterCoffee = new Rickshaw.Graph.Behavior.Series.Highlight({
var graph = graphObj.graph; graph: coffeelevelGraph,
var graphConfig = graphObj.config; legend: legendCoffee
});
var deviceIndex = 0; var deviceIndex = 0;
if (devices) { if (devices) {
getData(); getData();
} else { } else {
var backendApiUrl = $("#connectedcup-div-chart").data("backend-api-url") + type + "?from=" + from + "&to=" + to; var backendApiUrl = $("#connectedcup-div-chart").data("backend-api-url") + "/sensors/temperature" + "?from=" + from + "&to=" + to;
var successCallback = function (data) { var successCallback = function (data) {
if (data) { if (data) {
drawLineGraph(JSON.parse(data)); drawTemperatureLineGraph(JSON.parse(data));
} }
populateGraph();
}; };
invokerUtil.get(backendApiUrl, successCallback, function (message) { invokerUtil.get(backendApiUrl, successCallback, function (message) {
console.log(message); console.log(message);
populateGraph(); });
var coffeeLevelApiUrl = $("#connectedcup-div-chart").data("backend-api-url") + "/sensors/coffeelevel"
+ "?from=" + from + "&to=" + to;
var successCallbackCoffeeLevel = function (data) {
if (data) {
drawCoffeeLevelLineGraph(JSON.parse(data));
}
};
invokerUtil.get(coffeeLevelApiUrl, successCallbackCoffeeLevel, function (message) {
console.log(message);
}); });
} }
@ -208,10 +251,11 @@ function drawGraph_connectedcup(from, to) {
return; return;
} }
var backendApiUrl = $("#connectedcup-div-chart").data("backend-api-url") + devices[deviceIndex].deviceIdentifier var backendApiUrl = $("#connectedcup-div-chart").data("backend-api-url") + devices[deviceIndex].deviceIdentifier
+ "/sensors/" + type + "?from=" + from + "&to=" + to; + "/sensors/temperature"
+ "?from=" + from + "&to=" + to;
var successCallback = function (data) { var successCallback = function (data) {
if (data) { if (data) {
drawLineGraph(JSON.parse(data)); drawTemperatureLineGraph(JSON.parse(data));
} }
deviceIndex++; deviceIndex++;
getData(); getData();
@ -221,9 +265,20 @@ function drawGraph_connectedcup(from, to) {
deviceIndex++; deviceIndex++;
getData(); getData();
}); });
var coffeeLevelApiUrl = $("#connectedcup-div-chart").data("backend-api-url") + devices[deviceIndex].deviceIdentifier
+ "/sensors/coffeelevel" + "?from=" + from + "&to=" + to;
var successCallbackCoffeeLevel = function (data) {
if (data) {
drawCoffeeLevelLineGraph(JSON.parse(data));
}
};
invokerUtil.get(coffeeLevelApiUrl, successCallbackCoffeeLevel, function (message) {
console.log(message);
});
} }
function drawLineGraph(data) { function drawTemperatureLineGraph(data) {
if (data.length === 0 || data.length === undefined) { if (data.length === 0 || data.length === undefined) {
return; return;
} }
@ -233,28 +288,31 @@ function drawGraph_connectedcup(from, to) {
chartData.push( chartData.push(
{ {
x: parseInt(data[i].values.time) - tzOffset, x: parseInt(data[i].values.time) - tzOffset,
y: parseInt(getFieldData(data[i], type)) y: parseInt(data[i].values.temperature)
} }
); );
} }
graphConfig.series[deviceIndex].data = chartData; temperatureGraphConfig.series[deviceIndex].data = chartData;
graph.update(); temperatureGraph.update();
}
} }
function getFieldData(data, type) { function drawCoffeeLevelLineGraph(data) {
var columnData; if (data.length === 0 || data.length === undefined) {
switch (type) { return;
case "temperature" :
columnData = data.values.temperature;
break;
case "coffeelevel" :
columnData = data.values.coffeelevel;
break;
} }
return columnData; var chartData = [];
for (var i = 0; i < data.length; i++) {
chartData.push(
{
x: parseInt(data[i].values.time) - tzOffset,
y: parseInt(data[i].values.coffeelevel)
}
);
} }
coffeelevelGraphConfig.series[deviceIndex].data = chartData;
coffeelevelGraph.update();
}
} }

Loading…
Cancel
Save