1
0
mirror of https://github.com/mgerb/mywebsite synced 2026-01-11 18:32:50 +00:00

added graphs

This commit is contained in:
2015-12-19 03:53:29 -06:00
parent 78f5e35270
commit 7d3822904d
7 changed files with 182 additions and 42 deletions

View File

@@ -6,14 +6,14 @@ require("../models/temperature");
var temperature = mongoose.model('temperature');
/* GET sensors page. */
//api to return the max and min temps of each day based on location
router.get('/allsensors', function(req, res, next) {
//var location = req.query.location;
temperature.aggregate([{$group : { _id : {location : "$location", month: {$month: "$updated" }, day: { $dayOfMonth: "$updated" }, year: { $year: "$updated" }},
max : {$max : "$temperature"},
min : {$min : "$temperature"}}},
{$sort : {"_id.month" : -1, "_id.day" : -1, "_id.year" : -1}}]).exec(function(err, info){
{$sort : {"_id.month" : 1, "_id.day" : 1, "_id.year" : 1}}]).exec(function(err, info){
console.log(info);
res.setHeader('Content-Type', 'application/json');
@@ -26,13 +26,20 @@ router.get('/allsensors', function(req, res, next) {
router.get('/sensorbylocation', function(req, res, next) {
var loc = req.query.location;
console.log(loc);
//var location = req.query.location;
temperature.aggregate([ {$match : {location : loc}},
var year = req.query.year;
if (year == null){
var date = new Date();
year = date.getFullYear();
}
//query finds a entries in a collection based on location and the year specified
//they are then grouped by date and sorted by date as well
temperature.aggregate([ {$match : {location : loc, updated : {$gte : new Date('1 Jan, ' + year), $lt : new Date('1 Jan ' + year +1)}}},
{$group : { _id : {location : "$location", month: {$month: "$updated" }, day: { $dayOfMonth: "$updated" }, year: { $year: "$updated" }},
max : {$max : "$temperature"},
min : {$min : "$temperature"}}},
{$sort : {"_id.month" : -1, "_id.day" : -1, "_id.year" : -1}}]).exec(function(err, info){
{$sort : {"_id.month" : 1, "_id.day" : 1, "_id.year" : 1}}]).exec(function(err, info){
console.log(info);
res.setHeader('Content-Type', 'application/json');