2626VIDEO_NAME = "video_name"
2727INTERPOLATED_OCCURRENCE = "interpolated_occurrence"
2828INTERPOLATED_EVENT_COORDINATE = "interpolated_event_coordinate"
29+ GEO_X : str = "geo_x"
30+ GEO_Y : str = "geo_y"
2931
3032DATE_FORMAT : str = "%Y-%m-%d %H:%M:%S.%f"
3133FILE_NAME_PATTERN = r"(?P<hostname>[A-Za-z0-9]+)_.*\..*"
@@ -80,6 +82,8 @@ class Event(DataclassValidation):
8082 event occurred.
8183 interpolated_event_coordinate (ImageCoordinate): interpolated event
8284 coordinate between two detections.
85+ geo_x (float | None): optional geo x coordinate. Defaults to None.
86+ geo_y (float | None): optional geo y coordinate. Defaults to None.
8387 """
8488
8589 road_user_id : str
@@ -94,6 +98,8 @@ class Event(DataclassValidation):
9498 video_name : str
9599 interpolated_occurrence : datetime
96100 interpolated_event_coordinate : ImageCoordinate
101+ geo_x : float | None = None
102+ geo_y : float | None = None
97103
98104 def _validate (self ) -> None :
99105 self ._validate_frame_number_greater_equal_one ()
@@ -129,6 +135,8 @@ def to_dict(self) -> dict:
129135 VIDEO_NAME : self .video_name ,
130136 INTERPOLATED_OCCURRENCE : self .interpolated_occurrence .strftime (DATE_FORMAT ),
131137 INTERPOLATED_EVENT_COORDINATE : self .interpolated_event_coordinate .to_list (),
138+ GEO_X : self .geo_x ,
139+ GEO_Y : self .geo_y ,
132140 }
133141
134142 def to_typed_dict (self ) -> dict :
@@ -151,6 +159,8 @@ def to_typed_dict(self) -> dict:
151159 VIDEO_NAME : self .video_name ,
152160 INTERPOLATED_OCCURRENCE : self .interpolated_occurrence ,
153161 INTERPOLATED_EVENT_COORDINATE : self .interpolated_event_coordinate .to_list (),
162+ GEO_X : self .geo_x ,
163+ GEO_Y : self .geo_y ,
154164 }
155165
156166 def _serialized_section_id (self ) -> Optional [str ]:
@@ -172,6 +182,8 @@ def __init__(self) -> None:
172182 self .section_id : Optional [SectionId ] = None
173183 self .interpolated_occurrence : Optional [datetime ] = None
174184 self .interpolated_event_coordinate : Optional [ImageCoordinate ] = None
185+ self .geo_x : float | None = None
186+ self .geo_y : float | None = None
175187
176188 @abstractmethod
177189 def create_event (self , detection : Detection ) -> Event :
@@ -255,6 +267,16 @@ def add_interpolated_occurrence(self, occurrence: datetime) -> None:
255267 def add_interpolated_event_coordinate (self , x : float , y : float ) -> None :
256268 self .interpolated_event_coordinate = ImageCoordinate (x , y )
257269
270+ def add_geo_coordinate (self , geo_x : float | None , geo_y : float | None ) -> None :
271+ """Add geo coordinates to the event to be built.
272+
273+ Args:
274+ geo_x: the geo x coordinate, or None if unavailable.
275+ geo_y: the geo y coordinate, or None if unavailable.
276+ """
277+ self .geo_x = geo_x
278+ self .geo_y = geo_y
279+
258280
259281class SectionEventBuilder (EventBuilder ):
260282 """A builder to build section events."""
@@ -320,6 +342,8 @@ def create_event(self, detection: Detection) -> Event:
320342 video_name = detection .video_name ,
321343 interpolated_occurrence = self .interpolated_occurrence ,
322344 interpolated_event_coordinate = self .interpolated_event_coordinate ,
345+ geo_x = self .geo_x ,
346+ geo_y = self .geo_y ,
323347 )
324348
325349
@@ -369,6 +393,8 @@ def create_event(self, detection: Detection) -> Event:
369393 video_name = detection .video_name ,
370394 interpolated_occurrence = detection .occurrence ,
371395 interpolated_event_coordinate = self .event_coordinate ,
396+ geo_x = self .geo_x ,
397+ geo_y = self .geo_y ,
372398 )
373399
374400
0 commit comments