mirror of
https://github.com/mgerb/mywebsite
synced 2026-01-11 18:32:50 +00:00
added date updated to sensors
This commit is contained in:
@@ -10,11 +10,30 @@ var temperature = mongoose.model('temperature');
|
||||
router.get('/', function(req, res, next) {
|
||||
|
||||
temperature.aggregate( [ {$sort : {location : -1, updated : -1}}, { $group : { _id : "$location", temperature : {$first : "$temperature"}, humidity : {$first : "$humidity"}, updated : {$first : "$updated"}} } ] ).exec(function(err, info){
|
||||
var date1 = new Date();
|
||||
|
||||
for (var i = 0; i < info.length; i++){
|
||||
console.log(info[i].updated.getTime());
|
||||
console.log(Date.now());
|
||||
var monthNames = ["January", "February", "March", "April", "May", "June",
|
||||
"July", "August", "September", "October", "November", "December"];
|
||||
|
||||
var hours = info[i].updated.getHours();
|
||||
var minutes = info[i].updated.getMinutes();
|
||||
var month = monthNames[info[i].updated.getMonth()];
|
||||
var date = info[i].updated.getUTCDate();
|
||||
var year = info[i].updated.getUTCFullYear();
|
||||
|
||||
var dateString = month + " " + date + ", " + year;
|
||||
|
||||
//converting 24 hours time to AM or PM
|
||||
if (hours < 12){
|
||||
info[i].lastUpdate = dateString + " - " + hours + ":" + minutes + " AM";
|
||||
}
|
||||
else if (hours == 12){
|
||||
info[i].lastUpdate = dateString + " - " + hours + ":" + minutes + " PM";
|
||||
}
|
||||
else{
|
||||
hours = hours - 12;
|
||||
info[i].lastUpdate = dateString + " - " + hours + ":" + minutes + " PM";
|
||||
}
|
||||
|
||||
//compared current time to last db entry - 1200000 milliseconds is 2 minutes
|
||||
if(info[i].updated.getTime() > (Date.now() - 120000)){
|
||||
@@ -24,13 +43,14 @@ router.get('/', function(req, res, next) {
|
||||
info[i].connected = false;
|
||||
}
|
||||
|
||||
console.log(info[i].connected);
|
||||
|
||||
|
||||
}
|
||||
|
||||
res.render('sensors', {query : info});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
router.post('/', function(req, res,next) {
|
||||
|
||||
Reference in New Issue
Block a user