Skip to content

Commit

Permalink
WIP for rebase on dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ziv17 committed Dec 9, 2023
1 parent abb0887 commit aaf2a78
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
4 changes: 2 additions & 2 deletions alembic/versions/7ea883c8a245_add_road_junction_km_table.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""add suburban junction table
Revision ID: 7ea883c8a245
Revises: 664f8a93794e
Revises: 881e7b1dba8a
Create Date: 2023-06-04 17:43:13.170728
"""

# revision identifiers, used by Alembic.
revision = '7ea883c8a245'
down_revision = '664f8a93794e'
down_revision = '881e7b1dba8a'
branch_labels = None
depends_on = None

Expand Down
2 changes: 1 addition & 1 deletion anyway/widgets/segment_junctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __calc_fill_segment_junctions():
continue
# logger.debug(f"seg:{k},road:{v.road}:juncs:{rkj[v.road]}.")
junctions = [
rkj[v.road][km] for km in rkj[v.road].keys() if v.from_km - 1 <= km <= v.to_km + 1
rkj[v.road][km] for km in rkj[v.road].keys() if v.from_km <= km <= v.to_km
]
# logger.debug(f"segment junctions:{junctions}")
res[k] = junctions
Expand Down
36 changes: 34 additions & 2 deletions tests/test_infographics_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
from anyway.widgets.widget_utils import (format_2_level_items, get_query, get_filter_expression,
get_expression_for_segment_junctions)
from anyway.backend_constants import AccidentSeverity
from anyway.models import AccidentMarkerView
from anyway.models import AccidentMarkerView, RoadJunctionKM, RoadSegments
from anyway.widgets.segment_junctions import SegmentJunctions
from widgets import segment_junctions


class TestInfographicsUtilsCase(unittest.TestCase):
item1 = {
Expand Down Expand Up @@ -37,6 +40,28 @@ class TestInfographicsUtilsCase(unittest.TestCase):
}
]

t = RoadJunctionKM()
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=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=30, non_urban_intersection=3, km=10.0),
]
segments = [
RoadSegments(segment_id=1, road=1, from_km=0.0, to_km=1.0),
# RoadSegments(segment_id=2, road=1, from_km=1.0, to_km=2.0),
RoadSegments(segment_id=3, road=1, from_km=1.0, to_km=3.0),
RoadSegments(segment_id=4, road=1, from_km=3.0, to_km=4.0),
RoadSegments(segment_id=11, road=10, from_km=0.0, to_km=10.0),
RoadSegments(segment_id=12, road=10, from_km=10.0, to_km=20.0),
RoadSegments(segment_id=21, road=20, from_km=0.0, to_km=10.0),
RoadSegments(segment_id=22, road=20, from_km=10.0, to_km=20.0),
RoadSegments(segment_id=31, road=30, from_km=0.0, to_km=10.0),
RoadSegments(segment_id=32, road=30, from_km=10.0, to_km=20.0),
]

def test_format_two_level_items(self):
actual = format_2_level_items(
self.item1,
Expand All @@ -45,8 +70,15 @@ def test_format_two_level_items(self):
)
self.assertEqual(self.items1_res, actual, "leve 2 formatting")

@patch("anyway.widgets.segment_junctions.db")
def test_get_segment_junctions(self, db):
db.session.query.all.side_effect = [self.rjks, self.segments]
db.session.query.return_value = db.session.query
sg = SegmentJunctions()
actual = sg.get_segment_junctions(1)
self.assertEqual([1], actual, "1")

def test_segment_junctions(self):
from anyway.widgets.segment_junctions import SegmentJunctions
i = SegmentJunctions.get_instance()
segment_junctions = i.get_segment_junctions(1)
self.assertTrue(isinstance(segment_junctions, list))
Expand Down

0 comments on commit aaf2a78

Please sign in to comment.