Many improvements and big fixes
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
|
.DS_Store
|
||||||
node_modules
|
node_modules
|
||||||
.env
|
.env
|
||||||
WeatherService.zip
|
WeatherService.zip
|
||||||
|
|||||||
21
.jshintrc
Normal file
21
.jshintrc
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
13
Gruntfile.js
13
Gruntfile.js
@@ -2,29 +2,20 @@ module.exports = function( grunt ) {
|
|||||||
|
|
||||||
// Load node-modules;
|
// Load node-modules;
|
||||||
grunt.loadNpmTasks( "grunt-contrib-jshint" );
|
grunt.loadNpmTasks( "grunt-contrib-jshint" );
|
||||||
grunt.loadNpmTasks( "grunt-jscs" );
|
|
||||||
|
|
||||||
// Project configuration.
|
// Project configuration.
|
||||||
grunt.initConfig( {
|
grunt.initConfig( {
|
||||||
pkg: grunt.file.readJSON( "package.json" ),
|
pkg: grunt.file.readJSON( "package.json" ),
|
||||||
|
|
||||||
jshint: {
|
jshint: {
|
||||||
main: [ "Gruntfile.js", "server.js", "routes/**", "models/**" ],
|
main: [ "Gruntfile.js", "server.js", "routes/*.js", "models/*.js" ],
|
||||||
options: {
|
options: {
|
||||||
jshintrc: true
|
jshintrc: true
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
jscs: {
|
|
||||||
main: [ "Gruntfile.js", "server.js", "routes/**", "models/**" ],
|
|
||||||
options: {
|
|
||||||
config: true,
|
|
||||||
fix: true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// Default task(s).
|
// Default task(s).
|
||||||
grunt.registerTask( "default", [ "jshint", "jscs" ] );
|
grunt.registerTask( "default", [ "jshint" ] );
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
"express": "^4.13.0",
|
"express": "^4.13.0",
|
||||||
"grunt": "^0.4.5",
|
"grunt": "^0.4.5",
|
||||||
"grunt-contrib-jshint": "^0.11.2",
|
"grunt-contrib-jshint": "^0.11.2",
|
||||||
"grunt-jscs": "^1.8.0",
|
|
||||||
"mongoose": "^4.0.6",
|
"mongoose": "^4.0.6",
|
||||||
"xml2js": "^0.4.9"
|
"xml2js": "^0.4.9"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
( function() {
|
( function() {
|
||||||
|
|
||||||
var http = require( "http" ),
|
var http = require( "http" ),
|
||||||
parseXML = require( "xml2js" ).parseString,
|
// parseXML = require( "xml2js" ).parseString,
|
||||||
Cache = require( "../models/Cache" ),
|
Cache = require( "../models/Cache" ),
|
||||||
|
|
||||||
// Define regex filters to match against location
|
// Define regex filters to match against location
|
||||||
@@ -92,7 +92,7 @@
|
|||||||
|
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
// Retrieve the historical weather data for the provided location
|
// Retrieve the historical weather data for the provided location
|
||||||
function getYesterdayWeatherData( location, callback ) {
|
function getYesterdayWeatherData( location, callback ) {
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@
|
|||||||
// Generate URL using WSI Cleaned History API in Imperial units showing daily average values
|
// 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 +
|
url = "http://cleanedobservations.wsi.com/CleanedObs.svc/GetObs?ID=" + WSI_HISTORY_KEY +
|
||||||
"&Lat=" + location[0] + "&Long=" + location[1] +
|
"&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
|
// Perform the HTTP request to retrieve the weather data
|
||||||
httpRequest( url, function( xml ) {
|
httpRequest( url, function( xml ) {
|
||||||
@@ -117,7 +117,7 @@
|
|||||||
});
|
});
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
// Update weather cache record in the local database
|
// Update weather cache record in the local database
|
||||||
function updateCache( location, weather ) {
|
function updateCache( location, weather ) {
|
||||||
|
|
||||||
@@ -163,7 +163,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Zimmerman method
|
// Zimmerman method
|
||||||
if ( adjustmentMethod == 1 ) {
|
if ( adjustmentMethod === 1 ) {
|
||||||
|
|
||||||
var humidityFactor = ( 30 - rh ),
|
var humidityFactor = ( 30 - rh ),
|
||||||
tempFactor = ( ( temp - 70 ) * 4 ),
|
tempFactor = ( ( temp - 70 ) * 4 ),
|
||||||
@@ -237,7 +237,7 @@
|
|||||||
location = req.query.loc,
|
location = req.query.loc,
|
||||||
weatherUndergroundKey = req.query.key,
|
weatherUndergroundKey = req.query.key,
|
||||||
outputFormat = req.query.format,
|
outputFormat = req.query.format,
|
||||||
firmwareVersion = req.query.fwv,
|
// firmwareVersion = req.query.fwv,
|
||||||
remoteAddress = req.headers[ "x-forwarded-for" ] || req.connection.remoteAddress,
|
remoteAddress = req.headers[ "x-forwarded-for" ] || req.connection.remoteAddress,
|
||||||
|
|
||||||
// Function that will accept the weather after it is received from the API
|
// 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] );
|
return ( ( ( ( ( ( +ip[0] ) * 256 ) + ( +ip[1] ) ) * 256 ) + ( +ip[2] ) ) * 256 ) + ( +ip[3] );
|
||||||
}
|
}
|
||||||
|
|
||||||
function F2C( temp ) {
|
/*
|
||||||
|
function f2c( temp ) {
|
||||||
return ( temp - 32 ) * 5 / 9;
|
return ( temp - 32 ) * 5 / 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -419,8 +420,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Resolves the Month / Day / Year of a Date object
|
// Resolves the Month / Day / Year of a Date object
|
||||||
Date.prototype.toUSDate = function(){
|
function toUSDate( date ){
|
||||||
return ( this.getMonth() + 1 ) + "/" + this.getDate() + "/" + this.getFullYear();
|
return ( date.getMonth() + 1 ) + "/" + date.getDate() + "/" + date.getFullYear();
|
||||||
};
|
}
|
||||||
|
*/
|
||||||
} )();
|
} )();
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ var express = require( "express" ),
|
|||||||
mongoose = require( "mongoose" ),
|
mongoose = require( "mongoose" ),
|
||||||
Cache = require( "./models/Cache" ),
|
Cache = require( "./models/Cache" ),
|
||||||
CronJob = require( "cron" ).CronJob,
|
CronJob = require( "cron" ).CronJob,
|
||||||
port = process.env.PORT || 3000;
|
port = process.env.PORT || 3000,
|
||||||
app = express();
|
app = express();
|
||||||
|
|
||||||
if ( !process.env.PORT ) {
|
if ( !process.env.PORT ) {
|
||||||
@@ -30,7 +30,7 @@ app.use( function( req, res ) {
|
|||||||
} );
|
} );
|
||||||
|
|
||||||
// Start listening on the service port
|
// 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 );
|
console.log( "OpenSprinkler Weather Service now listening on port %s", port );
|
||||||
} );
|
} );
|
||||||
|
|||||||
Reference in New Issue
Block a user