Metadata-Version: 2.1
Name: django-oemof
Version: 0.18.2
Summary: Django application to run oemof
License: AGPL-3.0
Author: Hendrik Huyskens
Author-email: hendrik.huyskens@rl-institut.de
Requires-Python: >=3.9,<4.0
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Dist: celery (>=5.1.2,<6.0.0)
Requires-Dist: django-environ (>=0.10.0,<0.11.0)
Requires-Dist: djangorestframework (>=3.14.0,<4.0.0)
Requires-Dist: numpy (<2.0)
Requires-Dist: pandas (>2.0)
Requires-Dist: psycopg2-binary (>=2.9.10,<3.0.0)
Description-Content-Type: text/markdown

# Django-Oemof

Django-Oemof is a Django app to provide an API to build and optimize oemof.solph models and deliver results via JSON response.

## Requirements

- `oemof.tabular` has to be installed 
- CBC solver has to be installed. Install it via (conda):
```
conda install -c conda-forge coincbc
```

Django project must use celery and automatically detect celery tasks. (follow https://docs.celeryq.dev/en/stable/django/first-steps-with-django.html to setup celery)

## Quick start

1. Add "oemof" to your INSTALLED_APPS setting like this::
    ```
        INSTALLED_APPS = [
            ...
            'rest_framework'
            'django_oemof',
        ]
    ```

2. Include the oemof URLconf in your project urls.py like this::

    path('oemof/', include('django_oemof.urls')),

3. Run ``python manage.py migrate`` to create the oemof models.

## Configuration

You can set following configs via environment:

- DJANGO_OEMOF_IGNORE_SIMULATION_PARAMETERS
  list of parameter keys which shall be ignored when initializing a simulation 

## OEMOF Datapackages

Have to be put in folder `oemof` within djangos `MEDIA_ROOT` folder.
Name of datapackage folder is used in request for building ES.

## Hooks

Hooks can be used to change default behaviour of parameter setup, energysystem build and model solving.
This is done by defining custom functions which can be registered in django_oemof and are applied when simulating an ES.
Depending on hook type (Parameter/Energysystem/Model), the defined custom functions are applied to parameters, build Es or after creating the model.
See following flow chart for order of hooks:

![Hook Flow Chart](./docs/images/oemof_flow.png)

Every hook is scenario-dependent to allow different hooks per scenario, but you can use `hooks.ALL_SCENARIO` as scenario to aplly hook to all scenarios.
An example hook (changing default behaviour of parameter setup) could be set up as follows:

```python

from django_oemof import hooks


def converting_demand_to_kW(data):
   data["demand"] = data["demand"] * 1000
   return data


demand_kW_hook = hooks.Hook(scenario="dispatch", function=converting_demand_to_kW)
hooks.register_hook(hooks.HookType.PARAMETER, demand_kW_hook)

```

## Tests

Run tests for standalone app via `python runtests.py`

