From f62142ef45e17cf4601e5e2c546630241a5ea08c Mon Sep 17 00:00:00 2001 From: Maj Smerkol <maj.smerkol@ijs.si> Date: Mon, 27 Mar 2023 14:27:58 +0200 Subject: [PATCH] update for spider chart with hierarchical buttons --- .dockerignore | 0 .env | 17 +++--- .gitignore | 97 +++++++++++++++++++++++++++++++++++ app/__init__.py | 2 - app/api.py | 8 ++- app/assets/kpi_hierarchy.json | 35 +++++++++++++ 6 files changed, 148 insertions(+), 11 deletions(-) create mode 100644 .dockerignore create mode 100644 .gitignore create mode 100644 app/assets/kpi_hierarchy.json diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e69de29 diff --git a/.env b/.env index 385757b..ba385c5 100644 --- a/.env +++ b/.env @@ -5,14 +5,15 @@ PG_PORT=5432 PG_USER="urbanite" PG_PASSWORD="password" PG_DB="urbanite" -PG_HOST="0.0.0.0" +PG_HOST="db" FLASK_SECRET_KEY="secret" # URLS of other components with ports -DATA_DIR = "/storage/app/data" -HOST_DATA_DIR = "../storage_data" -TS_URL = "http://ts:8082" -DSS_URL = "http://dss:5003" -DEXI_DIR = "/storage/app/dexi" +DATA_DIR="/storage/app/data" +ASSETS_DIR="/storage/app/app/assets" +HOST_DATA_DIR="../storage_data" +TS_URL="http://ts:8082" +DSS_URL="http://dss:5003" +DEXI_DIR="/storage/app/dexi" # city - one of "bilbao", "amsterdam", "messina", "helsinki" -URBANITE_CITY="amsterdam" -DEVELOPMENT=True \ No newline at end of file +URBANITE_CITY="bilbao" +DEVELOPMENT=True diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0c1b528 --- /dev/null +++ b/.gitignore @@ -0,0 +1,97 @@ +.env +# Created by http://www.gitignore.io + +postgres-data/* +storage_data.zip +pg_data +storage_data + +### PyCharm ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm + +## Directory-based project format +.idea/ +# if you remove the above rule, at least ignore user-specific stuff: +# .idea/workspace.xml +# .idea/tasks.xml +# and these sensitive or high-churn files: +# .idea/dataSources.ids +# .idea/dataSources.xml +# .idea/sqlDataSources.xml +# .idea/dynamic.xml + +## File-based project format +*.ipr +*.iml +*.iws + +## Additional for IntelliJ +out/ + +# generated by mpeltonen/sbt-idea +.idea_modules/ + +# generated by JIRA plugin +atlassian-ide-plugin.xml + +# generated by Crashlytics plugin (for Android Studio and Intellij) +com_crashlytics_export_strings.xml + + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.cache +nosetests.xml +coverage.xml + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +gaenv_lib/ +appengine_config.py diff --git a/app/__init__.py b/app/__init__.py index 4466439..17d13bc 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -12,8 +12,6 @@ from pony.orm.dbapiprovider import OperationalError # load environment variables, add interal load_dotenv() -os.environ["DATA_DIR"] = "/storage/app/data" -os.environ["ASSETS_DIR"] = "/storage/app/assets" logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) diff --git a/app/api.py b/app/api.py index 2d8c47d..024313e 100644 --- a/app/api.py +++ b/app/api.py @@ -13,6 +13,7 @@ from app.entities import City, Simulation, Network, Plan api_bp = Blueprint("api", __name__) data_dir = f"{app.dotenv['DATA_DIR']}/{app.dotenv['URBANITE_CITY']}" +assets_dir = f"{app.dotenv['ASSETS_DIR']}" city = app.dotenv["URBANITE_CITY"] # Endpoints for EDA @@ -50,7 +51,12 @@ def evaluated_kpis_many(): ) as file: json_obj = json.loads(file.read()) jsons[sim_id] = json_obj - return jsons + + meta_path = f"{assets_dir}/kpi_hierarchy.json" + app.logger.debug("meta path %s", meta_path) + with open(meta_path) as f: + metadata = json.load(f) + return {"data": jsons, "metadata": metadata[city]} @app.route("/storage/dss/kpis", methods=["POST"]) diff --git a/app/assets/kpi_hierarchy.json b/app/assets/kpi_hierarchy.json new file mode 100644 index 0000000..daca4ed --- /dev/null +++ b/app/assets/kpi_hierarchy.json @@ -0,0 +1,35 @@ +{ + "bilbao": { + "Mobility Policy Quality": "0", + "Local": "1", + "City-wide": "1", + "Entry capacity to center": "1", + "Local Pollution": "2", + "Local Traffic": "2", + "City-wide Pollution": "2", + "City-wide Traffic": "2", + "City-wide Emissions": "3", + "City-wide Acoustic pollution": "3", + "City-wide Pedestrian travel time": "3", + "City-wide Daily internal bike travels": "3", + "Local Emissions": "3", + "Local Acoustic pollution": "3", + "Local Pedestrian travel time": "3", + "Local Daily internal bike travels": "3", + "Local NOx": "4", + "Local PM10": "4", + "Local CO2": "4", + "City-wide NOx": "4", + "City-wide PM10": "4", + "City-wide CO2": "4" + }, + "amsterdam": { + + }, + "helsinki": { + + }, + "messina": { + + } +} \ No newline at end of file -- GitLab