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
@ -239,4 +239,5 @@ log4j.logger.org.wso2.carbon.event.stream.core.internal.EventJunction=WARN
log4j.logger.org.wso2.carbon.event.receiver.core.EventReceiverDeployer=WARN 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,27 +1,29 @@
<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>
<div id="legend-temperature"></div> <div id="legend-temperature"></div>
</div> </div>
<div id="chart-temperature" class="custom_rickshaw_graph" ></div> <div id="chart-temperature" class="custom_rickshaw_graph"></div>
<div id="x_axis-temperature" class="custom_x_axis"></div> <div id="x_axis-temperature" class="custom_x_axis"></div>
<div id="slider-temperature" class="custom_slider"></div> <div id="slider-temperature" class="custom_slider"></div>
</div> </div>
<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>
<div id="legend-coffeelevel"></div> <div id="legend-coffeelevel"></div>
</div> </div>
<div id="chart-coffeelevel" class="custom_rickshaw_graph" ></div> <div id="chart-coffeelevel" class="custom_rickshaw_graph"></div>
<div id="x_axis-coffeelevel" class="custom_x_axis"></div> <div id="x_axis-coffeelevel" class="custom_x_axis"></div>
<div id="slider-coffeelevel" class="custom_slider"></div> <div id="slider-coffeelevel" class="custom_slider"></div>
</div> </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,11 +34,11 @@ 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!");
exit(); exit();
} }
} }
} }

