Fix unit tests and remove unused code
This commit is contained in:
@@ -1,14 +0,0 @@
|
|||||||
var mongoose = require( "mongoose" );
|
|
||||||
|
|
||||||
var cacheSchema = new mongoose.Schema( {
|
|
||||||
|
|
||||||
// Stores the current GPS location as unique for weather data cache
|
|
||||||
location: { type: String, unique: true },
|
|
||||||
|
|
||||||
// This is the end of day value for the humidity yesterday
|
|
||||||
yesterdayHumidity: Number,
|
|
||||||
currentHumidityTotal: Number,
|
|
||||||
currentHumidityCount: Number
|
|
||||||
} );
|
|
||||||
|
|
||||||
module.exports = mongoose.model( "Cache", cacheSchema );
|
|
||||||
183
package-lock.json
generated
183
package-lock.json
generated
@@ -170,11 +170,6 @@
|
|||||||
"tweetnacl": "^0.14.3"
|
"tweetnacl": "^0.14.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"bluebird": {
|
|
||||||
"version": "3.5.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.0.tgz",
|
|
||||||
"integrity": "sha1-eRQg1/VR7qKJdFOop3ZT+WYG1nw="
|
|
||||||
},
|
|
||||||
"body-parser": {
|
"body-parser": {
|
||||||
"version": "1.18.2",
|
"version": "1.18.2",
|
||||||
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.2.tgz",
|
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.2.tgz",
|
||||||
@@ -214,21 +209,11 @@
|
|||||||
"integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==",
|
"integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"bson": {
|
|
||||||
"version": "1.0.6",
|
|
||||||
"resolved": "https://registry.npmjs.org/bson/-/bson-1.0.6.tgz",
|
|
||||||
"integrity": "sha512-D8zmlb46xfuK2gGvKmUjIklQEouN2nQ0LEHHeZ/NoHM2LDiMk2EYzZ5Ntw/Urk+bgMDosOZxaRzXxvhI5TcAVQ=="
|
|
||||||
},
|
|
||||||
"buffer-from": {
|
"buffer-from": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.0.0.tgz",
|
||||||
"integrity": "sha512-83apNb8KK0Se60UE1+4Ukbe3HbfELJ6UlI4ldtOGs7So4KD26orJM8hIY9lxdzP+UpItH1Yh/Y8GUvNFWFFRxA=="
|
"integrity": "sha512-83apNb8KK0Se60UE1+4Ukbe3HbfELJ6UlI4ldtOGs7So4KD26orJM8hIY9lxdzP+UpItH1Yh/Y8GUvNFWFFRxA=="
|
||||||
},
|
},
|
||||||
"buffer-shims": {
|
|
||||||
"version": "1.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/buffer-shims/-/buffer-shims-1.0.0.tgz",
|
|
||||||
"integrity": "sha1-mXjOMXOIxkmth5MCjDR37wRKi1E="
|
|
||||||
},
|
|
||||||
"builtin-modules": {
|
"builtin-modules": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz",
|
||||||
@@ -474,14 +459,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
|
||||||
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
|
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
|
||||||
},
|
},
|
||||||
"cron": {
|
|
||||||
"version": "1.3.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/cron/-/cron-1.3.0.tgz",
|
|
||||||
"integrity": "sha512-K/SF7JlgMmNjcThWxkKvsHhey2EDB4CeOEWJ9aXWj3fbQJppsvTPIeyLdHfNq5IbbsMUUjRW1nr5dSO95f2E4w==",
|
|
||||||
"requires": {
|
|
||||||
"moment-timezone": "^0.5.x"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"currently-unhandled": {
|
"currently-unhandled": {
|
||||||
"version": "0.4.1",
|
"version": "0.4.1",
|
||||||
"resolved": "https://registry.npmjs.org/currently-unhandled/-/currently-unhandled-0.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/currently-unhandled/-/currently-unhandled-0.4.1.tgz",
|
||||||
@@ -1195,11 +1172,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/hooker/-/hooker-0.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/hooker/-/hooker-0.2.3.tgz",
|
||||||
"integrity": "sha1-uDT3I8xKJCqmWWNFnfbZhMXT2Vk="
|
"integrity": "sha1-uDT3I8xKJCqmWWNFnfbZhMXT2Vk="
|
||||||
},
|
},
|
||||||
"hooks-fixed": {
|
|
||||||
"version": "2.0.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/hooks-fixed/-/hooks-fixed-2.0.2.tgz",
|
|
||||||
"integrity": "sha512-YurCM4gQSetcrhwEtpQHhQ4M7Zo7poNGqY4kQGeBS6eZtOcT3tnNs01ThFa0jYBByAiYt1MjMjP/YApG0EnAvQ=="
|
|
||||||
},
|
|
||||||
"hosted-git-info": {
|
"hosted-git-info": {
|
||||||
"version": "2.7.1",
|
"version": "2.7.1",
|
||||||
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.7.1.tgz",
|
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.7.1.tgz",
|
||||||
@@ -1481,11 +1453,6 @@
|
|||||||
"verror": "1.10.0"
|
"verror": "1.10.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"kareem": {
|
|
||||||
"version": "1.5.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/kareem/-/kareem-1.5.0.tgz",
|
|
||||||
"integrity": "sha1-4+QQHZ3P3imXadr0tNtk2JXRdEg="
|
|
||||||
},
|
|
||||||
"kind-of": {
|
"kind-of": {
|
||||||
"version": "3.2.2",
|
"version": "3.2.2",
|
||||||
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz",
|
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz",
|
||||||
@@ -1529,11 +1496,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz",
|
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz",
|
||||||
"integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg=="
|
"integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg=="
|
||||||
},
|
},
|
||||||
"lodash.get": {
|
|
||||||
"version": "4.4.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz",
|
|
||||||
"integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk="
|
|
||||||
},
|
|
||||||
"longest": {
|
"longest": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz",
|
||||||
@@ -1714,132 +1676,11 @@
|
|||||||
"moment": ">= 2.9.0"
|
"moment": ">= 2.9.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"mongodb": {
|
|
||||||
"version": "2.2.34",
|
|
||||||
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-2.2.34.tgz",
|
|
||||||
"integrity": "sha1-o09Zu+thdUrsQy3nLD/iFSakTBo=",
|
|
||||||
"requires": {
|
|
||||||
"es6-promise": "3.2.1",
|
|
||||||
"mongodb-core": "2.1.18",
|
|
||||||
"readable-stream": "2.2.7"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"es6-promise": {
|
|
||||||
"version": "3.2.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-3.2.1.tgz",
|
|
||||||
"integrity": "sha1-7FYjOGgDKQkgcXDDlEjiREndH8Q="
|
|
||||||
},
|
|
||||||
"isarray": {
|
|
||||||
"version": "1.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
|
|
||||||
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
|
|
||||||
},
|
|
||||||
"process-nextick-args": {
|
|
||||||
"version": "1.0.7",
|
|
||||||
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz",
|
|
||||||
"integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M="
|
|
||||||
},
|
|
||||||
"readable-stream": {
|
|
||||||
"version": "2.2.7",
|
|
||||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.2.7.tgz",
|
|
||||||
"integrity": "sha1-BwV6y+JGeyIELTb5jFrVBwVOlbE=",
|
|
||||||
"requires": {
|
|
||||||
"buffer-shims": "~1.0.0",
|
|
||||||
"core-util-is": "~1.0.0",
|
|
||||||
"inherits": "~2.0.1",
|
|
||||||
"isarray": "~1.0.0",
|
|
||||||
"process-nextick-args": "~1.0.6",
|
|
||||||
"string_decoder": "~1.0.0",
|
|
||||||
"util-deprecate": "~1.0.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"string_decoder": {
|
|
||||||
"version": "1.0.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz",
|
|
||||||
"integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==",
|
|
||||||
"requires": {
|
|
||||||
"safe-buffer": "~5.1.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"mongodb-core": {
|
|
||||||
"version": "2.1.18",
|
|
||||||
"resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-2.1.18.tgz",
|
|
||||||
"integrity": "sha1-TEYTm986HwMt7ZHbSfOO7AFlkFA=",
|
|
||||||
"requires": {
|
|
||||||
"bson": "~1.0.4",
|
|
||||||
"require_optional": "~1.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"mongoose": {
|
|
||||||
"version": "4.13.13",
|
|
||||||
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-4.13.13.tgz",
|
|
||||||
"integrity": "sha512-QBuryf62TVwpbdsaeJS6Ym3/FlrMhp7Xa5MkuomIX+wBeOSkMR8MjIDuiMZVZmQvN8j9/FnL7uZ9DX2wIJifYw==",
|
|
||||||
"requires": {
|
|
||||||
"async": "2.6.0",
|
|
||||||
"bson": "~1.0.4",
|
|
||||||
"hooks-fixed": "2.0.2",
|
|
||||||
"kareem": "1.5.0",
|
|
||||||
"lodash.get": "4.4.2",
|
|
||||||
"mongodb": "2.2.34",
|
|
||||||
"mpath": "0.3.0",
|
|
||||||
"mpromise": "0.5.5",
|
|
||||||
"mquery": "2.3.3",
|
|
||||||
"ms": "2.0.0",
|
|
||||||
"muri": "1.3.0",
|
|
||||||
"regexp-clone": "0.0.1",
|
|
||||||
"sliced": "1.0.1"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"async": {
|
|
||||||
"version": "2.6.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/async/-/async-2.6.0.tgz",
|
|
||||||
"integrity": "sha512-xAfGg1/NTLBBKlHFmnd7PlmUW9KhVQIUuSrYem9xzFUZy13ScvtyGGejaae9iAVRiRq9+Cx7DPFaAAhCpyxyPw==",
|
|
||||||
"requires": {
|
|
||||||
"lodash": "^4.14.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"mpath": {
|
|
||||||
"version": "0.3.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/mpath/-/mpath-0.3.0.tgz",
|
|
||||||
"integrity": "sha1-elj3iem1/TyUUgY0FXlg8mvV70Q="
|
|
||||||
},
|
|
||||||
"mpromise": {
|
|
||||||
"version": "0.5.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/mpromise/-/mpromise-0.5.5.tgz",
|
|
||||||
"integrity": "sha1-9bJCWddjrMIlewoMjG2Gb9UXMuY="
|
|
||||||
},
|
|
||||||
"mquery": {
|
|
||||||
"version": "2.3.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/mquery/-/mquery-2.3.3.tgz",
|
|
||||||
"integrity": "sha512-NC8L14kn+qxJbbJ1gbcEMDxF0sC3sv+1cbRReXXwVvowcwY1y9KoVZFq0ebwARibsadu8lx8nWGvm3V0Pf0ZWQ==",
|
|
||||||
"requires": {
|
|
||||||
"bluebird": "3.5.0",
|
|
||||||
"debug": "2.6.9",
|
|
||||||
"regexp-clone": "0.0.1",
|
|
||||||
"sliced": "0.0.5"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"sliced": {
|
|
||||||
"version": "0.0.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/sliced/-/sliced-0.0.5.tgz",
|
|
||||||
"integrity": "sha1-XtwETKTrb3gW1Qui/GPiXY/kcH8="
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"ms": {
|
"ms": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||||
},
|
},
|
||||||
"muri": {
|
|
||||||
"version": "1.3.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/muri/-/muri-1.3.0.tgz",
|
|
||||||
"integrity": "sha512-FiaFwKl864onHFFUV/a2szAl7X0fxVlSKNdhTf+BM8i8goEgYut8u5P9MqQqIYwvaMxjzVESsoEm/2kfkFH1rg=="
|
|
||||||
},
|
|
||||||
"negotiator": {
|
"negotiator": {
|
||||||
"version": "0.6.1",
|
"version": "0.6.1",
|
||||||
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz",
|
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz",
|
||||||
@@ -5359,11 +5200,6 @@
|
|||||||
"strip-indent": "^1.0.1"
|
"strip-indent": "^1.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"regexp-clone": {
|
|
||||||
"version": "0.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/regexp-clone/-/regexp-clone-0.0.1.tgz",
|
|
||||||
"integrity": "sha1-p8LgmJH9vzj7sQ03b7cwA+aKxYk="
|
|
||||||
},
|
|
||||||
"repeat-string": {
|
"repeat-string": {
|
||||||
"version": "1.6.1",
|
"version": "1.6.1",
|
||||||
"resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz",
|
"resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz",
|
||||||
@@ -5406,25 +5242,11 @@
|
|||||||
"uuid": "^3.1.0"
|
"uuid": "^3.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"require_optional": {
|
|
||||||
"version": "1.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/require_optional/-/require_optional-1.0.1.tgz",
|
|
||||||
"integrity": "sha512-qhM/y57enGWHAe3v/NcwML6a3/vfESLe/sGM2dII+gEO0BpKRUkWZow/tyloNqJyN6kXSl3RyyM8Ll5D/sJP8g==",
|
|
||||||
"requires": {
|
|
||||||
"resolve-from": "^2.0.0",
|
|
||||||
"semver": "^5.1.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"resolve": {
|
"resolve": {
|
||||||
"version": "1.1.7",
|
"version": "1.1.7",
|
||||||
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.1.7.tgz",
|
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.1.7.tgz",
|
||||||
"integrity": "sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs="
|
"integrity": "sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs="
|
||||||
},
|
},
|
||||||
"resolve-from": {
|
|
||||||
"version": "2.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-2.0.0.tgz",
|
|
||||||
"integrity": "sha1-lICrIOlP+h2egKgEx+oUdhGWa1c="
|
|
||||||
},
|
|
||||||
"resolve-protobuf-schema": {
|
"resolve-protobuf-schema": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/resolve-protobuf-schema/-/resolve-protobuf-schema-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/resolve-protobuf-schema/-/resolve-protobuf-schema-2.0.0.tgz",
|
||||||
@@ -5539,11 +5361,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/slice-source/-/slice-source-0.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/slice-source/-/slice-source-0.4.1.tgz",
|
||||||
"integrity": "sha1-QKV6wDxmaLXaIA4FN44AC/KmHXk="
|
"integrity": "sha1-QKV6wDxmaLXaIA4FN44AC/KmHXk="
|
||||||
},
|
},
|
||||||
"sliced": {
|
|
||||||
"version": "1.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/sliced/-/sliced-1.0.1.tgz",
|
|
||||||
"integrity": "sha1-CzpmK10Ewxd7GSa+qCsD+Dei70E="
|
|
||||||
},
|
|
||||||
"source-map": {
|
"source-map": {
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.2.0.tgz",
|
||||||
|
|||||||
@@ -7,13 +7,11 @@
|
|||||||
"test": "mocha test"
|
"test": "mocha test"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cron": "^1.3.0",
|
|
||||||
"dotenv": "^2.0.0",
|
"dotenv": "^2.0.0",
|
||||||
"express": "^4.16.3",
|
"express": "^4.16.3",
|
||||||
"geo-tz": "^4.0.1",
|
"geo-tz": "^4.0.1",
|
||||||
"grunt": "^1.0.3",
|
"grunt": "^1.0.3",
|
||||||
"moment-timezone": "^0.5.17",
|
"moment-timezone": "^0.5.17",
|
||||||
"mongoose": "^4.13.13",
|
|
||||||
"suncalc": "^1.8.0"
|
"suncalc": "^1.8.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
var http = require( "http" ),
|
var http = require( "http" ),
|
||||||
Cache = require( "../models/Cache" ),
|
|
||||||
SunCalc = require( "suncalc" ),
|
SunCalc = require( "suncalc" ),
|
||||||
moment = require( "moment-timezone" ),
|
moment = require( "moment-timezone" ),
|
||||||
geoTZ = require( "geo-tz" ),
|
geoTZ = require( "geo-tz" ),
|
||||||
@@ -105,14 +104,7 @@ function getOWMWeatherData( location, callback ) {
|
|||||||
|
|
||||||
location = location.join( "," );
|
location = location.join( "," );
|
||||||
|
|
||||||
getCache( {
|
callback( weather );
|
||||||
key: "yesterdayHumidity",
|
|
||||||
location: location,
|
|
||||||
weather: weather,
|
|
||||||
callback: callback
|
|
||||||
} );
|
|
||||||
|
|
||||||
updateCache( location, weather );
|
|
||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
@@ -135,58 +127,6 @@ function getTimeData( location, callback ) {
|
|||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve cached record for a given location
|
|
||||||
// opt is defined as an object with two required items
|
|
||||||
// opt.location defines the location for the cache record
|
|
||||||
// opt.key defines the key to return for the location
|
|
||||||
function getCache( opt, callback ) {
|
|
||||||
|
|
||||||
// Find the cache entry for the provided location
|
|
||||||
Cache.findOne( { location: opt.location }, function( err, record ) {
|
|
||||||
|
|
||||||
if ( err ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If a record is found for the provided key, return it
|
|
||||||
if ( record && record[ opt.key ] !== null ) {
|
|
||||||
opt.weather[ opt.key ] = record[ opt.key ];
|
|
||||||
}
|
|
||||||
|
|
||||||
opt.callback( opt.weather );
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update weather cache record in the local database
|
|
||||||
function updateCache( location, weather ) {
|
|
||||||
|
|
||||||
// Search for a cache record for the provided location
|
|
||||||
Cache.findOne( { location: location }, function( err, record ) {
|
|
||||||
|
|
||||||
if ( err ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If a record is found update the data and save it
|
|
||||||
if ( record ) {
|
|
||||||
|
|
||||||
record.currentHumidityTotal += weather.humidity;
|
|
||||||
record.currentHumidityCount++;
|
|
||||||
record.save();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// If no cache record is found, generate a new one and save it
|
|
||||||
new Cache( {
|
|
||||||
location: location,
|
|
||||||
currentHumidityTotal: weather.humidity,
|
|
||||||
currentHumidityCount: 1
|
|
||||||
} ).save();
|
|
||||||
|
|
||||||
}
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculates the resulting water scale using the provided weather data, adjustment method and options
|
// Calculates the resulting water scale using the provided weather data, adjustment method and options
|
||||||
function calculateWeatherScale( adjustmentMethod, adjustmentOptions, weather ) {
|
function calculateWeatherScale( adjustmentMethod, adjustmentOptions, weather ) {
|
||||||
|
|
||||||
@@ -394,7 +334,7 @@ exports.getWeather = function( req, res ) {
|
|||||||
|
|
||||||
// Attempt to resolve provided location to GPS coordinates when it does not match
|
// Attempt to resolve provided location to GPS coordinates when it does not match
|
||||||
// a GPS coordinate or Weather Underground location using Weather Underground autocomplete
|
// a GPS coordinate or Weather Underground location using Weather Underground autocomplete
|
||||||
resolveCoordinates( location, function( result, timezone ) {
|
resolveCoordinates( location, function( result ) {
|
||||||
if ( result === false ) {
|
if ( result === false ) {
|
||||||
res.send( "Error: Unable to resolve location" );
|
res.send( "Error: Unable to resolve location" );
|
||||||
return;
|
return;
|
||||||
|
|||||||
41
server.js
41
server.js
@@ -1,8 +1,5 @@
|
|||||||
var express = require( "express" ),
|
var express = require( "express" ),
|
||||||
weather = require( "./routes/weather.js" ),
|
weather = require( "./routes/weather.js" ),
|
||||||
mongoose = require( "mongoose" ),
|
|
||||||
Cache = require( "./models/Cache" ),
|
|
||||||
CronJob = require( "cron" ).CronJob,
|
|
||||||
host = process.env.HOST || "127.0.0.1",
|
host = process.env.HOST || "127.0.0.1",
|
||||||
port = process.env.PORT || 3000,
|
port = process.env.PORT || 3000,
|
||||||
app = express();
|
app = express();
|
||||||
@@ -13,14 +10,6 @@ if ( !process.env.HOST || !process.env.PORT ) {
|
|||||||
port = process.env.PORT || 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
|
// Handle requests matching /weatherID.py where ID corresponds to the
|
||||||
// weather adjustment method selector.
|
// weather adjustment method selector.
|
||||||
// This endpoint is considered deprecated and supported for prior firmware
|
// 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 );
|
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;
|
exports.app = app;
|
||||||
|
|||||||
17
test/api.js
17
test/api.js
@@ -15,7 +15,7 @@ describe( "Weather API", function() {
|
|||||||
loc: test,
|
loc: test,
|
||||||
key: process.env.WU_API_KEY,
|
key: process.env.WU_API_KEY,
|
||||||
expected: expected.WU[test],
|
expected: expected.WU[test],
|
||||||
callback: function( reply ) {
|
callback: function() {
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
@@ -30,7 +30,7 @@ describe( "Weather API", function() {
|
|||||||
method: 0,
|
method: 0,
|
||||||
loc: test,
|
loc: test,
|
||||||
expected: expected.noWeather[test],
|
expected: expected.noWeather[test],
|
||||||
callback: function( reply ) {
|
callback: function() {
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
@@ -69,18 +69,19 @@ function setupMocks( location ) {
|
|||||||
nock.cleanAll();
|
nock.cleanAll();
|
||||||
|
|
||||||
nock( "http://autocomplete.wunderground.com" )
|
nock( "http://autocomplete.wunderground.com" )
|
||||||
.filteringPath( function( path ) {
|
.filteringPath( function() { return "/"; } )
|
||||||
return "/";
|
|
||||||
} )
|
|
||||||
.get( "/" )
|
.get( "/" )
|
||||||
.reply( 200, replies[location].WUautoComplete );
|
.reply( 200, replies[location].WUautoComplete );
|
||||||
|
|
||||||
nock( "http://api.wunderground.com" )
|
nock( "http://api.wunderground.com" )
|
||||||
.filteringPath( function( path ) {
|
.filteringPath( function() { return "/"; } )
|
||||||
return "/";
|
|
||||||
} )
|
|
||||||
.get( "/" )
|
.get( "/" )
|
||||||
.reply( 200, replies[location].WUyesterday );
|
.reply( 200, replies[location].WUyesterday );
|
||||||
|
|
||||||
|
nock( "http://api.openweathermap.org" )
|
||||||
|
.filteringPath( function() { return "/"; } )
|
||||||
|
.get( "/" )
|
||||||
|
.reply( 200, replies[location].OWMData );
|
||||||
}
|
}
|
||||||
|
|
||||||
function extend( target ) {
|
function extend( target ) {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
"tz": 32,
|
"tz": 32,
|
||||||
"sunrise": 324,
|
"sunrise": 324,
|
||||||
"sunset": 1228,
|
"sunset": 1228,
|
||||||
"eip": 2130706433
|
"eip": null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"noWeather": {
|
"noWeather": {
|
||||||
@@ -14,9 +14,9 @@
|
|||||||
"scale": -1,
|
"scale": -1,
|
||||||
"rd": -1,
|
"rd": -1,
|
||||||
"tz": 32,
|
"tz": 32,
|
||||||
"sunrise": 324,
|
"sunrise": 333,
|
||||||
"sunset": 1226,
|
"sunset": 1221,
|
||||||
"eip": 2130706433
|
"eip": null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1535
test/replies.json
1535
test/replies.json
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user