Many improvements and big fixes

This commit is contained in:
Samer Albahra
2015-07-02 20:53:18 -05:00
parent 8bfe799a01
commit 69d4c9ca4d
7 changed files with 38 additions and 28 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
.DS_Store
node_modules
.env
WeatherService.zip

View File

@@ -1,3 +0,0 @@
{
"maximumLineLength": 150
}

21
.jshintrc Normal file
View File

@@ -0,0 +1,21 @@
{
"boss": true,
"curly": true,
"eqeqeq": true,
"eqnull": true,
"expr": true,
"immed": true,
"noarg": true,
"onevar": true,
"quotmark": "double",
"smarttabs": true,
"trailing": true,
"undef": true,
"unused": true,
"browser": true,
"node": true,
"sub": true,
"globals": {
"module": true
}
}

View File

@@ -2,29 +2,20 @@ module.exports = function( grunt ) {
// Load node-modules;
grunt.loadNpmTasks( "grunt-contrib-jshint" );
grunt.loadNpmTasks( "grunt-jscs" );
// Project configuration.
grunt.initConfig( {
pkg: grunt.file.readJSON( "package.json" ),
jshint: {
main: [ "Gruntfile.js", "server.js", "routes/**", "models/**" ],
main: [ "Gruntfile.js", "server.js", "routes/*.js", "models/*.js" ],
options: {
jshintrc: true
}
},
jscs: {
main: [ "Gruntfile.js", "server.js", "routes/**", "models/**" ],
options: {
config: true,
fix: true
}
}
} );
// Default task(s).
grunt.registerTask( "default", [ "jshint", "jscs" ] );
grunt.registerTask( "default", [ "jshint" ] );
};

View File

@@ -9,7 +9,6 @@
"express": "^4.13.0",
"grunt": "^0.4.5",
"grunt-contrib-jshint": "^0.11.2",
"grunt-jscs": "^1.8.0",
"mongoose": "^4.0.6",
"xml2js": "^0.4.9"
}

View File

@@ -1,7 +1,7 @@
( function() {
var http = require( "http" ),
parseXML = require( "xml2js" ).parseString,
// parseXML = require( "xml2js" ).parseString,
Cache = require( "../models/Cache" ),
// Define regex filters to match against location
@@ -92,7 +92,7 @@
} );
}
/*
// Retrieve the historical weather data for the provided location
function getYesterdayWeatherData( location, callback ) {
@@ -108,7 +108,7 @@
// Generate URL using WSI Cleaned History API in Imperial units showing daily average values
url = "http://cleanedobservations.wsi.com/CleanedObs.svc/GetObs?ID=" + WSI_HISTORY_KEY +
"&Lat=" + location[0] + "&Long=" + location[1] +
"&Req=davg&startdate=" + yesterday.toUSDate() + "&enddate=" + yesterday.toUSDate() + "&TS=LST";
"&Req=davg&startdate=" + toUSDate( yesterday ) + "&enddate=" + toUSDate( yesterday ) + "&TS=LST";
// Perform the HTTP request to retrieve the weather data
httpRequest( url, function( xml ) {
@@ -117,7 +117,7 @@
});
} );
}
*/
// Update weather cache record in the local database
function updateCache( location, weather ) {
@@ -163,7 +163,7 @@
}
// Zimmerman method
if ( adjustmentMethod == 1 ) {
if ( adjustmentMethod === 1 ) {
var humidityFactor = ( 30 - rh ),
tempFactor = ( ( temp - 70 ) * 4 ),
@@ -237,7 +237,7 @@
location = req.query.loc,
weatherUndergroundKey = req.query.key,
outputFormat = req.query.format,
firmwareVersion = req.query.fwv,
// firmwareVersion = req.query.fwv,
remoteAddress = req.headers[ "x-forwarded-for" ] || req.connection.remoteAddress,
// Function that will accept the weather after it is received from the API
@@ -406,7 +406,8 @@
return ( ( ( ( ( ( +ip[0] ) * 256 ) + ( +ip[1] ) ) * 256 ) + ( +ip[2] ) ) * 256 ) + ( +ip[3] );
}
function F2C( temp ) {
/*
function f2c( temp ) {
return ( temp - 32 ) * 5 / 9;
}
@@ -419,8 +420,8 @@
}
// Resolves the Month / Day / Year of a Date object
Date.prototype.toUSDate = function(){
return ( this.getMonth() + 1 ) + "/" + this.getDate() + "/" + this.getFullYear();
};
function toUSDate( date ){
return ( date.getMonth() + 1 ) + "/" + date.getDate() + "/" + date.getFullYear();
}
*/
} )();

View File

@@ -3,7 +3,7 @@ var express = require( "express" ),
mongoose = require( "mongoose" ),
Cache = require( "./models/Cache" ),
CronJob = require( "cron" ).CronJob,
port = process.env.PORT || 3000;
port = process.env.PORT || 3000,
app = express();
if ( !process.env.PORT ) {
@@ -30,7 +30,7 @@ app.use( function( req, res ) {
} );
// Start listening on the service port
var server = app.listen( port, "127.0.0.1", function() {
app.listen( port, "127.0.0.1", function() {
console.log( "OpenSprinkler Weather Service now listening on port %s", port );
} );