Skip to content

Commit

Permalink
chore: autoformat isort & black
Browse files Browse the repository at this point in the history
  • Loading branch information
sahand-asgarpour authored and github-actions[bot] committed Sep 10, 2024
1 parent 2882876 commit 54bde54
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 31 deletions.
20 changes: 10 additions & 10 deletions ra2ce/analysis/losses/losses_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ def _get_disrupted_criticality_analysis_results(
]
# link_id from list to tuple
if len(self.criticality_analysis_non_disrupted) > 0:
self.criticality_analysis_non_disrupted[self.link_id] = (
self.criticality_analysis_non_disrupted[self.link_id].apply(
lambda x: tuple(x) if isinstance(x, list) else x
)
self.criticality_analysis_non_disrupted[
self.link_id
] = self.criticality_analysis_non_disrupted[self.link_id].apply(
lambda x: tuple(x) if isinstance(x, list) else x
)
self.criticality_analysis[self.link_id] = self.criticality_analysis[
self.link_id
Expand Down Expand Up @@ -451,9 +451,9 @@ def _calculate_production_loss_per_capita(
[vlh_row.name], f"vlh_{trip_type}_{hazard_col_name}"
] = vlh_trip_type_event
vlh_total += vlh_trip_type_event
vehicle_loss_hours.loc[[vlh_row.name], f"vlh_{hazard_col_name}_total"] = (
vlh_total
)
vehicle_loss_hours.loc[
[vlh_row.name], f"vlh_{hazard_col_name}_total"
] = vlh_total

def _populate_vehicle_loss_hour(
self,
Expand Down Expand Up @@ -503,9 +503,9 @@ def _populate_vehicle_loss_hour(
[vlh_row.name], f"vlh_{trip_type}_{hazard_col_name}"
] = vlh_trip_type_event
vlh_total += vlh_trip_type_event
vehicle_loss_hours.loc[[vlh_row.name], f"vlh_{hazard_col_name}_total"] = (
vlh_total
)
vehicle_loss_hours.loc[
[vlh_row.name], f"vlh_{hazard_col_name}_total"
] = vlh_total

@abstractmethod
def _get_criticality_analysis(self) -> AnalysisLossesProtocol:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import re
from abc import ABC, abstractmethod

import geopandas as gpd
import numpy as np
import re


class RiskCalculationBase(ABC):
Expand Down Expand Up @@ -80,5 +80,3 @@ def get_integration_of_df_trapezoidal(self) -> np.array:
_risk_calculations = self._get_network_risk_calculations()
frequencies = sorted(1 / rp for rp in _risk_calculations.columns)
return np.trapz(_risk_calculations.values, frequencies, axis=1)


Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import geopandas as gpd

import geopandas as gpd
import numpy as np

from ra2ce.analysis.losses.risk_calculation.risk_calculation_base import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging

import geopandas as gpd

from ra2ce.analysis.losses.risk_calculation.risk_calculation_base import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import geopandas as gpd

from ra2ce.analysis.analysis_config_data.enums.risk_calculation_mode_enum import (
RiskCalculationModeEnum,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging

import geopandas as gpd

from ra2ce.analysis.losses.risk_calculation.risk_calculation_base import (
Expand Down
4 changes: 3 additions & 1 deletion ra2ce/network/network_wrappers/vector_network_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ def get_network(
graph_simple = nut.add_missing_geoms_graph(graph_simple, geom_name="geometry")

# Update rfid_c after segmentation, which created more edges n teh complex graph
graph_simple = nut.add_complex_id_to_graph_simple(graph_simple, link_tables[0], "rfid")
graph_simple = nut.add_complex_id_to_graph_simple(
graph_simple, link_tables[0], "rfid"
)

logging.info("Finished converting the complex graph to a simple graph")

Expand Down
21 changes: 7 additions & 14 deletions ra2ce/network/networks_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
"""
import itertools
import logging
from copy import deepcopy
import os
import sys
import warnings
from copy import deepcopy
from pathlib import Path
from statistics import mean
from typing import Optional
Expand Down Expand Up @@ -1481,19 +1481,15 @@ def add_simple_id_to_graph_complex(
"""

# {(u,v,k) : 'rfid_c'}
obtained_complex_ids = nx.get_edge_attributes(
complex_graph, "{}_c".format(new_id)
)
obtained_complex_ids = nx.get_edge_attributes(complex_graph, "{}_c".format(new_id))
# start with a copy
simple_ids_per_complex_id = deepcopy(obtained_complex_ids)

# {(u,v,k) : 'rfid_c'}
for key, value in obtained_complex_ids.items():
try:
# find simple id belonging to the complex id
new_value = complex_to_simple[
value
]
new_value = complex_to_simple[value]
simple_ids_per_complex_id[key] = new_value
except KeyError as e:
logging.error(
Expand Down Expand Up @@ -1585,6 +1581,7 @@ def buffer_geometry(
)
return gdf


def add_complex_id_to_graph_simple(
simple_graph: nx.classes.Graph, simple_to_complex, simple_id: str
) -> nx.classes.Graph:
Expand All @@ -1601,19 +1598,15 @@ def add_complex_id_to_graph_simple(
"""

# {(u,v,k) : 'rfid'}
obtained_simple_ids = nx.get_edge_attributes(
simple_graph, f"{simple_id}"
)
obtained_simple_ids = nx.get_edge_attributes(simple_graph, f"{simple_id}")
# start with a copy
complex_ids_per_simple_id = deepcopy(obtained_simple_ids)

# {(u,v,k) : 'rfid'}
for key, value in obtained_simple_ids.items():
for key, value in obtained_simple_ids.items():
try:
# find simple id belonging to the complex id
new_value = simple_to_complex[
value
]
new_value = simple_to_complex[value]
complex_ids_per_simple_id[key] = new_value
except KeyError as e:
logging.error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ def test_get_functionality_loss_ratio(
"link_type, hazard_range, expected",
[
pytest.param(RoadTypeEnum.MOTORWAY, (0.2, 0.5), 5.0, id="Motorway 0.2-0.5"),
pytest.param(RoadTypeEnum.MOTORWAY, (0.5, 1.2), 10.0, id="Motorway 0.5-1.2"),
pytest.param(
RoadTypeEnum.MOTORWAY, (0.5, 1.2), 10.0, id="Motorway 0.5-1.2"
),
],
)
def test_calculate_disruption(
Expand Down
2 changes: 1 addition & 1 deletion tests/analysis/losses/risk_calculation/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def get_expected_factory_results_fixture() -> Iterator[dict]:
name="risk_calculation_info_fixture",
)
def _get_risk_calculation_info_fixture(
request: pytest.FixtureRequest,
request: pytest.FixtureRequest,
) -> Iterator[tuple[RiskCalculationModeEnum, int]]:
_risk_calculation_info = request.param
assert isinstance(_risk_calculation_info[0], RiskCalculationModeEnum)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pandas as pd

from ra2ce.analysis.analysis_config_data.enums.risk_calculation_mode_enum import (
RiskCalculationModeEnum,
)
Expand Down
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from pathlib import Path
from typing import Iterator

import pytest

from tests import acceptance_test_data


Expand Down

0 comments on commit 54bde54

Please sign in to comment.