Skip to content
Snippets Groups Projects
Commit 2b73094c authored by Gjorgji's avatar Gjorgji
Browse files

Fixing RE, bikeability index,changed something in read network, and new bilbao model

parent 50730256
Branches
No related tags found
No related merge requests found
......@@ -44,8 +44,8 @@ def dexi_eval_json(city_id=None):
if city_id is None:
return {"message": "Error on frontend - city_id not specified"}
baseline_id = request.get_json()["baseline"]
compare_id = 1 # hehe what a nasty hack
baseline_id = 1
compare_id = request.get_json()["compare"] # changed because we always have baseline as 1 on the UI, dropdowns to be removed
compare_simulation_name = get_compare_simulation_name(compare_id)
baseline_json, compare_json, _ = preprocess_kpi_jsons(baseline_id, compare_id)
......@@ -55,7 +55,7 @@ def dexi_eval_json(city_id=None):
dexi_output = postprocess_dexi_result(dexi_output, baseline_json)
app.logger.debug("postprocessed \n%s", json.dumps(dexi_output, indent=2))
write_results(dexi_output, baseline_id, simulation_dirs[0])
write_results(dexi_output, compare_id, simulation_dirs[1])
return {"success": True}
......@@ -82,10 +82,22 @@ def recommendation_analysis(city_id=None):
dexi_output, simulation_dirs = prepare_and_run_dexi(plus_one_json, city_id, compare_simulation_name,
baseline_id, compare_id, folder_name)
write_results(dexi_output, baseline_id, simulation_dirs[0])
write_results(dexi_output, compare_id, simulation_dirs[1])
# Remark: first we need to run the normal dexi pipeline, so we can create the temp folder. Then later we need to call the recommendation analysis function
compare_dexi_results(f'{data_dir}/temp/', f'{data_dir}/{folder_name}/', changed_element, folder_name, step_size)
# running dexi here normally
# Doing this because if we run recommendation engine after running runDSS on the front end, it will change the evaluated.json files
# and next time we open the UI we would have incorrect spider chart
compare_simulation_name = get_compare_simulation_name(compare_id)
baseline_json, compare_json, _ = preprocess_kpi_jsons(1, compare_id)
dexi_output, simulation_dirs = prepare_and_run_dexi(compare_json, city_id, compare_simulation_name,
1, compare_id, "temp")
dexi_output = postprocess_dexi_result(dexi_output, baseline_json)
write_results(dexi_output, compare_id, simulation_dirs[1])
return {"success": True}
@app.route("/dss/general_recommendation", methods=["GET"])
......
......@@ -26,11 +26,12 @@ logger = logging.getLogger(__name__)
# DEBUG
@app.route("/dss/test/<int:simulation_id>", methods=["GET"])
def test_kpi_congestions(simulation_id):
app.logger.info("test called")
# rush_hour = utils.get_max_traffic_time(simulation_id)
network, events = utils.get_network_and_events(simulation_id)
ll = network.nearby_links_range("1691828242", 500)
app.logger.debug(ll)
result = events.share_bicycles(local_links=ll)
# ll = network.nearby_links_range("1691828242", 500)
result = events.bikeability_index()
# app.logger.info("result:\n%s", result)
return {"res": result}
@app.route("/dss/kpis/<city_id>/<int:simulation_id>", methods=["GET"])
......
......@@ -151,6 +151,7 @@ class VehicleEvents(Events):
Events.__init__(self, path, network)
self.trips_number = self.trips_amount()
# TODO this doesn't work for Amsterdam - is always 10 or 0
def bike_safety_index(self, local_links=None, timeslot=None) -> Dict:
"""
Calculates the bike safety KPI, based on
......@@ -191,6 +192,7 @@ class VehicleEvents(Events):
)
return links
# TODO fix after fixing bike_safety_index above
def bike_safety_aggregate(self, safety_score: List[Dict]):
safety_avg = 0
n_scores = 0
......@@ -213,8 +215,12 @@ class VehicleEvents(Events):
if local_links is not None:
filter_expr = lambda link: link["id"] in local_links
score = {}
n_links_with_osm_way = 0
for link in filter(filter_expr, self.network.links):
if "osm:way:highway" in link:
n_links_with_osm_way += 1
# logger.info("link iwth osm:way:h %s", link["osm:way:highway"])
if link["osm:way:highway"] == "steps":
score[link["id"]] = {"infra": 0, "speed": 0}
elif link["osm:way:highway"] == "motorway":
......@@ -248,14 +254,14 @@ class VehicleEvents(Events):
elif link["osm:way:highway"] == "cycleway":
score[link["id"]] = {"infra": 10, "speed": 0}
# speed limit 30 km/h - 8.33 m/s - 10 points
if float(link["freespeed"]) < 8.4:
# speed limit 30 km/h - 8.7 m/s - 10 points
if float(link["freespeed"]) < 9:
if not score.get(link["id"], False):
score[link["id"]] = {"infra": 0, "speed": 10}
else:
score[link["id"]]["speed"] = 10
# speed limit 50 km/h - 13.88 m/s - 7 points
elif float(link["freespeed"]) < 13.9:
elif float(link["freespeed"]) < 14:
if not score.get(link["id"], False):
score[link["id"]] = {"infra": 0, "speed": 7}
else:
......@@ -266,7 +272,7 @@ class VehicleEvents(Events):
score[link["id"]] = {"infra": 0, "speed": 0}
else:
score[link["id"]]["speed"] = 0
# logger.info("bikeability index found %s links with osm:way: property", n_links_with_osm_way)
return score
@staticmethod
......@@ -280,7 +286,8 @@ class VehicleEvents(Events):
infra_avg /= len(scores)
speed_avg /= len(scores)
except ZeroDivisionError:
pass
logger.warn("No infra or speed scores - missing data in network?")
return (len(scores) / (len(scores) + len(scores))) * infra_avg + (
len(scores) / (len(scores) + len(scores))
) * speed_avg
......
......@@ -26,13 +26,11 @@ class Network:
:param path: path to the network.xml file
:param type: string
:param crs_epsg: the coordinate reference system used.
Network files used by MATSim use CRS epsg 2062.
:param type: string
"""
self.city = city
# used for importing counting locations, which use a different CRS
if city == "bilbao":
self.crs_epsg = "32630"
elif city == "amsterdam":
......@@ -84,7 +82,16 @@ class Network:
elif child.tag == "links":
for link in child:
links.append(link.attrib)
link_attributes = link.attrib
# logger.debug("link %s", link.attrib)
for x in link:
# logger.debug("attributes %s", x.attrib)
for y in x:
# logger.debug("attribute %s", y.attrib)
if y.attrib["name"] == "osm:way:highway":
# logger.debug("text %s", y.text)
link_attributes["osm:way:highway"] = y.text
links.append(link_attributes)
self.nodes = nodes
self.links = links
......
<?xml version="1.0" encoding="UTF-8"?>
<DEXi>
<VERSION>5.05</VERSION>
<CREATED>2023-03-30T15:23:15</CREATED>
<CREATED>2023-04-03T09:52:25</CREATED>
<OPTION>a</OPTION>
<OPTION>b</OPTION>
<SETTINGS/>
......@@ -46,8 +46,8 @@
<FUNCTION>
<LOW>001012122</LOW>
</FUNCTION>
<OPTION>0</OPTION>
<OPTION>0</OPTION>
<OPTION>1</OPTION>
<OPTION>1</OPTION>
<ATTRIBUTE>
<NAME>Local Pollution</NAME>
<SCALE>
......@@ -72,7 +72,7 @@
<NORMLOCWEIGHTS>50.00;50.00</NORMLOCWEIGHTS>
</FUNCTION>
<OPTION>1</OPTION>
<OPTION>0</OPTION>
<OPTION>1</OPTION>
<ATTRIBUTE>
<NAME>Local Emissions</NAME>
<SCALE>
......@@ -212,8 +212,8 @@
<GROUP>GOOD</GROUP>
</SCALEVALUE>
</SCALE>
<OPTION>3</OPTION>
<OPTION>4</OPTION>
<OPTION>2</OPTION>
<OPTION>2</OPTION>
</ATTRIBUTE>
</ATTRIBUTE>
<ATTRIBUTE>
......@@ -239,7 +239,7 @@
<LOCWEIGHTS>50.00;50.00</LOCWEIGHTS>
<NORMLOCWEIGHTS>50.00;50.00</NORMLOCWEIGHTS>
</FUNCTION>
<OPTION>0</OPTION>
<OPTION>1</OPTION>
<OPTION>1</OPTION>
<ATTRIBUTE>
<NAME>Local Pedestrian travel time</NAME>
......@@ -265,8 +265,8 @@
<GROUP>GOOD</GROUP>
</SCALEVALUE>
</SCALE>
<OPTION>3</OPTION>
<OPTION>3</OPTION>
<OPTION>2</OPTION>
<OPTION>2</OPTION>
</ATTRIBUTE>
<ATTRIBUTE>
<NAME>Local Daily internal bike travels</NAME>
......@@ -292,8 +292,8 @@
<GROUP>GOOD</GROUP>
</SCALEVALUE>
</SCALE>
<OPTION>3</OPTION>
<OPTION>1</OPTION>
<OPTION>2</OPTION>
<OPTION>2</OPTION>
</ATTRIBUTE>
</ATTRIBUTE>
</ATTRIBUTE>
......@@ -317,7 +317,7 @@
<LOW>001012122</LOW>
</FUNCTION>
<OPTION>1</OPTION>
<OPTION>2</OPTION>
<OPTION>1</OPTION>
<ATTRIBUTE>
<NAME>City-wide Pollution</NAME>
<SCALE>
......@@ -341,8 +341,8 @@
<LOCWEIGHTS>50.00;50.00</LOCWEIGHTS>
<NORMLOCWEIGHTS>50.00;50.00</NORMLOCWEIGHTS>
</FUNCTION>
<OPTION>0</OPTION>
<OPTION>2</OPTION>
<OPTION>1</OPTION>
<OPTION>1</OPTION>
<ATTRIBUTE>
<NAME>City-wide Acoustic pollution</NAME>
<SCALE>
......@@ -367,8 +367,8 @@
<GROUP>GOOD</GROUP>
</SCALEVALUE>
</SCALE>
<OPTION>4</OPTION>
<OPTION>0</OPTION>
<OPTION>2</OPTION>
<OPTION>2</OPTION>
</ATTRIBUTE>
<ATTRIBUTE>
<NAME>City-wide Emissions</NAME>
......@@ -402,7 +402,7 @@
<NORMLOCWEIGHTS>33.33;33.33;33.33</NORMLOCWEIGHTS>
</FUNCTION>
<OPTION>2</OPTION>
<OPTION>1</OPTION>
<OPTION>2</OPTION>
<ATTRIBUTE>
<NAME>City-wide NOx</NAME>
<SCALE>
......@@ -428,7 +428,7 @@
</SCALEVALUE>
</SCALE>
<OPTION>2</OPTION>
<OPTION>0</OPTION>
<OPTION>2</OPTION>
</ATTRIBUTE>
<ATTRIBUTE>
<NAME>City-wide PM10</NAME>
......@@ -454,7 +454,7 @@
<GROUP>GOOD</GROUP>
</SCALEVALUE>
</SCALE>
<OPTION>3</OPTION>
<OPTION>2</OPTION>
<OPTION>2</OPTION>
</ATTRIBUTE>
<ATTRIBUTE>
......@@ -481,8 +481,8 @@
<GROUP>GOOD</GROUP>
</SCALEVALUE>
</SCALE>
<OPTION>1</OPTION>
<OPTION>0</OPTION>
<OPTION>2</OPTION>
<OPTION>2</OPTION>
</ATTRIBUTE>
</ATTRIBUTE>
</ATTRIBUTE>
......@@ -509,7 +509,7 @@
<LOCWEIGHTS>50.00;50.00</LOCWEIGHTS>
<NORMLOCWEIGHTS>50.00;50.00</NORMLOCWEIGHTS>
</FUNCTION>
<OPTION>2</OPTION>
<OPTION>1</OPTION>
<OPTION>1</OPTION>
<ATTRIBUTE>
<NAME>City-wide Pedestrian travel time</NAME>
......@@ -535,8 +535,8 @@
<GROUP>GOOD</GROUP>
</SCALEVALUE>
</SCALE>
<OPTION>1</OPTION>
<OPTION>3</OPTION>
<OPTION>2</OPTION>
<OPTION>2</OPTION>
</ATTRIBUTE>
<ATTRIBUTE>
<NAME>City-wide Daily internal bike travels</NAME>
......@@ -562,8 +562,8 @@
<GROUP>GOOD</GROUP>
</SCALEVALUE>
</SCALE>
<OPTION>1</OPTION>
<OPTION>1</OPTION>
<OPTION>2</OPTION>
<OPTION>2</OPTION>
</ATTRIBUTE>
</ATTRIBUTE>
</ATTRIBUTE>
......@@ -591,8 +591,8 @@
<GROUP>GOOD</GROUP>
</SCALEVALUE>
</SCALE>
<OPTION>1</OPTION>
<OPTION>3</OPTION>
<OPTION>2</OPTION>
<OPTION>2</OPTION>
</ATTRIBUTE>
</ATTRIBUTE>
</DEXi>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment