resolving coffeecup issues

merge-requests/1/head
ayyoob 9 years ago
parent 70079b9035
commit 57fd20291b

@ -38,10 +38,10 @@
log4j.rootLogger=ERROR, CARBON_CONSOLE, CARBON_LOGFILE, CARBON_MEMORY, CARBON_SYS_LOG, ERROR_LOGFILE
log4j.logger.AUDIT_LOG=INFO, AUDIT_LOGFILE
log4j.category.org.apache.synapse=INFO
log4j.category.org.apache.synapse.transport=INFO
log4j.category.org.apache.axis2=INFO
log4j.category.org.apache.axis2.transport=INFO
log4j.category.org.apache.synapse=WARN
log4j.category.org.apache.synapse.transport=WARN
log4j.category.org.apache.axis2=WARN
log4j.category.org.apache.axis2.transport=WARN
log4j.logger.com.atomikos=INFO,ATOMIKOS
log4j.logger.org.quartz=WARN
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.eventsink.AnalyticsEventStoreDeployer=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}}"
data-deviceid="{{device.deviceIdentifier}}"
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">
<span id="span-title">Temperature</span>
<div id="y_axis-temperature" class="custom_y_axis"></div>
<div class="legend_container">
<div id="smoother-temperature" title="Smoothing"></div>
@ -16,6 +17,7 @@
<div class="chartWrapper" id="chartWrapper-coffeelevel">
<span id="span-title">Coffee Level</span>
<div id="y_axis-coffeelevel" class="custom_y_axis"></div>
<div class="legend_container">
<div id="smoother-coffeelevel" title="Smoothing"></div>

