-
-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable external data sources to be added and accessed #188
base: main
Are you sure you want to change the base?
Conversation
@mrchrisadams 🎉 the main files to look at for this change are:
I can show you an example of this in action if you want. |
One thing I might look to change here is to pass an options object into the So instead of: const taiwanZoneLatest = await eMaps.source.getLatest("TW");
const taiwanLatLonLatest = await eMaps.source.getLatest(undefined, "23.6978", "120.9605"); You'd have: const taiwanZoneLatest = await eMaps.source.getLatest({ zone: "TW" });
const taiwanLatLonLatest = await eMaps.source.getLatest({ lat: "23.6978", lon: "120.9605" }); |
Probably also need someone from Electricity Maps to confirm the proper API base URL we should be using here for the free tier routes. Is it |
Hey @fershad, happy to quickly answer this one - and we'd also love to jump on a call together with you guys to give more details and context if required! We are in the process of aligning everything under the Users can get a token to use for the free tier over at https://api-portal.electricitymaps.com/. |
PS. We're also thinking of building SDKs for interacting with the API - would you be interested in using that if we did, or do you prefer having your own code for this? :) PPS. This is really cool and we're super excited that you're implementing this! 😍 |
const query = `${lat ? `lat=${lat}&` : ""}${lon ? `lon=${lon}&` : ""}${ | ||
zone ? `zone=${zone}` : "" | ||
}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how big of a deal this is, but with this current usage it's possible to call the API with both a zone and coordinates. In this case the coordinates overrule on our end :)
This PR adds the Electricity Maps API as an external data sources which can be accessed within CO2.js (#134).
This change adds a new
DataSource
class which is exposed to users. The class has as single functionset()
which is used to set the data source being used.Each data source is its own class, and can contain any number of functions which map to the structure of the external API being queried.
In the case of Electricity Maps, we use the free API endpoint and expose three functions:
getLatest
- returns the current grid intensity for the region (zone or lat+lon) from the Electricity Maps API.getHistory
- returns the last 24 hours grid intensity for the region (zone or lat+lon) from the Electricity Maps API.getZones
- returns a list of all available zones that can be queried from the Electricity Maps API.For example, to get the latest grid intensity for Taiwan we can:
With this update, it will also be possible for additional data sources to be added. The kinds of data sources which could be added are not just limited to grid intensity either, meaning it could be possible to add an adaptor for connecting with a service like the Boavista API (for example) to return environmental impact data for hardware and cloud devices.