Fix unit tests and remove unused code

This commit is contained in:
Samer Albahra
2018-07-22 19:31:38 -05:00
parent 1fa985e941
commit 616a0bda6f
8 changed files with 1551 additions and 315 deletions

View File

@@ -1,8 +1,5 @@
var express = require( "express" ),
weather = require( "./routes/weather.js" ),
mongoose = require( "mongoose" ),
Cache = require( "./models/Cache" ),
CronJob = require( "cron" ).CronJob,
host = process.env.HOST || "127.0.0.1",
port = process.env.PORT || 3000,
app = express();
@@ -13,14 +10,6 @@ if ( !process.env.HOST || !process.env.PORT ) {
port = process.env.PORT || port;
}
// Connect to local MongoDB instance
mongoose.connect( "mongodb://localhost", { useMongoClient: true } );
// If the database connection cannot be established, throw an error
mongoose.connection.on( "error", function() {
console.error( "MongoDB Connection Error. Please make sure that MongoDB is running." );
} );
// Handle requests matching /weatherID.py where ID corresponds to the
// weather adjustment method selector.
// This endpoint is considered deprecated and supported for prior firmware
@@ -42,34 +31,4 @@ app.listen( port, host, function() {
console.log( "OpenSprinkler Weather Service now listening on %s:%s", host, port );
} );
// Schedule a cronjob daily to consildate the weather cache data, runs daily
new CronJob( "0 0 0 * * *", function() {
// Find all records in the weather cache
Cache.find( {}, function( err, records ) {
if ( err ) {
return;
}
// Cycle through each record
records.forEach( function( record ) {
// If the record contains any unaveraged data, then process the record
if ( record.currentHumidityCount > 0 ) {
// Average the humidity by dividing the total over the total data points collected
record.yesterdayHumidity = record.currentHumidityTotal / record.currentHumidityCount;
// Reset the current humidity data for the new day
record.currentHumidityTotal = 0;
record.currentHumidityCount = 0;
// Save the record in the database
record.save();
}
} );
} );
}, null, true, "UTC" );
exports.app = app;