|
12 | 12 | from google.protobuf.timestamp_pb2 import Timestamp
|
13 | 13 |
|
14 | 14 | from viam.proto.common import Geometry, GeoPoint, GetGeometriesRequest, GetGeometriesResponse, Orientation, ResourceName, Vector3
|
| 15 | +from viam.proto.app.data import ( |
| 16 | + CaptureInterval, |
| 17 | + Filter, |
| 18 | + TagsFilter, |
| 19 | +) |
15 | 20 | from viam.resource.base import ResourceBase
|
16 | 21 | from viam.resource.registry import Registry
|
17 | 22 | from viam.resource.types import Subtype, SupportsGetGeometries
|
@@ -263,3 +268,65 @@ def from_dm_from_extra(extra: Optional[Dict[str, Any]]) -> bool:
|
263 | 268 | return False
|
264 | 269 |
|
265 | 270 | return bool(extra.get("fromDataManagement", False))
|
| 271 | + |
| 272 | + |
| 273 | +def create_filter( |
| 274 | + component_name: Optional[str] = None, |
| 275 | + component_type: Optional[str] = None, |
| 276 | + method: Optional[str] = None, |
| 277 | + robot_name: Optional[str] = None, |
| 278 | + robot_id: Optional[str] = None, |
| 279 | + part_name: Optional[str] = None, |
| 280 | + part_id: Optional[str] = None, |
| 281 | + location_ids: Optional[List[str]] = None, |
| 282 | + organization_ids: Optional[List[str]] = None, |
| 283 | + mime_type: Optional[List[str]] = None, |
| 284 | + start_time: Optional[datetime] = None, |
| 285 | + end_time: Optional[datetime] = None, |
| 286 | + tags: Optional[List[str]] = None, |
| 287 | + bbox_labels: Optional[List[str]] = None, |
| 288 | +) -> Filter: |
| 289 | + """Create a `Filter`. |
| 290 | +
|
| 291 | + Args: |
| 292 | + component_name (Optional[str]): Optional name of the component that captured the data being filtered (e.g., "left_motor"). |
| 293 | + component_type (Optional[str]): Optional type of the componenet that captured the data being filtered (e.g., "motor"). |
| 294 | + method (Optional[str]): Optional name of the method used to capture the data being filtered (e.g., "IsPowered"). |
| 295 | + robot_name (Optional[str]): Optional name of the robot associated with the data being filtered (e.g., "viam_rover_1"). |
| 296 | + robot_id (Optional[str]): Optional ID of the robot associated with the data being filtered. |
| 297 | + part_name (Optional[str]): Optional name of the system part associated with the data being filtered (e.g., "viam_rover_1-main"). |
| 298 | + part_id (Optional[str]): Optional ID of the system part associated with the data being filtered. |
| 299 | + location_ids (Optional[List[str]]): Optional list of location IDs associated with the data being filtered. |
| 300 | + organization_ids (Optional[List[str]]): Optional list of organization IDs associated with the data being filtered. |
| 301 | + mime_type (Optional[List[str]]): Optional mime type of data being filtered (e.g., "image/png"). |
| 302 | + start_time (Optional[datetime.datetime]): Optional start time of an interval to filter data by. |
| 303 | + end_time (Optional[datetime.datetime]): Optional end time of an interval to filter data by. |
| 304 | + tags (Optional[List[str]]): Optional list of tags attached to the data being filtered (e.g., ["test"]). |
| 305 | + bbox_labels (Optional[List[str]]): Optional list of bounding box labels attached to the data being filtered (e.g., ["square", |
| 306 | + "circle"]). |
| 307 | +
|
| 308 | + Returns: |
| 309 | + viam.proto.app.data.Filter: The `Filter` object. |
| 310 | + """ |
| 311 | + return Filter( |
| 312 | + component_name=component_name if component_name else "", |
| 313 | + component_type=component_type if component_type else "", |
| 314 | + method=method if method else "", |
| 315 | + robot_name=robot_name if robot_name else "", |
| 316 | + robot_id=robot_id if robot_id else "", |
| 317 | + part_name=part_name if part_name else "", |
| 318 | + part_id=part_id if part_id else "", |
| 319 | + location_ids=location_ids, |
| 320 | + organization_ids=organization_ids, |
| 321 | + mime_type=mime_type, |
| 322 | + interval=( |
| 323 | + CaptureInterval( |
| 324 | + start=datetime_to_timestamp(start_time), |
| 325 | + end=datetime_to_timestamp(end_time), |
| 326 | + ) |
| 327 | + ) |
| 328 | + if start_time or end_time |
| 329 | + else None, |
| 330 | + tags_filter=TagsFilter(tags=tags), |
| 331 | + bbox_labels=bbox_labels, |
| 332 | + ) |
0 commit comments