From bc2bc4309189d1fa4fbc7f76f184d381164e974a Mon Sep 17 00:00:00 2001
From: Gjorgji <g.noveski@yahoo.com>
Date: Fri, 31 Mar 2023 18:08:51 +0200
Subject: [PATCH] Adding kpi hierarchy all cities, added check for info.json

---
 app/__init__.py               | 79 ++++++++++++++++++-----------------
 app/assets/kpi_hierarchy.json | 55 ++++++++++++++++++++++--
 2 files changed, 93 insertions(+), 41 deletions(-)

diff --git a/app/__init__.py b/app/__init__.py
index 070772f..0d04a04 100644
--- a/app/__init__.py
+++ b/app/__init__.py
@@ -151,45 +151,48 @@ def setup_bilbao():
         simulations_path = Path(
             f"{app.dotenv['DATA_DIR']}/{app.dotenv['URBANITE_CITY']}/simulations"
         )
-        dirs = [x for x in simulations_path.iterdir() if x.is_dir()]
-        dirs.sort(key=lambda t: int(t.name))
-        app.logger.info(f"Found {dirs}")
-
-        # Inser the simulations based on the info.json file
-        for d in dirs:
-            info_json_path = d / "info.json"
-
-            if not info_json_path.exists():
-                app.logger.warning(
-                    f"info.json does not exists for {d.name}! It won't be added to the DB!"
+        if os.path.exists(simulations_path):
+            dirs = [x for x in simulations_path.iterdir() if x.is_dir()]
+            dirs.sort(key=lambda t: int(t.name))
+            app.logger.info(f"Found {dirs}")
+
+            # Inser the simulations based on the info.json file
+            for d in dirs:
+                info_json_path = d / "info.json"
+
+                if not info_json_path.exists():
+                    app.logger.warning(
+                        f"info.json does not exists for {d.name}! It won't be added to the DB!"
+                    )
+                    continue
+
+                with open(info_json_path) as info_file:
+                    info = json.load(info_file)
+
+                app.logger.info(f"Adding: {info['name']}")
+
+                network: Network = Network(
+                    name=info["name"],
+                    description=info["description"],
+                    city=bilbao,
+                    done_osm_processing=True,
+                    donematsim_processing=True,
                 )
-                continue
-
-            with open(info_json_path) as info_file:
-                info = json.load(info_file)
-
-            app.logger.info(f"Adding: {info['name']}")
-
-            network: Network = Network(
-                name=info["name"],
-                description=info["description"],
-                city=bilbao,
-                done_osm_processing=True,
-                donematsim_processing=True,
-            )
-            plan: Plan = Plan(name=info["name"], network=network)
-
-            Simulation(
-                city=bilbao,
-                name=info["name"],
-                description=info["description"],
-                plan=plan,
-                status=Status.CREATED,
-            )
-
-            app.logger.info(f"Bilbao simulation: {info['name']}")
-            app.logger.info(f"Bilbao network: {network}")
-            app.logger.info(f"Bilbao plans: {plan}")
+                plan: Plan = Plan(name=info["name"], network=network)
+
+                Simulation(
+                    city=bilbao,
+                    name=info["name"],
+                    description=info["description"],
+                    plan=plan,
+                    status=Status.CREATED,
+                )
+
+                app.logger.info(f"Bilbao simulation: {info['name']}")
+                app.logger.info(f"Bilbao network: {network}")
+                app.logger.info(f"Bilbao plans: {plan}")
+        else:
+            app.logger.info(f"No simulations folder present, skipping adding simulations from info.json")
 
 
 def setup_helsinki():
diff --git a/app/assets/kpi_hierarchy.json b/app/assets/kpi_hierarchy.json
index daca4ed..3ea4971 100644
--- a/app/assets/kpi_hierarchy.json
+++ b/app/assets/kpi_hierarchy.json
@@ -24,12 +24,61 @@
     "City-wide CO2": "4"
   },
   "amsterdam": {
-
+    "Mobility Policy Quality": "0",
+    "Local": "1",
+    "City-wide": "1",
+    "Local traffic": "2",
+    "Local bike infrastructure": "2",
+    "City-wide traffic": "2",
+    "City-wide bike infrastructure": "2",
+    "Local bike intensity": "3",
+    "Local bike congestion": "3",
+    "Local bike safety": "3",
+    "Local bikeability": "3",
+    "City-wide bike intensity": "3",
+    "City-wide bike congestion": "3",
+    "City-wide bike safety": "3",
+    "City-wide bikeability": "3"
   },
   "helsinki": {
-
+    "Mobility Policy Quality": "0",
+    "Local": "1",
+    "City-wide": "1",
+    "Harbour area traffic flow": "1",
+    "Local Pollution": "2",
+    "Local congestions and bottlenecks": "2",
+    "City-wide Pollution": "2",
+    "City-wide congestions and bottlenecks": "2",
+    "Local Emissions": "3",
+    "Local Acoustic Pollution": "3",
+    "City-wide Emissions": "3",
+    "City-wide Acoustic Pollution": "3",
+    "Local NOx": "4",
+    "Local PM10": "4",
+    "Local CO2": "4",
+    "City-wide NOx": "4",
+    "City-wide PM10": "4",
+    "City-wide CO2": "4"
   },
   "messina": {
-
+    "Mobility Policy Quality": "0",
+    "Local": "1",
+    "City-wide": "1",
+    "Local public transport": "2",
+    "Local trips share": "2",
+    "Local number of bike trips": "2",
+    "City-wide public transport": "2",
+    "City-wide trips share": "2",
+    "City-wide number of bike trips": "2",
+    "Local public transport use": "3",
+    "Local average speed of public transport": "3",
+    "Local share of public transport": "3",
+    "Local share of car trips": "3",
+    "Local share of bicycles": "3",
+    "City-wide public transport use": "3",
+    "City-wide average speed of public transport": "3",
+    "City-wide share of public transport": "3",
+    "City-wide share of car trips": "3",
+    "City-wide share of bicycles": "3"
   }
 }
\ No newline at end of file
-- 
GitLab