@ -17,244 +17,302 @@
*/ */
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) {
$("#y_axis-temperature").html("");
$("#smoother-temperature").html("");
$("#legend-temperature").html("");
$("#chart-temperature").html("");
$("#x_axis-temperature").html("");
$("#slider-temperature").html("");
$("#y_axis-coffeelevel").html("");
$("#smoother-coffeelevel").html("");
$("#legend-coffeelevel").html("");
$("#chart-coffeelevel").html("");
$("#x_axis-coffeelevel").html("");
$("#slider-coffeelevel").html("");
var devices = $("#connectedcup-details").data("devices"); var devices = $("#connectedcup-details").data("devices");
var tzOffset = new Date().getTimezoneOffset() * 60; var tzOffset = new Date().getTimezoneOffset() * 60;
var streamIndex = 0; var chartWrapperElmId = "#connectedcup-div-chart";
var streams = ["temperature", "coffeelevel"]; 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: []
};
populateGraph(); var coffeelevelGraphConfig = {
element: document.getElementById("chart-coffeelevel"),
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: []
};
function populateGraph() { if (devices) {
if (streamIndex < 2) { for (var i = 0; i < devices.length; i++) {
retrieveDataAndDrawLineGraph(streams[streamIndex], from, to); temperatureGraphConfig['series'].push(
{
'color': palette.color(),
'data': [{
x: parseInt(new Date().getTime() / 1000),
y: 0
}],
'name': devices[i].name
});
coffeelevelGraphConfig['series'].push(
{
'color': palette.color(),
'data': [{
x: parseInt(new Date().getTime() / 1000),
y: 0
}],
'name': devices[i].name
});
} }
streamIndex++; } else {
temperatureGraphConfig['series'].push(
{
'color': palette.color(),
'data': [{
x: parseInt(new Date().getTime() / 1000),
y: 0
}],
'name': $("#connectedcup-details").data("devicename")
});
coffeelevelGraphConfig['series'].push(
{
'color': palette.color(),
'data': [{
x: parseInt(new Date().getTime() / 1000),
y: 0
}],
'name': $("#connectedcup-details").data("devicename")
});
} }
function clearContent(type) { var temperatureGraph = new Rickshaw.Graph(temperatureGraphConfig);
$("#y_axis-" + type).html(""); var coffeelevelGraph = new Rickshaw.Graph(coffeelevelGraphConfig);
$("#smoother-" + type).html("");
$("#legend-" + type).html("");
$("#chart-" + type).html("");
$("#x_axis-" + type).html("");
$("#slider-" + type).html("");
}
function initGraph(type, isMultilined) { temperatureGraph.render();
if (graphMap[type]) { coffeelevelGraph.render
return graphMap[type];
}
var chartWrapperElmId = "#connectedcup-div-chart"; var xAxisTemepature = new Rickshaw.Graph.Axis.Time({
var graphWidth = $(chartWrapperElmId).width() - 50; graph: temperatureGraph
});
var graphConfig = {
element: document.getElementById("chart-" + type),
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: []
};
if (devices) { xAxisTemepature.render();
for (var i = 0; i < devices.length; i++) {
graphConfig['series'].push(
{
'color': palette.color(),
'data': [{
x: parseInt(new Date().getTime() / 1000),
y: 0
}],
'name': devices[i].name
});
}
} else {
if (isMultilined) {
graphConfig['series'].push(
{
'color': palette.color(),
'data': [{
x: parseInt(new Date().getTime() / 1000),
y: 0
}],
'name': "x"
},
{
'color': palette.color(),
'data': [{
x: parseInt(new Date().getTime() / 1000),
y: 0
}],
'name': "y"
},
{
'color': palette.color(),
'data': [{
x: parseInt(new Date().getTime() / 1000),
y: 0
}],
'name': "z"
}
);
} else {
graphConfig['series'].push(
{
'color': palette.color(),
'data': [{
x: parseInt(new Date().getTime() / 1000),
y: 0
}],
'name': $("#connectedcup-details").data("devicename")
});
}
}
var graph = new Rickshaw.Graph(graphConfig); var xAxisCoffeelevel = new Rickshaw.Graph.Axis.Time({
graph.render(); graph: coffeelevelGraph
});
var xAxis = new Rickshaw.Graph.Axis.Time({ xAxisCoffeelevel.render();
graph: graph
});
xAxis.render();
var yAxis = new Rickshaw.Graph.Axis.Y({
graph: graph,
orientation: 'left',
element: document.getElementById("y_axis-" + type),
width: 40,
height: 410
});
yAxis.render();
var slider = new Rickshaw.Graph.RangeSlider.Preview({ var yAxisTemperature = new Rickshaw.Graph.Axis.Y({
graph: graph, graph: temperatureGraph,
element: document.getElementById("slider-" + type) orientation: 'left',
}); element: document.getElementById("y_axis-temperature"),
width: 40,
height: 410
});
var legend = new Rickshaw.Graph.Legend({ yAxisTemperature.render();
graph: graph,
element: document.getElementById("legend-" + type)
});
var hoverDetail = new Rickshaw.Graph.HoverDetail({ var yAxisCoffeelevel = new Rickshaw.Graph.Axis.Y({
graph: graph, graph: coffeelevelGraph,
formatter: function (series, x, y) { orientation: 'left',
var date = '<span class="date">' + element: document.getElementById("y_axis-coffeelevel"),
moment((x + tzOffset) * 1000).format('Do MMM YYYY h:mm:ss a') + '</span>'; width: 40,
var swatch = '<span class="detail_swatch" style="background-color: ' + height: 410
series.color + '"></span>'; });
return swatch + series.name + ": " + parseInt(y) + '<br>' + date;
}
});
var shelving = new Rickshaw.Graph.Behavior.Series.Toggle({
graph: graph,
legend: legend
});
var order = new Rickshaw.Graph.Behavior.Series.Order({ yAxisCoffeelevel.render();
graph: graph,
legend: legend
});
var highlighter = new Rickshaw.Graph.Behavior.Series.Highlight({ var slider = new Rickshaw.Graph.RangeSlider.Preview({
graph: graph, graph: temperatureGraph,
legend: legend element: document.getElementById("slider-temperature")
}); });
graphMap[type] = {};
graphMap[type].graph = graph;
graphMap[type].config = graphConfig;
return graphMap[type];
}
function retrieveDataAndDrawLineGraph(type, from, to) { var legend = new Rickshaw.Graph.Legend({
clearContent(type); graph: temperatureGraph,
element: document.getElementById('legend-temperature')
});
var graphObj = initGraph(type, false); var sliderCoffee = new Rickshaw.Graph.RangeSlider.Preview({
var graph = graphObj.graph; graph: coffeelevelGraph,
var graphConfig = graphObj.config; element: document.getElementById("slider-coffeelevel")
});
var deviceIndex = 0; var legendCoffee = new Rickshaw.Graph.Legend({
graph: coffeelevelGraph,
element: document.getElementById('legend-coffeelevel')
});
if (devices) { var hoverDetail = new Rickshaw.Graph.HoverDetail({
getData(); graph: temperatureGraph,
} else { formatter: function (series, x, y) {
var backendApiUrl = $("#connectedcup-div-chart").data("backend-api-url") + type + "?from=" + from + "&to=" + to; var date = '<span class="date">' +
var successCallback = function (data) { moment((x + tzOffset) * 1000).format('Do MMM YYYY h:mm:ss a') + '</span>';
if (data) { var swatch = '<span class="detail_swatch" style="background-color: ' +
drawLineGraph(JSON.parse(data)); series.color + '"></span>';
} return swatch + series.name + ": " + parseInt(y) + '<br>' + date;
populateGraph();
};
invokerUtil.get(backendApiUrl, successCallback, function (message) {
console.log(message);
populateGraph();
});
} }
});
function getData() { var hoverDetailCoffeelevel = new Rickshaw.Graph.HoverDetail({
if (deviceIndex >= devices.length) { graph: coffeelevelGraph,
return; formatter: function (series, x, y) {
} var date = '<span class="date">' +
var backendApiUrl = $("#connectedcup-div-chart").data("backend-api-url") + devices[deviceIndex].deviceIdentifier moment((x + tzOffset) * 1000).format('Do MMM YYYY h:mm:ss a') + '</span>';
+ "/sensors/" + type + "?from=" + from + "&to=" + to; var swatch = '<span class="detail_swatch" style="background-color: ' +
var successCallback = function (data) { series.color + '"></span>';
if (data) { return swatch + series.name + ": " + parseInt(y) + '<br>' + date;
drawLineGraph(JSON.parse(data));
}
deviceIndex++;
getData();
};
invokerUtil.get(backendApiUrl, successCallback, function (message) {
console.log(message);
deviceIndex++;
getData();
});
} }
});
var shelving = new Rickshaw.Graph.Behavior.Series.Toggle({
graph: temperatureGraph,
legend: legend
});
function drawLineGraph(data) { var order = new Rickshaw.Graph.Behavior.Series.Order({
if (data.length === 0 || data.length === undefined) { graph: temperatureGraph,
return; legend: legend
});
var highlighter = new Rickshaw.Graph.Behavior.Series.Highlight({
graph: temperatureGraph,
legend: legend
});
var shelvingCoffee = new Rickshaw.Graph.Behavior.Series.Toggle({
graph: coffeelevelGraph,
legend: legendCoffee
});
var orderCoffee = new Rickshaw.Graph.Behavior.Series.Order({
graph: coffeelevelGraph,
legend: legendCoffee
});
var highlighterCoffee = new Rickshaw.Graph.Behavior.Series.Highlight({
graph: coffeelevelGraph,
legend: legendCoffee
});
var deviceIndex = 0;
if (devices) {
getData();
} else {
var backendApiUrl = $("#connectedcup-div-chart").data("backend-api-url") + "/sensors/temperature" + "?from=" + from + "&to=" + to;
var successCallback = function (data) {
if (data) {
drawTemperatureLineGraph(JSON.parse(data));
} }
};
invokerUtil.get(backendApiUrl, successCallback, function (message) {
console.log(message);
});
var chartData = []; var coffeeLevelApiUrl = $("#connectedcup-div-chart").data("backend-api-url") + "/sensors/coffeelevel"
for (var i = 0; i < data.length; i++) { + "?from=" + from + "&to=" + to;
chartData.push( var successCallbackCoffeeLevel = function (data) {
{ if (data) {
x: parseInt(data[i].values.time) - tzOffset, drawCoffeeLevelLineGraph(JSON.parse(data));
y: parseInt(getFieldData(data[i], type))
}
);
} }
};
invokerUtil.get(coffeeLevelApiUrl, successCallbackCoffeeLevel, function (message) {
console.log(message);
});
}
graphConfig.series[deviceIndex].data = chartData; function getData() {
graph.update(); if (deviceIndex >= devices.length) {
return;
} }
var backendApiUrl = $("#connectedcup-div-chart").data("backend-api-url") + devices[deviceIndex].deviceIdentifier
+ "/sensors/temperature"
+ "?from=" + from + "&to=" + to;
var successCallback = function (data) {
if (data) {
drawTemperatureLineGraph(JSON.parse(data));
}
deviceIndex++;
getData();
};
invokerUtil.get(backendApiUrl, successCallback, function (message) {
console.log(message);
deviceIndex++;
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 getFieldData(data, type) { function drawTemperatureLineGraph(data) {
var columnData; if (data.length === 0 || data.length === undefined) {
switch (type) { return;
case "temperature" : }
columnData = data.values.temperature;
break; var chartData = [];
case "coffeelevel" : for (var i = 0; i < data.length; i++) {
columnData = data.values.coffeelevel; chartData.push(
break; {
x: parseInt(data[i].values.time) - tzOffset,
y: parseInt(data[i].values.temperature)
}
);
} }
return columnData; temperatureGraphConfig.series[deviceIndex].data = chartData;
temperatureGraph.update();
} }
function drawCoffeeLevelLineGraph(data) {
if (data.length === 0 || data.length === undefined) {
return;
}
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