This datastore app provides an API for storing consumption data, project data, and reading meter run data. It is an OAuth 2 provider.
- postgres
git clone git@github.com:impactlab/oeem-energy-datastore.git
cd oeem-energy-datastore
We recommend using virtualenv (or virtualenvwrapper) to manage python packages
mkvirtualenv oeem-energy-datastore
pip install -r requirements.txt
pip install -r dev-requirements.txt
createdb oeem_energy_datastore
export DJANGO_SETTINGS_MODULE=oeem_energy_datastore.settings
export DATABASE_URL=postgres://:@localhost:5432/oeem_energy_datastore
export SECRET_KEY=<django-secret-key>
export DJANGO_LOGFILE=django.log
export CELERY_LOGFILE=celery.log
export BROKER_HOST=0.0.0.0:5672 # Placeholder (not currently used - can be any valid URI)
# For development only
export DEBUG=true
# for API docs
export SERVER_NAME=0.0.0.0:8000 # the IP or DNS name where datastore will be deployed
export PROTOCOL=http
You might consider adding these to your virtualenv postactivate script
vim /path/to/virtualenv/oeem-energy-datastore/bin/postactivate
# refresh environment
workon oeem-energy-datastore
python manage.py migrate
python manage.py createsuperuser
py.test
Run a single test:
py.test datastore/tests/views/test_project_run.py
python manage.py runserver
Once a superuser has been created for the client and the datastore, log in to the datastore and manually create the access token defined in the ini file.
In the admin, create a Django OAuth Toolkit application with the following attributes:
Client id: Use default
User: <pick a user or create a new one>
Redirect URI: https://example-client.openeemeter.org (this can actually be any url - we don't use it when creating an application manually)
Client type: Confidential
Authorization grant type: Authorization code
Client secret: Use default
Name: OEEM Client (can be anything that helps you remember)
Then go over and manually create a Django OAuth Toolkit access token with the following attributes.
User: <same user as for the application>
Token: <any string of characters - preferably at least 30 chars long and random>
Application: <the application you just created>
Expires: <some future date>
Scope: "read write" (no quotes)
The environment variable DATASTORE_ACCESS_TOKEN
should be set to the value
of this access token in the client's deployment environment. E.g.
export DATASTORE_ACCESS_TOKEN=YOUR_TOKEN_GOES_HERE
You will upload data to the datastore and view it in the client.
See the API in at this datastore URL: http://0.0.0.0:8000/docs/
Once data is uploaded, you'll need to run the following management command to actually run the meters.
./manage.py runmeter