diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a8d3df..743a0c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,20 @@ Dates use DD/MM/YYYY format. +## 2.0.0 - 24/05/17 +* Increase performance by approximately 10x due to use of `pixl-xml` and +improved algorithm for getting weather nodes. +* Simplify codebase. +* Update JSON output format to be closer to the original XML content. This gives +users of this module more flexibility and information but is a breaking change. +* Add `getValidTimes` function. +* Fix security `request` and `qs` module vulnerabilities by updating to `yr.no-interface@1.0.1`. -# 1.0.0 26/04/2017 +## 1.0.1 - 28/04/2017 +* Mitigate security vulnerabilities. +* Use new yr.no-interface@1.0.0 internally. + +## 1.0.0 - 27/04/2017 * Change to Promise based interface. * Make the module a factory function. * Use `pixl-xml` to increase XML parsing speed and lower memory usage. Yay for @@ -13,5 +25,5 @@ better performance! passing the current timestamp. Simplifies API footprint. -# < 1.0.0 +## < 1.0.0 * Undocumented. Sorry. diff --git a/README.md b/README.md index 3bfa42a..e6c0c5c 100644 --- a/README.md +++ b/README.md @@ -74,40 +74,93 @@ many time formats will work, but a millisecond timestamp or ISO formatted date string are both ideal options to use use. ### LocationForecast.getXml() -Returns the XML string that the locationforecast API returned. +Returns the raw XML string that the `locationforecast` API returned. ### LocationForecast.getJson() -Returns the JSON representation of a locationforecast response. +Returns the JSON representation of the entire `locationforecast` response. ### LocationForecast.getFirstDateInPayload() Returns the first date string that is available in the data returned from the locationforecast call. +### LocationForecast.getValidTimes() +Returns an Array of ISO timestamps that represent points in time that we have +weather data for. + ## Weather JSON Format -Format is somewhat inspired by that of the -[forecast.io](https://developer.forecast.io/) service. Some fields will be undefined depending on the weather conditions. Always -verify the field you need exists by using `data.hasOwnProperty('fog')` -or similar techniques. +verify the field you need exists, e.g use `data.hasOwnProperty('fog')` or +similar techniques. -```js +```json { - icon: 'PARTLYCLOUD', - to: '2013-11-15T18:00:00Z', - from: '2013-11-15T12:00:00Z', - rain: '0.0 mm', - temperature: '9.7 celcius', - windDirection: { deg: '220.2', name: 'SW' }, - windSpeed: { mps: '2.7', beaufort: '2', name: 'Svak vind' }, - humidity: '27.9 percent', - pressure: '1021.0 hPa', - cloudiness: '0.0%', - fog: '0.0%', - lowClouds: '0.0%', - mediumClouds: '0.0%', - highClouds: '0.0%', - dewpointTemperature: '-8.3 celcius' + "datatype": "forecast", + "from": "2017-04-18T03:00:00Z", + "to": "2017-04-18T03:00:00Z", + "icon": "PartlyCloud", + "rain": "0.0 mm", + "altitude": "0", + "latitude": "59.8940", + "longitude": "10.6450", + "temperature": { + "id": "TTT", + "unit": "celsius", + "value": "-0.9" + }, + "windDirection": { + "id": "dd", + "deg": "14.6", + "name": "N" + }, + "windSpeed": { + "id": "ff", + "mps": "1.5", + "beaufort": "1", + "name": "Flau vind" + }, + "windGust": { + "id": "ff_gust", + "mps": "2.4" + }, + "humidity": { + "value": "78.3", + "unit": "percent" + }, + "pressure": { + "id": "pr", + "unit": "hPa", + "value": "1030.1" + }, + "cloudiness": { + "id": "NN", + "percent": "15.4" + }, + "fog": { + "id": "FOG", + "percent": "0.0" + }, + "lowClouds": { + "id": "LOW", + "percent": "15.4" + }, + "mediumClouds": { + "id": "MEDIUM", + "percent": "0.8" + }, + "highClouds": { + "id": "HIGH", + "percent": "0.0" + }, + "dewpointTemperature": { + "id": "TD", + "unit": "celsius", + "value": "-4.5" + } } ``` + +## CHANGELOG + +Can be found [at this link](https://github.com/evanshortiss/yr.no-forecast/blob/master/CHANGELOG.md ). diff --git a/benchmark/index.js b/benchmark/index.js new file mode 100644 index 0000000..e104c96 --- /dev/null +++ b/benchmark/index.js @@ -0,0 +1,40 @@ +'use strict'; + +const Benchmark = require('benchmark'); +const suite = new Benchmark.Suite; +const readFileSync = require('fs').readFileSync; +const join = require('path').join; +const sinon = require('sinon'); +const yrno = { + locationforecast: sinon.stub().yields( + null, + readFileSync(join(__dirname, '../fixtures/weather-response-oslo.xml'), 'utf8') + ) +}; +const forecast = require('proxyquire')('../index.js', { + 'yr.no-interface': sinon.stub().returns(yrno) +}); + +suite + .add( + '#getFiveDaySummary', + (deffered) => { + forecast().getWeather() + .then((weather) => weather.getFiveDaySummary()) + .then(() => deffered.resolve()); + }, + {defer: true} + ) + .add( + '#getForecastForTime', + (deffered) => { + forecast().getWeather() + .then((weather) => weather.getFiveDaySummary()) + .then(() => deffered.resolve()); + }, + {defer: true} + ) + .on('cycle', function(event) { + console.log(String(event.target)); + }) + .run(); diff --git a/fixtures/weather-response-oslo.xml b/fixtures/weather-response-oslo.xml index 3cfc880..3da37f0 100644 --- a/fixtures/weather-response-oslo.xml +++ b/fixtures/weather-response-oslo.xml @@ -5,411 +5,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -