What kind of electricity are you getting right now? The WattTime grid API collects real-time information on the current generation fuel mix from the major American electricity markets (MISO, PJM, CAISO, ERCOT, ISONE, SPP, and BPA) using the pyiso library and displays it in a convenient standardized format. The API also calculates a real-time carbon footprint of electricity use in a given place and time based on this fuel mix. See the code in action at http://api.watttime.org/!
All the Django apps are in watttime_grid_api/apps
. These are
gridentities
: provides models for metadata and descriptions of geographic entities (BalancingAuthority
andPowerPlant
) and data types (FuelType
); standalonegriddata
: provides models for time series data (DataPoint
); depends ongridentities
supply_demand
: providesGeneration
,Load
, andTieFlow
models that associates generation and load observations toDataPoint
s, and management commands and celery tasks for pulling the data; depends ongridentities
andgriddata
carbon
: providesCarbon
andFuelCarbonIntensity
models that associate carbon intensity observations toDataPoint
s, and tasks for calculating the data; depends ongridentities
,griddata
, andsupply_demand
marginal
: providesMOER
,MOERAlgorithm
, andStructuralModelSet
models that associate marginal carbon intensity observations (MOER) toDataPoint
s, and tasks for calculating the data; depends ongridentities
,griddata
, andsupply_demand
api
: implements a Django REST Framework API to all other apps; depends ongridentities
,griddata
,supply_demand
,carbon
, andmarginal
etl
: implements a extract-transform-load job flow to supply data to all other apps; depends ongridentities
,griddata
,supply_demand
,carbon
, andmarginal
Start a postgres server (eg http://postgresapp.com/) and create a database called mydbname
.
You'll also need libmemcached:
brew install libmemcached
Also install the GeoDjango requirements. See the platform-specific instructions at https://docs.djangoproject.com/en/dev/ref/contrib/gis/install/, I used homebrew:
brew install postgresql
brew install postgis
brew install libgeoip
psql mydbname
# CREATE EXTENSION postgis;
Clone this repo and install the requirements:
cd watttime-grid-api
mkvirtualenv watttime-grid-api
pip install -r reqs/dev.txt
Set up the environment variables. You can put then in a .env
file and use foreman
(get it at https://github.com/ddollar/foreman or as part of the Heroku CLI)
or put them in your bash profile or whatever.
If you're not using foreman, remove the 'foreman run' from all following commands.
echo DATABASE_URL=postgres://localhost/mydbname > .env
Create database tables for the models (create user when prompted):
foreman run ./manage.py syncdb
foreman run ./manage.py migrate
Test the site:
foreman run ./manage.py test
foreman run ./manage.py loaddata isos gentypes fuelcarbonintensities griddata
foreman run ./manage.py shell
>>> from apps.gridentities import load
>>> load.run_balancing_authority()
foreman run ./manage.py runserver
To run tasks with celery, run rabbitmq-server &
, then
celery -A watttime_grid_api worker -B -l info
or
foreman start
(if you have newrelic-admin
installed locally).