@ -17,6 +17,8 @@
*/
function onRequest(context) {
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
var devices = context.unit.params.devices;
var deviceType = context.uriParams.deviceType;
var deviceId = request.getParameter("deviceId");
@ -24,7 +26,7 @@ function onRequest(context) {
if (devices) {
return {
"devices": stringify(devices),
"backendApiUri": devicemgtProps["httpsURL"] + "/android_sense/stats/"
"backendApiUri": devicemgtProps["httpsURL"] + "/connectedcup/stats/"
};
} else if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) {
var deviceModule = require("/app/modules/device.js").deviceModule;
@ -32,7 +34,7 @@ function onRequest(context) {
if (device && device.status != "error") {
return {
"device": device,
"backendApiUrl": devicemgtProps["httpsURL"] + "/connectedcup/stats/" + deviceId + "/sensors/"
"backendApiUri": devicemgtProps["httpsURL"] + "/connectedcup/stats/" + deviceId
};
} else {
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 graphMap = {};
function drawGraph_connectedcup(from, to) {
var devices = $("#connectedcup-details").data("devices");
var tzOffset = new Date().getTimezoneOffset() * 60;
var streamIndex = 0;
var streams = ["temperature", "coffeelevel"];
populateGraph();
function populateGraph() {
if (streamIndex < 2) {
retrieveDataAndDrawLineGraph(streams[streamIndex], from, to);
}
streamIndex++;
}
$("#y_axis-temperature").html("");
$("#smoother-temperature").html("");
$("#legend-temperature").html("");
$("#chart-temperature").html("");
$("#x_axis-temperature").html("");
$("#slider-temperature").html("");
function clearContent(type) {
$("#y_axis-" + type).html("");
$("#smoother-" + type).html("");
$("#legend-" + type).html("");
$("#chart-" + type).html("");
$("#x_axis-" + type).html("");
$("#slider-" + type).html("");
}
$("#y_axis-coffeelevel").html("");
$("#smoother-coffeelevel").html("");
$("#legend-coffeelevel").html("");
$("#chart-coffeelevel").html("");
$("#x_axis-coffeelevel").html("");
$("#slider-coffeelevel").html("");
function initGraph(type, isMultilined) {
if (graphMap[type]) {
return graphMap[type];
}
var devices = $("#connectedcup-details").data("devices");
var tzOffset = new Date().getTimezoneOffset() * 60;
var chartWrapperElmId = "#connectedcup-div-chart";
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 = {
element: document.getElementById("chart-" + type),
var coffeelevelGraphConfig = {
element: document.getElementById("chart-coffeelevel"),
width: graphWidth,
height: 400,
strokeWidth: 2,
@ -68,7 +68,7 @@ function drawGraph_connectedcup(from, to) {
if (devices) {
for (var i = 0; i < devices.length; i++) {
graphConfig['series'].push(
temperatureGraphConfig['series'].push(
{
'color': palette.color(),
'data': [{
@ -77,37 +77,28 @@ function drawGraph_connectedcup(from, to) {
}],
'name': devices[i].name
});
}
} else {
if (isMultilined) {
graphConfig['series'].push(
{
'color': palette.color(),
'data': [{
x: parseInt(new Date().getTime() / 1000),
y: 0
}],
'name': "x"
},
coffeelevelGraphConfig['series'].push(
{
'color': palette.color(),
'data': [{
x: parseInt(new Date().getTime() / 1000),
y: 0
}],
'name': "y"
},
'name': devices[i].name
});
}
} else {
temperatureGraphConfig['series'].push(
{
'color': palette.color(),
'data': [{
x: parseInt(new Date().getTime() / 1000),
y: 0
}],
'name': "z"
}
);
} else {
graphConfig['series'].push(
'name': $("#connectedcup-details").data("devicename")
});
coffeelevelGraphConfig['series'].push(
{
'color': palette.color(),
'data': [{
@ -117,37 +108,78 @@ function drawGraph_connectedcup(from, to) {
'name': $("#connectedcup-details").data("devicename")
});
}
}
var graph = new Rickshaw.Graph(graphConfig);
graph.render();
var temperatureGraph = new Rickshaw.Graph(temperatureGraphConfig);
var coffeelevelGraph = new Rickshaw.Graph(coffeelevelGraphConfig);
temperatureGraph.render();
coffeelevelGraph.render
var xAxis = new Rickshaw.Graph.Axis.Time({
graph: graph
var xAxisTemepature = new Rickshaw.Graph.Axis.Time({
graph: temperatureGraph
});
xAxis.render();
var yAxis = new Rickshaw.Graph.Axis.Y({
graph: graph,
xAxisTemepature.render();
var xAxisCoffeelevel = new Rickshaw.Graph.Axis.Time({
graph: coffeelevelGraph
});
xAxisCoffeelevel.render();
var yAxisTemperature = new Rickshaw.Graph.Axis.Y({
graph: temperatureGraph,
orientation: 'left',
element: document.getElementById("y_axis-" + type),
element: document.getElementById("y_axis-temperature"),
width: 40,
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({
graph: graph,
element: document.getElementById("slider-" + type)
graph: temperatureGraph,
element: document.getElementById("slider-temperature")
});
var legend = new Rickshaw.Graph.Legend({
graph: graph,
element: document.getElementById("legend-" + type)
graph: temperatureGraph,
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({
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) {
var date = '<span class="date">' +
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({
graph: graph,
graph: temperatureGraph,
legend: legend
});
var order = new Rickshaw.Graph.Behavior.Series.Order({
graph: graph,
graph: temperatureGraph,
legend: legend
});
var highlighter = new Rickshaw.Graph.Behavior.Series.Highlight({
graph: graph,
graph: temperatureGraph,
legend: legend
});
graphMap[type] = {};
graphMap[type].graph = graph;
graphMap[type].config = graphConfig;
return graphMap[type];
}
var shelvingCoffee = new Rickshaw.Graph.Behavior.Series.Toggle({
graph: coffeelevelGraph,
legend: legendCoffee
});
function retrieveDataAndDrawLineGraph(type, from, to) {
clearContent(type);
var orderCoffee = new Rickshaw.Graph.Behavior.Series.Order({
graph: coffeelevelGraph,
legend: legendCoffee
});
var graphObj = initGraph(type, false);
var graph = graphObj.graph;
var graphConfig = graphObj.config;
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") + type + "?from=" + from + "&to=" + to;
var backendApiUrl = $("#connectedcup-div-chart").data("backend-api-url") + "/sensors/temperature" + "?from=" + from + "&to=" + to;
var successCallback = function (data) {
if (data) {
drawLineGraph(JSON.parse(data));
drawTemperatureLineGraph(JSON.parse(data));
}
populateGraph();
};
invokerUtil.get(backendApiUrl, successCallback, function (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;
}
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) {
if (data) {
drawLineGraph(JSON.parse(data));
drawTemperatureLineGraph(JSON.parse(data));
}
deviceIndex++;
getData();
@ -221,9 +265,20 @@ function drawGraph_connectedcup(from, to) {
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 drawLineGraph(data) {
function drawTemperatureLineGraph(data) {
if (data.length === 0 || data.length === undefined) {
return;
}
@ -233,28 +288,31 @@ function drawGraph_connectedcup(from, to) {
chartData.push(
{
x: parseInt(data[i].values.time) - tzOffset,
y: parseInt(getFieldData(data[i], type))
y: parseInt(data[i].values.temperature)
}
);
}
graphConfig.series[deviceIndex].data = chartData;
graph.update();
}
temperatureGraphConfig.series[deviceIndex].data = chartData;
temperatureGraph.update();
}
function getFieldData(data, type) {
var columnData;
switch (type) {
case "temperature" :
columnData = data.values.temperature;
break;
case "coffeelevel" :
columnData = data.values.coffeelevel;
break;
function drawCoffeeLevelLineGraph(data) {
if (data.length === 0 || data.length === undefined) {
return;
}
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