Skip to content

Commit

Permalink
Fixed the crash and rounded of the interpolation value for the number… (
Browse files Browse the repository at this point in the history
#555)

* Fixed the crash and rounded of the interpolation value for the number of lanes

* chore: cleaned the code and resolved nan to integer

* chore: ceil replaced round

---------

Co-authored-by: sahand_asgarpour <[email protected]>
  • Loading branch information
LiekeMeijer and sahand-asgarpour authored Aug 13, 2024
1 parent 1d7f927 commit 1e92f77
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions ra2ce/analysis/damages/damages_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""


import logging
from typing import Any, List

Expand Down Expand Up @@ -130,10 +129,11 @@ def create_summary_statistics(gdf: GeoDataFrame) -> dict:

# get a default value if any key of the dictionary is nan
# (because the mode operation on the 'lanes' column for a road type results in an empty array)
default_value = np.mean(
lanes_values = np.mean(
list(_val for _val in _lanes_dict.values() if not np.isnan(_val))
)

# Round the mean to the nearest integer
default_value = np.ceil(lanes_values)
# Replace nan with the calculated average
return {
_road_type: _lanes if not np.isnan(_lanes) else default_value
Expand Down
4 changes: 2 additions & 2 deletions tests/analysis/damages/test_damages_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def test_clean_lane_data(self):
[
pytest.param([0, 1, 3], [0, 1, 3], id="Valid lanes"),
pytest.param([np.nan, 1, 3], [2, 1, 3], id="First lane invalid"),
pytest.param([0, np.nan, 3], [0, 1.5, 3], id="Middle lane invalid"),
pytest.param([0, 1, np.nan], [0, 1, 0.5], id="Last lane invalid"),
pytest.param([0, np.nan, 3], [0, 2, 3], id="Middle lane invalid"),
pytest.param([0, 1, np.nan], [0, 1, 1], id="Last lane invalid"),
pytest.param(
[np.nan, np.nan, np.nan],
[np.nan, np.nan, np.nan],
Expand Down

0 comments on commit 1e92f77

Please sign in to comment.