Skip to content

Commit

Permalink
Merge pull request #477 from OpenTrafficCam/bug/4553-show-events-of-c…
Browse files Browse the repository at this point in the history
…urrent-filter-ignores-time-filter

bug/4553-show-events-of-current-filter-ignores-time-filter
  • Loading branch information
randy-seng authored Mar 7, 2024
2 parents b918a1c + fb848d2 commit eb1956b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
20 changes: 20 additions & 0 deletions OTAnalytics/domain/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,26 @@ def to_dict(self) -> dict:
VIDEO_NAME: self.video_name,
}

def to_typed_dict(self) -> dict:
"""Convert event into dict to interact with other parts of the system,
e.g. serialization.
Returns:
dict: serialized event
"""
return {
ROAD_USER_ID: self.road_user_id,
ROAD_USER_TYPE: self.road_user_type,
HOSTNAME: self.hostname,
OCCURRENCE: self.occurrence,
FRAME_NUMBER: self.frame_number,
SECTION_ID: self._serialized_section_id(),
EVENT_COORDINATE: self.event_coordinate.to_list(),
EVENT_TYPE: self.event_type.value,
DIRECTION_VECTOR: self.direction_vector.to_list(),
VIDEO_NAME: self.video_name,
}

def _serialized_section_id(self) -> Optional[str]:
return self.section_id.serialize() if self.section_id else None

Expand Down
2 changes: 1 addition & 1 deletion OTAnalytics/plugin_prototypes/event_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def _convert_tracks(self, events: Iterable[Event]) -> DataFrame:
Returns:
DataFrame: events as dataframe.
"""
prepared: list[dict] = [current.to_dict() for current in events]
prepared: list[dict] = [current.to_typed_dict() for current in events]

if not prepared:
return DataFrame()
Expand Down
12 changes: 11 additions & 1 deletion OTAnalytics/plugin_ui/visualization/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ def __init__(
self._data_provider_all_filters_with_offset: Optional[
PandasDataFrameProvider
] = None
self._pandas_event_data_provider_all_filters: Optional[
PandasDataFrameProvider
] = None
self._data_provider_class_filter: Optional[PandasDataFrameProvider] = None
self._event_data_provider_class_filter: Optional[PandasDataFrameProvider] = None
self._data_provider_class_filter_with_offset: Optional[
Expand Down Expand Up @@ -396,6 +399,13 @@ def _get_event_data_provider_class_filter(self) -> PandasDataFrameProvider:
)
return self._event_data_provider_class_filter

def _get_event_data_provider_all_filters(self) -> PandasDataFrameProvider:
if not self._pandas_event_data_provider_all_filters:
self._pandas_event_data_provider_all_filters = self._create_all_filters(
self._get_pandas_event_data_provider()
)
return self._pandas_event_data_provider_all_filters

def _get_data_provider_class_filter(self) -> PandasDataFrameProvider:
if not self._data_provider_class_filter:
self._data_provider_class_filter = self._build_filter_by_classification(
Expand Down Expand Up @@ -799,7 +809,7 @@ def _create_event_point_plotter_frame(self) -> Plotter:
def _create_event_point_plotter_filter(self) -> Plotter:
track_plotter = MatplotlibTrackPlotter(
TrackPointPlotter(
self._get_event_data_provider_class_filter(),
self._get_event_data_provider_all_filters(),
self._color_palette_provider,
alpha=ALPHA_BOUNDING_BOX,
marker=MARKER_EVENT_FILTER,
Expand Down

0 comments on commit eb1956b

Please sign in to comment.