The simulation logic and database management for the K-dPS project. For the interactive website see the frontend folder.
For general information on the project like e.g. licensing information or future plans, see the Project README.
- install from official python website
- version should be at least 3.12
- navigate into backend folder
pip install -r requirements.txt
We are using black as a biased formatter for the whole project. For more information about black see: Black
- make sure you have python extension installed
- download "Black Formatter" from marketplace
- right-click on a python file
- select "Format Document with"
- select "Configure Default formatter"
- select "Black"
- head to VS Code settings
- search for "format on save"
- enable "Editor: Format on Save"
Running the project without docker is currently not tested/supported.
For more information on the difference between prod
and dev
, see the docs file.
Note that the prod
env file here still assumes this is running locally -
meaning it will expect the frontend to run on localhost.
Build and run:
docker compose --env-file .env.<prod/dev> up --build
Optionally, to access the database, create a superuser account:
docker exec -it K-dPS-django python manage.py createsuperuser
Afterwards, you can log into the admin interface at e.g. http://localhost:80/admin/
Note: this is only available if DEBUG = true, which is the case in the dev environment.
When changing models, you need to create migrations in order to update existing databases.
- Create new migrations:
docker exec -it K-dPS-django python manage.py makemigrations
- Optionally, if you have conflicting migrations:
docker exec -it K-dPS-django python manage.py migrate --merge
- Execute these migrations to update the database:
docker exec -it K-dPS-django python manage.py migrate
- start docker container with docker compose(see Running the project using Docker)
- wait until Application Startup is Completed
- run:
docker exec -it K-dPS-django python manage.py test
Example given for creating the "patient_states.json" fixture containing all patientstates, statetransitions, subconditions and logicnodes.
- clear database of the wanted models via e.g.
docker exec -it K-dPS-django python manage.py flush
- fill database with data you want to export as fixture:
docker exec -it K-dPS-django python manage.py import_patient_states
- create fixture:
docker exec -it K-dPS-django bash
export PYTHONIOENCODING=utf8
python manage.py dumpdata template.patientstate template.statetransition template.subcondition template.logicnode > data/fixtures/patient_states.json
- now you can load it:
docker exec -it K-dPS-django python manage.py loaddata patient_states.json