Skip to content

Commit

Permalink
Merge pull request #337 from OpenTrafficCam/feature/3026-print-number…
Browse files Browse the repository at this point in the history
…-of-tracks-intersecting-section-or-assigned-to-flow-to-stdout

Print number of tracks intersecting section or assigned to flow to stdout
  • Loading branch information
briemla authored Sep 21, 2023
2 parents c791c9c + 6dc904c commit 517631f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def get_ids(self) -> Iterable[TrackId]:
for assignment in assignments:
if assignment.assignment.id in self._flow_state.selected_flows.get():
ids.add(TrackId(assignment.road_user))
print(f"Tracks assigned to selected flow(s): {len(ids)}")
return ids


Expand Down
19 changes: 13 additions & 6 deletions OTAnalytics/plugin_intersect/simple_intersect.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,19 @@ def __call__(self, sections: Iterable[Section]) -> set[TrackId]:
def _intersect(
self, tracks: Iterable[Track], sections: Iterable[Section]
) -> set[TrackId]:
return {
track.id
for section in sections
for track in tracks
if self._track_intersects_section(track, section)
}
print("Number of intersecting tracks per section")
all_track_ids: set[TrackId] = set()
for section in sections:
track_ids = {
track.id
for track in tracks
if self._track_intersects_section(track, section)
}
print(f"{section.name}: {len(track_ids)} tracks")
all_track_ids.update(track_ids)

print(f"All sections: {len(all_track_ids)} tracks")
return all_track_ids

def _track_intersects_section(self, track: Track, section: Section) -> bool:
section_offset = section.get_offset(EventType.SECTION_ENTER)
Expand Down
1 change: 1 addition & 0 deletions tests/OTAnalytics/plugin_intersect/test_intersect.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,7 @@ def test_tracks_intersecting_sections(self, track: Track) -> None:
section = Mock(spec=Section)
offset = RelativeOffsetCoordinate(0, 0)
section.get_offset.return_value = offset
section.name = "south"

intersect_implementation = Mock(spec=IntersectImplementation)
intersect_implementation.line_intersects_line.return_value = True
Expand Down

0 comments on commit 517631f

Please sign in to comment.