A new Scenario Type has been introduced, called SOURCE_FILE. After uploading a source, the source is deepcopied, and inserted as a parent of the SOURCE scenario. This happens after functions which fix zero duration or zero distance trips and creating opp stations at depots when needed. This source_file scenario should never be mutated. The SOURCE scenario is now mutable by a filter_scenario view, which permanently removes rotations/stations/lines. This is only possible as long as there are no other children of this scenario.
How to create public data scenarios. Admins can now easily add Scenarios which can be selected by users to run a scenarios without uploading data. Steps
- Login as Superuser
2a. Upload a Scenarios using the standard way/trips.html OR
2b. Upload a Scenarios using the scenario_tee import
- If the tree does not contain a Mutation-Scenario create one
- Create a variant using the "Szenarien" Tab. Click on "Variante Erstellen" filter it the way you like using the wizards "Simulationsfilter"
- If the tree does not contain a Mutation-Scenario create one
- Go to the admin panel, select the created mutation scenario and make the scenario a PUBLIC_DATA scenario
Most Models have been added to the scenario panel. If you search for a specific item a query can be added to the model url,
vehicletype/?battery_capacity__gte=500&name__contains=MyVehicleType
To allow caching, enable permanent celery results storage and use the same stack as production. Redis is very recommended. Install redis and use the following .env settings
REDIS_URL=redis://127.0.0.1:6379
CELERY_BROKER_URL=redis://127.0.0.1:6379
CELERY_RESULT_BACKEND='redis://127.0.0.1:6379'This removes rabbitmq or other brokers from the necessary dependencies. REDIS_URL is used for caching and needs to be redis. If no REDIS_URL is supplied, caching will be skipped. CELERY_BROKER_URL is the broker which manages celery task management. CELERY_RESULT_BACKEND is used to store results. CELERY_TASK_RESULT_EXPIRES can be used to define how long the results are stored (in seconds). default is 1 day.
-
Clone this git repository (or download a specific release)
git clone git@github.com:rl-institut/django-simba.git
-
Install prerequisites
- The currently suggested Python version is 3.11.*, it may work with other versions, but this is not tested.
- This software requires GDAL, which can be installed
- The software requires a PostgreSQL database with the PostGIS package.
- The software is found here and here or via your system's (or server's) package manager (e.g.
apt install postgis) - When the elevation_api is used postgis_raster is needed
- can be installed by connecting to your database and running
create extension postgis_raster; - The credentials for the database are set in
ebusdjango/settings.pyin theDATABASESvariable. SECURITY WARNING: Do not commit your passwords to GitHub! - In order to set up PostGIS, the user you created needs to have 'superuser' privileges.
- The software is found here and here or via your system's (or server's) package manager (e.g.
- The software can optionally use backend for Celery to be available. Its address is set in the
CELERY_BROKER_URLin the.envfile.- rabbitmq can be installed on ubuntu using
apt install rabbitmq-server - A user can be added using the following commands (or the guest user can bs used):
rabbitmqctl add_user $user $passwordrabbitmqctl set_permissions -p / $user ".*" ".*" ".*"
- rabbitmq can be installed on ubuntu using
- Install poetry for environment and dependency management.
- The dependencies can be installed via
For developers, use
poetry install
poetry install --with dev
- Django uses an .env file to read user specific data. This file has to be created by the user and is not shared through GitHub to make uploads of sensitive data impossible. Create a file named
.envwith the following input`
DJANGO_SECRET_KEY=INSERT_YOUR_KEY_HERE DJANGO_DEBUG=True # Replace with your own database info DATABASE_URL=postgis://YOUR_DB_USERNAME:YOUR_PASSWORD@localhost/YOUR_DB_NAME # Should the simulation run with eflips-depot. Development setting which will be set to True in stable Versions. EFLIPS_USE=TRUE # Redis backend url. This allows caching. Can be the same as the celery broker url but does not have to be REDIS_URL=redis://127.0.0.1:6379 # Should celery be used synchronously? In this case no celery process and CELERY_BROKER_URL is needed. CELERY_TASK_ALWAYS_EAGER=True # CELERY_BROKER_URL=pyamqp://guest@localhost// TILING_SERVICE_TOKEN=GET_YOUR_TOKEN_THROUGH_MAP_TILER TILING_SERVICE_STYLE_ID=basic-v2 DJANGO_SETTINGS_MODULE=ebusdjango.settings # If you are developing locally set this to true. It disables production security features. DJANGO_LOCAL_DEVELOPMENT=True # for elevation API usage DJANGO_ELEVATION_TOKEN=YOUR_TOKEN_ELEVATION_TOKEN OPENELEVATION_URL=http://127.0.0.1:8000/elevation_api/YOUR_TOKEN_ELEVATION_TOKEN # If no admin user exists in the database, one will be autogenerated with this password DJANGO_ADMIN_PASSWORD=SOME_ADMIN_PASSWORD -
Set up django (inside the virtual environment)
- Set up the database:
python manage.py migrate - Create admin account:
python manage.py createsuperuserTODO: Is this necessary?
- Set up the database:
- Only if
.envhas a celery broker listed, start a celery worker (in another terminal):celery -A ebusdjango worker -l info- on macOS
OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YESbefore the command may be necessary
- on macOS
- Run the server:
python manage.py runserver - For the design, Tailwind is used. Therefore, styles have to be compiled with
python manage.py tailwind start. While developing and changing designs, this should run parallel to Django. Later, it might have to be called once to generate styles.
For development dependencies can be installed via
poetry install --with devTo run tests your PostgreSQL user needs SUPERUSER rights to be able to create test databases and delete them. Furthermore, for testing with selenium chromedriver is needed. Resources can be found here Latest Google Chrome and Chromedriver. Chromedriver has to be added to PATH.
During development, it might be necessary to delete the database and recreate it. The following instructions seem to work for Linux/Ubuntu go into terminal and log in as postgres superuser
sudo -i -u postgresGet into sql
psql -U postgresDrop the old database
DROP DATABASE your_database;Create new database
CREATE DATABASE your_database;go into database via
\c mydbor exit with \q and connect directly from normal terminal
psql -U postgres -d mydbDefine settings and install postgis and show installation worked
CREATE EXTENSION IF NOT EXISTS postgis;
SELECT PostGIS_version();A database dump can be used to fill the database. In your terminal navigate to the dump file ending with sql. If it is a text based dump use
psql -U YourProjectuser -h 127.0.0.1 YourDBName < DumpFileName.sql;For some reason specifying the host seems to be needed on my machine. This has something to do how authentification seems to work.
To build a docker locally install docker using https://docs.docker.com/engine/install/
Make sure to not have other dockers installed https://docs.docker.com/engine/install/ubuntu/#uninstall-old-versions
For me only installing from package worked https://docs.docker.com/engine/install/ubuntu/#install-from-a-package
wsl users can try following this https://docs.docker.com/desktop/wsl/
Go into your django-simba root containing manage.py
Make sure your .env file reflects the docker-compose.yml properties
DATABASE_URL=postgis://myprojectuser:1234@my-docker-postgres:5432/mydb
CELERY_BROKER_URL=redis://my-docker-redis:6379/0
When running locally for development some security settings need to be applied by setting in the .env file
DJANGO_LOCAL_DEVELOPMENT=True
Navigate to your cloned repo of django-simba in a terminal. Now running the following line, builds and starts a docker container including creating a database
sudo docker compose upAfter this django-simba will be available under http://127.0.0.1:8000/
To stop containers and remove containers, networks, volumes, and images created by up, run
sudo docker compose downThe build has to be repeated if dependencies change. This can be fixed by rebuilding the docker or removing containers, volumes and images and running again
sudo docker compose upChanges in the source code or templates are reflected live, even while running the docker container.
Create a network for your postgres and django-app to communicate
docker network create mynetworkOptional check your networks
sudo docker network lsrun a postgis instance in this network. Set your database according to your settings
sudo docker run --name my-docker-postgres -e POSTGRES_PASSWORD=1234 -e POSTGRES_USER=myprojectuser -e POSTGRES_DB=mydb -d --network=mynetwork postgis/postgisGo into your Django .env file and make sure the host is the same as in the above db, e.g. my-docker-postgres. This replaces "localhost" in the database url, e.g.
DATABASE_URL=postgis://myprojectuser:1234@my-docker-postgres:5432/mydbThe .env used while building will define which configuration the dockerimage will use Build your Django-simba docker
sudo docker build -t django-simba .run the created docker in this network and expose the port
sudo docker run -p 8000:8000 --network=mynetwork django-simbaOptional you can use the flag -d to start the container as detached. This means closing the terminal will NOT stop the container to stop the container
sudo docker stop CONTAINER_IDIn the above options only docker compose uses a permanent storage for the database. By creating the volume postgres_data. In other words stopping the container and starting it again, the database will not have lost its data. At the same time, migrations have to respect the existing data as well.
sudo docker volume lsor removed
sudo docker volume rm VOLUME_IDbut only if the docker is not running
- Search function provided with local db.
- Admin Areas from level 4 (Bundesland) to 8 (Gemeinden) for Germany are queried in a hierarchical manner
- bus_stops are queried with a guaranteed relation to the highest found admin_level up to level 8. The admin area hierarchy in Germany is complicated. Not every location is part of an admin area of level 8. In these cases the highest found admin area is used
- Introduces an API and map to find bus stops by name.
- /data_scrapers/stations/map/?search_stations=S%2BU Alexanderplatz/Memhardstraße
- /data_scrapers/stations/api/?search_stations=S%2BU Alexanderplatz/Memhardstraße
- the API returns the results as JSON
- if querying for multiple stations use '|' as delimiter
- the keyword query param '&filter=true' can be added to use filters, which try to uniquely identify the searched stations. Default is filter=false
- /data_scrapers/stations/api/?search_stations=Alexanderplatz
- finds multiple Alexanderplatz bus_stops around Germany
- /data_scrapers/stations/api/?search_stations=Alexanderplatz&filter=True
- finds no bus_stop since the found stations relate to different bus_stops, since the distance between each other is above a threshold -/data_scrapers/stations/api/?search_stations=S%2BU%20Alexanderplatz/Memhardstra%C3%9Fe|Alexanderplatz&filter=false
- finds the station at Memhardstraße and several Alexanderplatz stops around Germany
-/data_scrapers/stations/api/?search_stations=S%2BU%20Alexanderplatz/Memhardstra%C3%9Fe|Alexanderplatz&filter=true
- Finds the stop at Memhardstraße. Since this station is uniquely identified Alexanderplatz is found as well, since it's assumed that stations of a bus system are located next to each other.
- Search Features:
- Checks for Admin area names inside of searched name up to admin_level 8
- /data_scrapers/stations/api/?search_stations=Berlin+Alexanderplatz
- will find only the Alexanderplatz which is in Berlin
- Fuzzy search with trigram similarity
- Alekanderplatz finds bus_stop around Germany called Alexanderplatz
- Only the closest matches of the fuzzy search are returned
- If no unique stations can be found, previously found stations are used and:
- a convex hull of found stations with a buffer zone is created. This area is checked for a uniquely identifiable station
- admin_areas which contain found stations are fuzzily searched for a uniquely identifiable station
- Alekanderplatz finds bus_stop around Germany called Alexanderplatz
- Checks for Admin area names inside of searched name up to admin_level 8
- DB import and export are possible as superuser via /data_scrapers/stations/import/ and /export/
- import is only supported for empty tables of BusStation and AdminArea
The website supports basic translation. Text is marked with get_text. To create translation files for all languages in the settings file run.
django-admin makemessages -a
The translation becomes available when the msgstr inside these .po files is set and running
django-admin compilemessages
The Website supports temperature statistics via DWD-data. Currently they are used in supporting the user deciding on a scenario temperature. The closest weatherstation in regards to the scenario centroid with sufficient data is searched. Found data is used to compare user input to historical data, but using temperature timeseries for simulation could be possible in the future. Data is NOT automatically filled into the db. Admins can upload temperature data to their liking via /temperatures/import/ The expected fileformat is a zip containing hourly, historical data of air_temperature found here
TU_Stundenwerte_Beschreibung_Stationen.txt
stundenwerte_TU_00003_19500401_20110331_hist.zip
stundenwerte_TU_00003_19500401_20110331_hist.zip
...
Temperature fetching uses caching. This requires a REDIS_URL. If no REDIS_URL is given, caching should be skipped.
Some visual assets in this project are licensed from Freepik under a Premium License. These assets are provided only for use within this project. They cannot be reused, redistributed, or modified outside of this context without obtaining a valid Freepik license.