From 1d10bbb14c091293172dbef52abe1a1b4c8cf4c2 Mon Sep 17 00:00:00 2001 From: Lautaro Cozzani Date: Wed, 9 Apr 2014 18:23:28 +0200 Subject: [PATCH] remove duplicate temperatures #131 --- etc/POST_CEBADA.json | 2 +- etc/bin/post_json.sh | 1 + etc/bin/post_json_prod.sh | 1 + public/js/RecipeCtrl.js | 11 +++-- public/partial/recipe-temperature.html | 12 +++++- public/template/abm-combo-object.html | 1 + routes/data.js | 59 +++++++++++++++++++++----- 7 files changed, 71 insertions(+), 16 deletions(-) create mode 100755 etc/bin/post_json.sh create mode 100755 etc/bin/post_json_prod.sh diff --git a/etc/POST_CEBADA.json b/etc/POST_CEBADA.json index 244a7c9e..5ad66fed 100644 --- a/etc/POST_CEBADA.json +++ b/etc/POST_CEBADA.json @@ -3,7 +3,7 @@ "coldStatus": true, "heatStatus": false, "source": "1", - "temperature": 14.0, + "temperature": 19.0, "temperatureMax": 20, "temperatureMin": 19, "temperatureExt": 14.1 diff --git a/etc/bin/post_json.sh b/etc/bin/post_json.sh new file mode 100755 index 00000000..84389314 --- /dev/null +++ b/etc/bin/post_json.sh @@ -0,0 +1 @@ +curl -X POST -d @"etc/POST_CEBADA.json" http://localhost:3000/TempDeviceReport -H "Accept: Application/json" -H "Content-Type: application/json" diff --git a/etc/bin/post_json_prod.sh b/etc/bin/post_json_prod.sh new file mode 100755 index 00000000..f0d12b4c --- /dev/null +++ b/etc/bin/post_json_prod.sh @@ -0,0 +1 @@ +curl -X POST -d @"etc/POST_CEBADA.json" http://brew-o-matic.eu01.aws.af.cm/TempDeviceReport -H "Accept: Application/json" -H "Content-Type: application/json" diff --git a/public/js/RecipeCtrl.js b/public/js/RecipeCtrl.js index 257717b2..5eaaef2a 100644 --- a/public/js/RecipeCtrl.js +++ b/public/js/RecipeCtrl.js @@ -464,10 +464,14 @@ module.controller("RecipeTemperatureCtrl", function($scope, TempDeviceReport, pushListener) { - $scope.temperatures = TempDeviceReport.query({recipe_id: $scope.recipe._id}, function() { - $scope.updateChart(); - }); + $scope.reload = function() { + $scope.temperatures = TempDeviceReport.query({recipe_id: $scope.recipe._id}, function() { + $scope.updateChart(); + }); + }; + $scope.reload(); + function onNewTemperature(temp) { $scope.temperatures.push(temp); $scope.updateChart(); @@ -480,6 +484,7 @@ pushListener.off("TEMP_DEVICE_REPORT_" + $scope.recipe._id, onNewTemperature); }); + $scope.updateChart = function() { var cols = [{ "id": "day", diff --git a/public/partial/recipe-temperature.html b/public/partial/recipe-temperature.html index 81027354..552bc835 100644 --- a/public/partial/recipe-temperature.html +++ b/public/partial/recipe-temperature.html @@ -2,6 +2,14 @@
+
+
+ +
+
+
@@ -20,8 +28,8 @@ - - + + diff --git a/public/template/abm-combo-object.html b/public/template/abm-combo-object.html index cde68e09..aeae9c11 100644 --- a/public/template/abm-combo-object.html +++ b/public/template/abm-combo-object.html @@ -1,4 +1,5 @@ \ No newline at end of file diff --git a/routes/data.js b/routes/data.js index f2e9a18c..9141e936 100644 --- a/routes/data.js +++ b/routes/data.js @@ -97,7 +97,7 @@ exports.TempDeviceReport.findAll = function(req, res) { exports.TempDeviceReport.save = function(req, res) { var temp = req.body; - console.log("ACA!!!!",temp); + // console.log("ACA!!!!",temp); delete temp._id; if ( !temp.timestamp ) { @@ -109,18 +109,57 @@ exports.TempDeviceReport.save = function(req, res) { //Busco el dispositivo correspondiente y obtengo el ID de la receta que corresponde. model.TempDevice.find({code:temp.code}).exec(function(err, device) { - if ( !err && device && device.length > 0 ) { + //Solo guardo si existe el dispositivo y si el mismo esta vinculado a una receta + if ( !err && device && device.length > 0 && device[0].recipe_id) { temp.recipe_id = device[0].recipe_id; + + model.TempDeviceReport.findByIdAndUpdate(id,temp,{upsert:true}).exec(function(err,results) { + // console.log('err', err); + // console.log('results', results); + if ( temp.recipe_id ) { + push.emit("TEMP_DEVICE_REPORT_" + temp.recipe_id,results); + } + res.send(results); + + //Elimino posibles duplicados de valores + model.TempDeviceReport.find({ + recipe_id: device[0].recipe_id + }).sort("timestamp").exec(function (err, duplicated) { + if ( duplicated.length > 2 ) { + + var base = duplicated[duplicated.length-1]; + var toRemove = null; + + var finish = false; + var i = duplicated.length-2; + while ( !finish && i>=0 ) { + var actual = duplicated[i--]; + if ( + actual.source == base.source && + actual.temperature == base.temperature && + actual.temperatureExt == base.temperatureExt && + actual.temperatureMax == base.temperatureMax && + actual.temperatureMin == base.temperatureMin && + actual.coldStatus == base.coldStatus && + actual.heatStatus == base.heatStatus ) { + // actual.remove(); + if ( toRemove ) toRemove.remove(); + toRemove = actual; + console.log("ELIMIMAR"); + } else { + console.log("FINiSH",actual,base); + finish = true; + } + } + + } + }); + }); + + } else { + res.send(500); } - model.TempDeviceReport.findByIdAndUpdate(id,temp,{upsert:true}).exec(function(err,results) { - // console.log('err', err); - // console.log('results', results); - if ( temp.recipe_id ) { - push.emit("TEMP_DEVICE_REPORT_" + temp.recipe_id,results); - } - res.send(results); - }); });
{{temperature.timestamp|ts2date|date:'dd-MM-yyyy HH:mm'}}
{{temperature.timestamp|ts2date|date:'dd-MM-yyyy HH:mm:ss'}} {{temperature.source}} {{temperature.temperature}} {{temperature.temperatureExt}}