mirror of
https://repository.entgra.net/community/product-iots.git
synced 2025-09-16 23:32:19 +00:00
resolving coffeecup issues
This commit is contained in:
parent
70079b9035
commit
57fd20291b
@ -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 xAxisTemepature = new Rickshaw.Graph.Axis.Time({
|
||||||
|
graph: temperatureGraph
|
||||||
|
});
|
||||||
|
|
||||||
|
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-temperature"),
|
||||||
|
width: 40,
|
||||||
|
height: 410
|
||||||
|
});
|
||||||
|
|
||||||
|
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: temperatureGraph,
|
||||||
|
element: document.getElementById("slider-temperature")
|
||||||
|
});
|
||||||
|
|
||||||
|
var legend = new Rickshaw.Graph.Legend({
|
||||||
|
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: 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 chartWrapperElmId = "#connectedcup-div-chart";
|
var hoverDetailCoffeelevel = new Rickshaw.Graph.HoverDetail({
|
||||||
var graphWidth = $(chartWrapperElmId).width() - 50;
|
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>';
|
||||||
|
var swatch = '<span class="detail_swatch" style="background-color: ' +
|
||||||
|
series.color + '"></span>';
|
||||||
|
return swatch + series.name + ": " + parseInt(y) + '<br>' + date;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
var graphConfig = {
|
var shelving = new Rickshaw.Graph.Behavior.Series.Toggle({
|
||||||
element: document.getElementById("chart-" + type),
|
graph: temperatureGraph,
|
||||||
width: graphWidth,
|
legend: legend
|
||||||
height: 400,
|
});
|
||||||
strokeWidth: 2,
|
|
||||||
renderer: 'line',
|
var order = new Rickshaw.Graph.Behavior.Series.Order({
|
||||||
interpolation: "linear",
|
graph: temperatureGraph,
|
||||||
unstack: true,
|
legend: legend
|
||||||
stack: false,
|
});
|
||||||
xScale: d3.time.scale(),
|
|
||||||
padding: {top: 0.2, left: 0.02, right: 0.02, bottom: 0.2},
|
var highlighter = new Rickshaw.Graph.Behavior.Series.Highlight({
|
||||||
series: []
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
if (devices) {
|
var coffeeLevelApiUrl = $("#connectedcup-div-chart").data("backend-api-url") + "/sensors/coffeelevel"
|
||||||
for (var i = 0; i < devices.length; i++) {
|
+ "?from=" + from + "&to=" + to;
|
||||||
graphConfig['series'].push(
|
var successCallbackCoffeeLevel = function (data) {
|
||||||
{
|
if (data) {
|
||||||
'color': palette.color(),
|
drawCoffeeLevelLineGraph(JSON.parse(data));
|
||||||
'data': [{
|
|
||||||
x: parseInt(new Date().getTime() / 1000),
|
|
||||||
y: 0
|
|
||||||
}],
|
|
||||||
'name': devices[i].name
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else {
|
};
|
||||||
if (isMultilined) {
|
invokerUtil.get(coffeeLevelApiUrl, successCallbackCoffeeLevel, function (message) {
|
||||||
graphConfig['series'].push(
|
console.log(message);
|
||||||
{
|
|
||||||
'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);
|
|
||||||
graph.render();
|
|
||||||
|
|
||||||
var xAxis = new Rickshaw.Graph.Axis.Time({
|
|
||||||
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({
|
|
||||||
graph: graph,
|
|
||||||
element: document.getElementById("slider-" + type)
|
|
||||||
});
|
|
||||||
|
|
||||||
var legend = new Rickshaw.Graph.Legend({
|
|
||||||
graph: graph,
|
|
||||||
element: document.getElementById("legend-" + type)
|
|
||||||
});
|
|
||||||
|
|
||||||
var hoverDetail = new Rickshaw.Graph.HoverDetail({
|
|
||||||
graph: graph,
|
|
||||||
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 shelving = new Rickshaw.Graph.Behavior.Series.Toggle({
|
|
||||||
graph: graph,
|
|
||||||
legend: legend
|
|
||||||
});
|
|
||||||
|
|
||||||
var order = new Rickshaw.Graph.Behavior.Series.Order({
|
|
||||||
graph: graph,
|
|
||||||
legend: legend
|
|
||||||
});
|
|
||||||
|
|
||||||
var highlighter = new Rickshaw.Graph.Behavior.Series.Highlight({
|
|
||||||
graph: graph,
|
|
||||||
legend: legend
|
|
||||||
});
|
|
||||||
|
|
||||||
graphMap[type] = {};
|
|
||||||
graphMap[type].graph = graph;
|
|
||||||
graphMap[type].config = graphConfig;
|
|
||||||
return graphMap[type];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function retrieveDataAndDrawLineGraph(type, from, to) {
|
function getData() {
|
||||||
clearContent(type);
|
if (deviceIndex >= devices.length) {
|
||||||
|
return;
|
||||||
var graphObj = initGraph(type, false);
|
}
|
||||||
var graph = graphObj.graph;
|
var backendApiUrl = $("#connectedcup-div-chart").data("backend-api-url") + devices[deviceIndex].deviceIdentifier
|
||||||
var graphConfig = graphObj.config;
|
+ "/sensors/temperature"
|
||||||
|
+ "?from=" + from + "&to=" + to;
|
||||||
var deviceIndex = 0;
|
var successCallback = function (data) {
|
||||||
|
if (data) {
|
||||||
if (devices) {
|
drawTemperatureLineGraph(JSON.parse(data));
|
||||||
|
}
|
||||||
|
deviceIndex++;
|
||||||
getData();
|
getData();
|
||||||
} else {
|
};
|
||||||
var backendApiUrl = $("#connectedcup-div-chart").data("backend-api-url") + type + "?from=" + from + "&to=" + to;
|
invokerUtil.get(backendApiUrl, successCallback, function (message) {
|
||||||
var successCallback = function (data) {
|
console.log(message);
|
||||||
if (data) {
|
deviceIndex++;
|
||||||
drawLineGraph(JSON.parse(data));
|
getData();
|
||||||
}
|
});
|
||||||
populateGraph();
|
var coffeeLevelApiUrl = $("#connectedcup-div-chart").data("backend-api-url") + devices[deviceIndex].deviceIdentifier
|
||||||
};
|
+ "/sensors/coffeelevel" + "?from=" + from + "&to=" + to;
|
||||||
invokerUtil.get(backendApiUrl, successCallback, function (message) {
|
|
||||||
console.log(message);
|
|
||||||
populateGraph();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getData() {
|
var successCallbackCoffeeLevel = function (data) {
|
||||||
if (deviceIndex >= devices.length) {
|
if (data) {
|
||||||
return;
|
drawCoffeeLevelLineGraph(JSON.parse(data));
|
||||||
}
|
}
|
||||||
var backendApiUrl = $("#connectedcup-div-chart").data("backend-api-url") + devices[deviceIndex].deviceIdentifier
|
};
|
||||||
+ "/sensors/" + type + "?from=" + from + "&to=" + to;
|
invokerUtil.get(coffeeLevelApiUrl, successCallbackCoffeeLevel, function (message) {
|
||||||
var successCallback = function (data) {
|
console.log(message);
|
||||||
if (data) {
|
});
|
||||||
drawLineGraph(JSON.parse(data));
|
|
||||||
}
|
|
||||||
deviceIndex++;
|
|
||||||
getData();
|
|
||||||
};
|
|
||||||
invokerUtil.get(backendApiUrl, successCallback, function (message) {
|
|
||||||
console.log(message);
|
|
||||||
deviceIndex++;
|
|
||||||
getData();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function drawLineGraph(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(getFieldData(data[i], type))
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
graphConfig.series[deviceIndex].data = chartData;
|
|
||||||
graph.update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getFieldData(data, type) {
|
|
||||||
var columnData;
|
|
||||||
switch (type) {
|
|
||||||
case "temperature" :
|
|
||||||
columnData = data.values.temperature;
|
|
||||||
break;
|
|
||||||
case "coffeelevel" :
|
|
||||||
columnData = data.values.coffeelevel;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return columnData;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function drawTemperatureLineGraph(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.temperature)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
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…
Reference in New Issue
Block a user