0.0.5 • Published 8 years ago

decentraleyes-weather v0.0.5

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

decentraleyes-weather

The decentraleyes-weather microservice reference implementation

The decentraleyes-weather microservice running on the Decentraleyes Open Platform Engine is an experiment in the integration of third-party data on a variety of levels. It makes use of the Dark Sky Weather API to pull live weather data for the greater Pittsburgh area of Pennsylvania. The location can be changed by editing decentraleyes-weather/service-options.js.

Goals

The eventual goal is for this service to cache and provide recent weather data for all users of Decentraleyes. For today, it is limited to providing weather data for one location per node. This is due to limited access and resource utilization on the free/no-cost tier of the Dark Sky Weather API. When I have enough budget to afford one, I will subscribe and develop unlockable features that permit per-user weather information to be offered by a decentraleyes node or might make per-user weather data available users who pay for service on a monthly basis.

I don't really know. I just wanted a weather app, and this works great for my uses. Perfect, actually. Install it, get your own free API key and have your node run weather data for your location. Poof. You have decentraleyes-weather for your location. I would rather you run your own node than pay me to get you weather data.

Configuration

A SysOp must sign up for an account on the Dark Sky weather service and receive their own API key. The free tier permits your node to issue up to 1,000 API requests per day, which is enough to provide the level of service you are seeing here. If you want your node's users to each be able to enter a zip code as a user preference and receive weather data specific to their location instead of the location of your node, you will need to subscribe to the Dark Sky serivce and pay a monthly fee that they have deemed appropriate for your level of resource utilization.

Weather Data Sources and Updating

Once every 90 seconds (by default), the server wakes up and fetches live data from Dark Sky. The response is stored mostly untransformed into decentraleyes.weathersamples collection in MongoDB. Timestamps are multiplied by 1,000 to convert them from seconds to milliseconds since the epoch. No other changes are made to the data received. Timestamps are changed only because the JavaScript Date class works with timestamps measured in milliseconds, not seconds.

As responses are received from the Dark Sky API, they are archived to MongoDB in the decentraleyes.weathersamples and decentraleyes.weatheralerts database collections. This design is what lets me serve out an unlimited number of requests for "recent enough" data without exceeding the 1,000 requests per day limitation of the free/no-cost Dark Sky API. While it generates many more calls for them that would otherwise be needed, it affords me an excellent opportunity to store data locally at regular intervals.

MongoDB's "upsert" functionality is used to ensure that duplicates are not created while allowing data in things like alerts to mutate if the they mutate upstream for the same timestamp. Back-to-back requests for the same alert can, for this reason, generate different answers. This is expected behavior - the upstream service simply updated the alert. Decentraleyes simply catches up to these upstream changes as they occur.

Timestamps are transformed by multiplying by 1,000 to convert from seconds since Jan 1, 1970, to milliseconds since Jan 1, 1970. Timestamps are not stored separately in the database. Timestamps (integers) are not stored in the local database. Instead, a JavaScript Date object is stored in the database to allow for the full range of MongoDB date-based queries as there is extreme interest in aggregating this information along calendar-based metrics.

Graphics

The recent history chart is generated using Chart.js. The satellite and radar imaging is provided by AccuWeather.com.

The weather direction arrows are a custom AngularJS directive that renders to <canvas>.

Known Issues

  • Radar and satellite views do not auto-refresh. This is by design as I am not a licensed user of that data and want to be kind.
  • Chart.js chart does not resize when the browser resizes. Easily fixed, and I'll get to it.
  • Dismissed weather alerts reappear. I'll get to it.

Reporting Issues

You can report a problem or make a suggestion for the decentraleyes-weather service on github. If you don't have a github account, please know that you don't have to be a developer to create one and they are free.