Skip to content

Commit

Permalink
Merge pull request #2654 from ziv17/2653-multiple-junctions
Browse files Browse the repository at this point in the history
Support multiple suburban junctions in same km.
  • Loading branch information
atalyaalon authored May 24, 2024
2 parents 9e7c615 + a0f9a2d commit 10d34da
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from flask_sqlalchemy import BaseQuery
from sqlalchemy import func, asc
# noinspection PyProtectedMember
from flask_babel import _

from anyway.app_and_db import db
Expand Down Expand Up @@ -34,8 +35,8 @@ def filter_and_group_injured_count_per_age_group(
) -> Dict[str, Dict[int, int]]:
start_time = request_params.start_time
end_time = request_params.end_time
cache_key = None #prevent pylint warning
cache_key = None # prevent pylint warning

if request_params.resolution == BE_CONST.ResolutionCategories.STREET:
involve_yishuv_name = request_params.location_info["yishuv_name"]
street1_hebrew = request_params.location_info["street1_hebrew"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def is_included(self) -> bool:
segment_others = item["count"]
else:
raise ValueError
segment_total = segment_h2h + segment_others
segment_total = segment_h2h + segment_others # pylint: disable=E0606
all_items = self.items[self.ALL_ROADS_SUBTITLE]
for item in all_items:
if item["desc"] == "frontal":
Expand All @@ -116,7 +116,7 @@ def is_included(self) -> bool:
all_others = item["count"]
else:
raise ValueError
all_total = all_h2h + all_others
all_total = all_h2h + all_others # pylint: disable=E0606
return segment_h2h > 0 and (segment_h2h / segment_total) > all_h2h / all_total


Expand Down
18 changes: 12 additions & 6 deletions anyway/widgets/segment_junctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ def __calc_fill_segment_junctions():
if t.road not in rkj:
rkj[t.road] = {}
road_last_junction_km[t.road] = -1
rkj[t.road][t.km] = t.non_urban_intersection
if t.km not in rkj[t.road]:
rkj[t.road][t.km] = []
else:
logging.debug(
f"Two junctions in same location:road:{t.road},km:{t.km},1:"
f"{rkj[t.road][t.km]},2:{t.non_urban_intersection}."
)
rkj[t.road][t.km].append(t.non_urban_intersection)
if road_last_junction_km[t.road] < t.km:
road_last_junction_km[t.road] = t.km
tmp: List[RoadSegments] = db.session.query(RoadSegments).all()
Expand All @@ -45,11 +52,10 @@ def __calc_fill_segment_junctions():
if seg.road not in rkj:
logging.warning(f"No junctions in road {seg.road}.")
continue
junctions = [
rkj[seg.road][km]
for km in rkj[seg.road].keys()
if is_junction_km_in_segment(km, seg, road_last_junction_km.get(seg.road))
]
junctions = []
for km in rkj[seg.road].keys():
if is_junction_km_in_segment(km, seg, road_last_junction_km.get(seg.road)):
junctions.extend(rkj[seg.road][km])
res[seg_id] = junctions
return res

Expand Down
8 changes: 7 additions & 1 deletion tests/test_infographics_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ class TestInfographicsUtilsCase(unittest.TestCase):
rjks = [
RoadJunctionKM(road=1, non_urban_intersection=1, km=1.0),
RoadJunctionKM(road=1, non_urban_intersection=2, km=2.0),
RoadJunctionKM(road=1, non_urban_intersection=22, km=2.0),
RoadJunctionKM(road=1, non_urban_intersection=3, km=3.0),
RoadJunctionKM(road=10, non_urban_intersection=1, km=10.0),
RoadJunctionKM(road=20, non_urban_intersection=2, km=10.0),
RoadJunctionKM(road=20, non_urban_intersection=22, km=10.0),
RoadJunctionKM(road=30, non_urban_intersection=3, km=10.0),
]
segments = [
Expand Down Expand Up @@ -90,7 +92,11 @@ def test_get_segment_junctions(self, db):
actual = sg.get_segment_junctions(2)
self.assertEqual([1], actual, "2")
actual = sg.get_segment_junctions(3)
self.assertEqual([1, 2, 3], actual, "3")
self.assertEqual([1, 2, 22, 3], actual, "3")
actual = sg.get_segment_junctions(4)
self.assertEqual([3], actual, "4")
actual = sg.get_segment_junctions(21)
self.assertEqual([2, 22], actual, "5")

def test_get_filter_expression(self):
actual = get_filter_expression(AccidentMarkerView, "road_segment_name", "seg1")
Expand Down

0 comments on commit 10d34da

Please sign in to comment.