<commit_before>var database = require('./database');

module.exports = function(app){
	var address = app.get('address');
	address = address == "127.0.0.1" ? 'mongodb://127.0.0.1/iit-project' : address; 

	app.get('/', function(req, res){
		database.getConnection(address, function(err, db){
			if(err){
				throw err;
			}else{
				db.collection('measures').find().toArray(function(error, result){
					if(error){
						throw error;
					}else{
						res.json(result);
					}
				});
			}
		});
	});
	app.get('/getHourData', function(req, res){
		database.getConnection(address, function(err, db){
			if(err){
				throw err;
			}else{
				var today = new Date();
				var tomorrow = new Date(today.getTime() + (24 * 60 * 60 * 1000));
				db.collection('measures').aggregate(
					[
						{
							$match: 
							{
								datetime: 
								{
									$gte: date, 
									$lt: tomorrow
								}
							}
						},
						{
							$group:
							{
								_id : { room: "$room", hour: { $hour: "$datetime" } },
								avgTemperature : { $avg: "$temperature" },
								avgPressure: {$avg: "$pressure"},
								avgHumidity: {$avg: "$humidity"}
							}
						}
					]
				).toArray(function(error, result){
					if(error){
						throw error;
					}else{
						res.json(result);
					}
				});<commit_msg>fix undefined variable issue<commit_after>var database = require('./database');

module.exports = function(app){
	var address = app.get('address');
	address = address == "127.0.0.1" ? 'mongodb://127.0.0.1/iit-project' : address; 

	app.get('/', function(req, res){
		database.getConnection(address, function(err, db){
			if(err){
				throw err;
			}else{
				db.collection('measures').find().toArray(function(error, result){
					if(error){
						throw error;
					}else{
						res.json(result);
					}
				});
			}
		});
	});
	app.get('/getHourData', function(req, res){
		database.getConnection(address, function(err, db){
			if(err){
				throw err;
			}else{
				var today = new Date();
				var tomorrow = new Date(today.getTime() + (24 * 60 * 60 * 1000));
				db.collection('measures').aggregate(
					[
						{
							$match: 
							{
								datetime: 
								{
									$gte: today, 
									$lt: tomorrow
								}
							}
						},
						{
							$group:
							{
								_id : { room: "$room", hour: { $hour: "$datetime" } },
								avgTemperature : { $avg: "$temperature" },
								avgPressure: {$avg: "$pressure"},
								avgHumidity: {$avg: "$humidity"}
							}
						}
					]
				).toArray(function(error, result){
					if(error){
						throw error;
					}else{
						res.json(result);
					}
				});
{'fraction_non_alphanumeric': 0.17974105102817975, 'fraction_numerical': 0.016755521706016754, 'mean_word_length': 2.097877358490566, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5464908', 'n_tokens_mistral': 1344, 'n_tokens_neox': 871, 'n_words': 167}